Skip to content

Commit

Permalink
Merge pull request #624 from rswgnu/rsw
Browse files Browse the repository at this point in the history
hywiki.el - Support let' change of hywiki-directory
  • Loading branch information
rswgnu authored Dec 22, 2024
2 parents 5edb95c + f2c6a6d commit 354fe30
Show file tree
Hide file tree
Showing 6 changed files with 266 additions and 22 deletions.
45 changes: 44 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
2024-12-22 Bob Weiner <[email protected]>

* test/hywiki-tests.el (hywiki-tests--add-org-id): Fix so :type
argument is a list as required, not a symbol.

* hact.el (action:param-count): Add and use in 'hywiki-add-org-id'.
hywiki.el (hywiki-add-org-id): Pre-9.7 versions of org-id-get
did not accept the 4th optional INHERIT arg, so fix by
conditionally sending this argument.

* hui-mouse.el (smart-magit-tab): Change 'if-let' (now obsolete)
to 'if-let*'.

* test/hywiki-tests.el (hywiki-tests--add-org-id): Fix final test
to just look for prefix of "ID: ".

* hywiki.el (hywiki-clear-pages-hasht): Also clear
'hywiki--any-page-regexp-list'.
(hywiki-add-org-id): Fix first two lines of doc string.

* test/hywiki-tests.el (hywiki-tests--add-org-id): Fix to not compare
error string values since when compiled may not be a string but
just a pair of indexes into one.

* hywiki.el (hywiki-let-directory, hywiki-set-directory,
hywiki-directory-changed): Add to support 'let' changes of
'hywiki-directory'.
(hywiki-clear-pages-hasht): Simplify to nullify hywiki
hash table and not try to reuse a previously build table.

2024-12-16 Mats Lidell <[email protected]>

* test/hywiki-tests.el (hywiki-tests--sections-with-dash-space)
(hywiki-tests--get-singular-wikiword)
(hywiki-tests--get-plural-wikiword, hywiki-tests--add-referent)
(hywiki-tests--add-bookmark, hywiki-tests--add-command)
(hywiki-tests--add-find, hywiki-tests--add-global-button)
(hywiki-tests--add-hyrolo, hywiki-tests--add-info-index)
(hywiki-tests--add-info-node, hywiki-tests--add-key-series)
(hywiki-tests--add-link, hywiki-tests--add-org-id)
(hywiki-tests--get-page-list-for-new-wiki-directory-after-added-referent):
Tests.

2024-12-16 Mats Lidell <[email protected]>

* Makefile (docker-all-tests, docker-batch-tests): No byte compiling to
Expand Down Expand Up @@ -100,7 +143,7 @@

2024-11-25 Mats Lidell <[email protected]>

* kotl/kmenu.el (kotl-menu-common-body): Use kotl-kview.
* kotl/kmenu.el (kotl-menu-common-body): Use kotl-kview.

