Skip to content

Commit

Permalink
Merge pull request #655 from rswgnu/rsw
Browse files Browse the repository at this point in the history
hywiki.el - Persistent loading and saving of all referent types
  • Loading branch information
rswgnu authored Jan 26, 2025
2 parents de8fa48 + e41f6be commit c5c8719
Show file tree
Hide file tree
Showing 7 changed files with 220 additions and 89 deletions.
36 changes: 36 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,45 @@

2025-01-26 Bob Weiner <[email protected]>

* test/hywiki-tests.el (hywiki-tests--action-key-on-wikiword-and-section-displays-page,
hywiki-tests--action-key-on-wikiword-and-line-column-displays-page):
Fix both of these so they no longer fail.

* test/hy-test-helpers.el (hy-delete-dir-and-buffer): Add support for
deleting automatically created HyWiki cache .hywiki.eld file
before trying to delete directory.

* hui-select.el (hui-select-at-delimited-sexp-p): Correct doc.

* hywiki.el (hywiki-get-referent-hasht): Load/build referent hash table
t if invalid or empty.

* hasht.el (hash-prin1): Add 'reverse' arg and use in 'hywiki-cache-save'.

* hywiki.el (hywiki-maybe-highlight-page-names,
hywiki-maybe-highlight-wikiwords-in-frame, hywiki-add-page):
Replace calls to 'hywiki-directory-set-mod-time' and
'hywiki-directory-set-checksum' with 'hywiki-env-save'.
(hywiki--referent-alist): Add.
(hywiki-cache-default-file, hywiki-cache-file, hywiki-cache-default-file,
hywiki-cache-edit, hywiki-cache-save): Add to save HyWikiWord referent
relations in a persistent cache. This makes HyWikis with multiple referent
types work across Emacs sessions.
(hywiki-make-referent-hasht): Add load from persistent cache.

* README.md: Update to show HTML, Info and PDF links to the Hyperbole Manual
as the first section in this file for easy reference.

* hmouse-tag.el (smart-emacs-lisp-mode-p): Add 'lisp-data-mode' support for
.eld files.

* hywiki.el (hywiki-set-directory): Ensure hash table has been created if
skip call 'hywiki-make-referent-hasht'.

* hasht.el: Change to use lexical scope.
(hash-make): Speed up by referencing 'reverse' value only once.
(hashp): Remove, use builtin 'hash-table-p' instead.

2025-01-20 Mats Lidell <[email protected]>

* test/test-helpers-tests.el (test-helpers-test--make-random-wikiword):
Expand Down
84 changes: 40 additions & 44 deletions hasht.el
Original file line number Diff line number Diff line change
@@ -1,32 +1,16 @@
;;!emacs
;;; hasht.el --- Create hash tables from lists and operate on them -*- lexical-binding: t -*-
;;
;; FILE: hasht.el
;; SUMMARY: Create hash tables from lists and operate on them.
;; USAGE: GNU Emacs Lisp Library
;; KEYWORDS: extensions, tools
;; Author: Bob Weiner
;;
;; AUTHOR: Bob Weiner
;; Orig-Date: 16-Mar-90 at 03:38:48
;; Last-Mod: 26-Jan-25 at 18:30:30 by Bob Weiner
;;
;; ORIG-DATE: 16-Mar-90 at 03:38:48
;; LAST-MOD: 5-Jan-25 at 12:21:16 by Bob Weiner
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
;; Copyright (C) 1990-1995, 1997, 2016 Free Software Foundation, Inc.
;; See the file BR-COPY for license information.
;; Copyright (C) 1990-1995, 1997, 2016, 2024, 2025 Free Software Foundation, Inc.
;; See the "HY-COPY" file for license information.
;;
;; This file is part of the OO-Browser.

;; The OO-Browser is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; The OO-Browser is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with the OO-Browser. If not, see <http://www.gnu.org/licenses/>.
;; This file is part of GNU Hyperbole.

;;; Commentary:
;;
Expand All @@ -44,6 +28,7 @@
;;
;; Public and private function names are alphabetized for easy location.


;;; Code:
;;; ************************************************************************
;;; Other required Elisp libraries
Expand Down Expand Up @@ -109,7 +94,7 @@ Otherwise, Return nil if KEY is not in HASH-TABLE or t otherwise."
((hash-table-p obj)
(let ((htable-copy (make-hash-table :size (length obj))))
(maphash
(lambda (key value)
(lambda (key _value)
(puthash key (hash-deep-copy obj) htable-copy))
obj)
htable-copy))
Expand Down Expand Up @@ -172,14 +157,19 @@ merge all the values for a given <key> instead."
(t (let* ((size (length initializer))
(hash-table (make-hash-table :size size))
key value sym)
(mapc (lambda (cns)
(when (consp cns)
(if reverse
(setq key (car cns) value (cdr cns))
(setq key (cdr cns) value (car cns))))
(when (setq sym (intern key))
(puthash sym value hash-table)))
initializer)
(if reverse
(mapc (lambda (cns)
(when (consp cns)
(setq key (car cns) value (cdr cns)))
(when (setq sym (intern key))
(puthash sym value hash-table)))
initializer)
(mapc (lambda (cns)
(when (consp cns)
(setq key (cdr cns) value (car cns)))
(when (setq sym (intern key))
(puthash sym value hash-table)))
initializer))
hash-table))))

(defun hash-make-prepend (initializer &optional reverse)
Expand Down Expand Up @@ -219,7 +209,7 @@ return all <value>s."
(mapcar #'symbol-name (hash-table-keys hash-table)))
((memq func '(car value first symbol-value))
(hash-table-values hash-table))
(t (let (result)
(t (let ((result nil))
(maphash
(lambda (key value)
(push (funcall func (cons value (symbol-name key)))
Expand Down Expand Up @@ -281,7 +271,7 @@ whose keys are the same."
hash-tables)
htable)))))))

(defun hash-merge-first-value (value1 value2)
(defun hash-merge-first-value (value1 _value2)
"Return a copy of VALUE1 for use in a hash table merge.
This is suitable for use as a value of `hash-merge-values-function'."
Expand Down Expand Up @@ -328,20 +318,28 @@ if KEY or HASH-TABLE are of the wrong type."
(error "(hash-prepend): `%s' key's value `%s' is not a list:" key key-val))
(error "(hash-prepend): Invalid hash-table key: %s" key)))))

(defun hash-prin1 (hash-table &optional stream)
(defun hash-prin1 (hash-table &optional stream reverse)
"Output the printed representation of HASH-TABLE as a list.
Quoting characters are printed when needed to make output that `read'
can handle, whenever this is possible.
Output stream is STREAM, or value of `standard-output'."
Output stream is optional STREAM, or the value of `standard-output'.
With optional REVERSE non-nil, print each element with its key and
value in reverse order to that stored in the hash table."
(if (not (hash-table-p hash-table))
(progn (prin1 hash-table stream)
(princ "\n" stream))
(princ "\(\n" stream)
(hash-map
(lambda (val-key-cons)
(prin1 val-key-cons stream)
(princ "\n" stream))
hash-table)
(if reverse
(hash-map
(lambda (val-key-cons)
(prin1 (cons (cdr val-key-cons) (car val-key-cons)) stream)
(princ "\n" stream))
hash-table)
(hash-map
(lambda (val-key-cons)
(prin1 val-key-cons stream)
(princ "\n" stream))
hash-table))
(princ "\)\n" stream)))

(defun hash-replace (value key hash-table)
Expand All @@ -363,8 +361,6 @@ Return nil if not a valid hash table."

(defalias 'hash-length 'hash-size)

(defalias 'hashp 'hash-table-p)

;;; ************************************************************************
;;; Private functions
;;; ************************************************************************
Expand Down
4 changes: 2 additions & 2 deletions hmouse-tag.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 24-Aug-91
;; Last-Mod: 16-Dec-24 at 00:34:24 by Bob Weiner
;; Last-Mod: 26-Jan-25 at 10:33:32 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -416,7 +416,7 @@ When optional NO-FLASH, do not flash."
;; Beyond Lisp files, Emacs Lisp symbols appear frequently in Byte-Compiled
;; buffers, debugger buffers, program ChangeLog buffers, Help buffers,
;; *Warnings*, *Flymake log* and *Flymake diagnostics buffers.
(or (apply #'derived-mode-p '(emacs-lisp-mode lisp-interaction-mode
(or (apply #'derived-mode-p '(emacs-lisp-mode lisp-data-mode lisp-interaction-mode
debugger-mode ert-results-mode))
(string-match-p (concat "\\`\\*\\(Warnings\\|Flymake log\\|Compile-Log\\(-Show\\)?\\)\\*"
"\\|\\`\\*Flymake diagnostics")
Expand Down
5 changes: 3 additions & 2 deletions hui-select.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 19-Oct-96 at 02:25:27
;; Last-Mod: 19-Jan-25 at 10:04:03 by Bob Weiner
;; Last-Mod: 26-Jan-25 at 17:04:55 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -894,7 +894,8 @@ Return t if selected, else nil."
(goto-char (match-end 0)))))))

(defun hui-select-at-delimited-sexp-p ()
"Select a delimited sexp."
"Return non-nil if at the start or on the end char of an sexpression.
Use `hui-select-mark-delimited-sexp' to select it."
(unless (eolp)
(let ((syn-before (if (char-before) (char-syntax (char-before)) 0))
(syn-after (if (char-after) (char-syntax (char-after)) 0)))
Expand Down
Loading

0 comments on commit c5c8719

Please sign in to comment.