* .github/workflows/static.yaml: Static workflow for publishing the manual
to a static site using GitHub Pages.
Expand Down
10 changes: 9 additions & 1 deletion hact.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 18-Sep-91 at 02:57:09
;; Last-Mod: 17-Aug-24 at 15:09:52 by Bob Weiner
;; Last-Mod: 22-Dec-24 at 16:03:11 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -333,6 +333,14 @@ TYPE and TYPE-CATEGORY are both symbols. TYPE-CATEGORY must be one of
"Return Hyperbole action that execute a keyboard MACRO REPEAT-COUNT times."
(list 'execute-kbd-macro macro repeat-count))

(defun action:param-count (action)
"Return the number of args in ACTION's arg list.
Keywords and special symbols like &optional and &key are excluded."
(length (seq-filter (lambda (sym)
(not (or (keywordp sym)
(string-match "^&" (symbol-name sym)))))
(action:params action))))

(defun action:params-emacs (def)
"Return the argument list for the function DEF.
DEF may be a symbol or a function body."
Expand Down
4 changes: 2 additions & 2 deletions hui-mouse.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 04-Feb-89
;; Last-Mod: 15-Dec-24 at 13:17:27 by Bob Weiner
;; Last-Mod: 22-Dec-24 at 13:22:26 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -1635,7 +1635,7 @@ If assist key is pressed:
(magit-section-show section)
(magit-section-hide section)))
(t
(if-let ((command (key-binding (kbd "RET"))))
(if-let* ((command (key-binding (kbd "RET"))))
(progn (setq last-command-event ?\()
(setq this-command command)
(smart-magit-display-file command))
Expand Down
4 changes: 2 additions & 2 deletions hyrolo.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 7-Jun-89 at 22:08:29
;; Last-Mod: 13-Nov-24 at 13:17:36 by Mats Lidell
;; Last-Mod: 22-Dec-24 at 11:02:15 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -220,7 +220,7 @@ Function is called with 4 arguments: (SYMBOL SET-TO-VALUE OPERATION WHERE)."
(hyrolo-set-file-list symbol set-to-value)))

;; This next line is needed to invoke `hyrolo-set-file-list' when
;; `hyrolo-file-list' is changed via `setq' rather than
;; `hyrolo-file-list' is changed via `setq' or `let' rather than
;; `customize-set-variable'.
(add-variable-watcher 'hyrolo-file-list #'hyrolo-file-list-changed)

Expand Down
51 changes: 36 additions & 15 deletions hywiki.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 21-Apr-24 at 22:41:13
;; Last-Mod: 16-Dec-24 at 01:03:45 by Bob Weiner
;; Last-Mod: 22-Dec-24 at 16:31:10 by Bob Weiner
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -254,20 +254,41 @@ Use nil for no HyWiki mode indicator."
(defvar hywiki-file-suffix ".org"
"File suffix (including period) to use when creating HyWiki pages.")

;;;###autoload
(defun hywiki-let-directory (option value)
(set option value)
(hywiki-clear-pages-hasht)
(hywiki-make-pages-hasht))

;;;###autoload
(defun hywiki-set-directory (option value)
(unless (and (boundp 'hywiki-directory)
(equal hywiki-directory (file-name-as-directory value)))
(set-default option (file-name-as-directory value))
(hywiki-clear-pages-hasht)
(hywiki-make-pages-hasht))
(hywiki-org-set-publish-project))

(defcustom hywiki-directory "~/hywiki/"
"Directory that holds all HyWiki pages in Org format.
See `hywiki-org-publishing-directory' for exported pages in html format."
:initialize #'custom-initialize-default
:set (lambda (option value)
(unless (and (boundp 'hywiki-directory)
(equal hywiki-directory (file-name-as-directory value)))
(set option (file-name-as-directory value))
(hywiki-clear-pages-hasht)
(hywiki-make-pages-hasht))
(hywiki-org-set-publish-project))
:set #'hywiki-set-directory
:type 'string
:group 'hyperbole-hywiki)

(defun hywiki-directory-changed (option set-to-value operation _where)
"Watch function for variable `hywiki-directory'.
Function is called with 4 arguments: (SYMBOL SET-TO-VALUE OPERATION WHERE)."
(if (memq operation '(let unlet)) ;; not setting global value
(hywiki-let-directory option set-to-value)
(hywiki-set-directory option set-to-value)))

;; This next line is needed to invoke `hywiki-set-directory' when
;; `hywiki-directory' is changed via `setq' or `let' rather than
;; `customize-set-variable'.
(add-variable-watcher 'hywiki-directory #'hywiki-directory-changed)

(defvar-local hywiki-buffer-highlighted-state nil
"State of HyWikiWords highlighting in the associated buffer.
\\='h means the buffer was already highlighted;
Expand Down Expand Up @@ -952,7 +973,8 @@ calling this function."
(hywiki-add-referent wikiword referent)))

(defun hywiki-add-org-id (wikiword)
"Make WIKIWORD evaluate a prompted for sexpression and return it.
"Make WIKIWORD display an Org file or headline with an Org id.
If no id exists, it is created. Return the string \"ID: org-id-string\".
If WIKIWORD is invalid, trigger a `user-error' if called interactively
or return nil if not.
Expand All @@ -970,7 +992,9 @@ calling this function."
(user-error "(hywiki-add-org-id): Referent buffer <%s> must be in org-mode, not %s"
(buffer-name)
major-mode))
(let ((org-id (org-id-get nil nil nil t)))
(let ((org-id (if (>= (action:param-count #'org-id-get) 4)
(org-id-get nil nil nil t)
(org-id-get))))
(when (and (null org-id) buffer-read-only)
(user-error "(hywiki-add-org-id): Referent buffer <%s> point has no Org ID and buffer is read-only"
(buffer-name)))
Expand Down Expand Up @@ -2059,11 +2083,8 @@ If deleted, update HyWikiWord highlighting across all frames."

(defun hywiki-clear-pages-hasht ()
"Clear all elements from the HyWiki referent hash table and return it."
(if (hashp hywiki--pages-hasht)
(progn (hash-map (lambda (key) (hash-delete key hywiki--pages-hasht))
(hash-map #'cdr hywiki--pages-hasht))
hywiki--pages-hasht)
(hash-make (length (hywiki-get-page-files)))))
(setq hywiki--pages-hasht nil
hywiki--any-page-regexp-list nil))

(eval-and-compile
'(when (featurep 'company)
Expand Down
Loading

0 comments on commit 354fe30

Please sign in to comment.