From 223c19e45d6baa0f5d03e9a36b9edf1a24e2514b Mon Sep 17 00:00:00 2001 From: bw Date: Sun, 15 Feb 2026 20:50:28 -0500 Subject: [PATCH] hywiki-word-highlight-in-current-buffer - Fix to run in proper bufs hywiki-default-mode - Add this customization which determines the initial state of HyWiki when Hyperbole is initialized. hywiki-mode-normalize - Add to normalize 'hywiki-mode' args and handle mode toggling. --- ChangeLog | 11 ++++ hyperbole.el | 7 ++- hywiki.el | 173 +++++++++++++++++++++++++++++++-------------------- 3 files changed, 121 insertions(+), 70 deletions(-) diff --git a/ChangeLog b/ChangeLog index 559f7b0b..6204b640 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2026-02-15 Bob Weiner + +* hywiki.el (hywiki-word-highlight-in-current-buffer): Fix bug that added + highlighting hooks to buffers where HyWikiWords are not highlighted. + Previously, this function filtered out only minibuffers. Now it filters + out buffers where hywiki-mode is not active. + (hywiki-mode-normalize): Add to normalize 'hywiki-mode' args and + handle mode toggling. + (hywiki-default-mode): Add this customization which determines + the state HyWiki is initialized to when Hyperbole is activated. + 2026-02-14 Bob Weiner * hsys-org.el (hsys-org-fix-version): Ensure 'org-install-dir' is a dir and diff --git a/hyperbole.el b/hyperbole.el index 3740e58a..01ecfab9 100644 --- a/hyperbole.el +++ b/hyperbole.el @@ -9,7 +9,7 @@ ;; Maintainer: Robert Weiner ;; Maintainers: Robert Weiner , Mats Lidell ;; Created: 06-Oct-92 at 11:52:51 -;; Last-Mod: 18-Jan-26 at 08:29:42 by Bob Weiner +;; Last-Mod: 15-Feb-26 at 20:18:18 by Bob Weiner ;; Released: 10-Mar-24 ;; Version: 9.0.2pre ;; Keywords: comm, convenience, files, frames, hypermedia, languages, mail, matching, mouse, multimedia, outlines, tools, wp @@ -510,8 +510,9 @@ frame, those functions by default still return the prior frame." (when (fboundp #'vertico-mouse-mode) (add-hook 'vertico-mode-hook (lambda () (vertico-mouse-mode 1)))) ;; - ;; Set HyWiki page auto-HyWikiWord highlighting and `yank-handled-properties' - (hywiki-mode :pages) + ;; Initialize HyWiki page auto-HyWikiWord highlighting and `yank-handled-properties' + ;; based on the `hywiki-default-mode'. + (hywiki-mode hywiki-default-mode) ;; ;; Hyperbole initialization is complete. (message "Initializing Hyperbole...done")) diff --git a/hywiki.el b/hywiki.el index f10841f4..62df7997 100644 --- a/hywiki.el +++ b/hywiki.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 21-Apr-24 at 22:41:13 -;; Last-Mod: 14-Feb-26 at 23:07:37 by Bob Weiner +;; Last-Mod: 15-Feb-26 at 20:39:33 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -786,11 +786,71 @@ since the command may have moved it off a HyWikiWord." ;; Not inside a comment or a string (not (or (nth 4 (syntax-ppss)) (hypb:in-string-p)))))) +(defcustom hywiki-default-mode :pages + "Customizable initial mode setting for HyWiki minor mode. +HyWiki mode has three states, any one of which can be set as the default: + - :pages - highlight HyWikiWords in HyWiki pages only (Org files in + `hywiki-directory') + - :all - highlight HyWikiWords in all editable buffers except those + with a major mode in `hywiki-exclude-major-modes'. + - nil - no highlighting, the mode is disabled." + :type 'string + :group 'hyperbole-hywiki) + (defvar hywiki-mode nil "Non-nil when the global hywiki minor mode is enabled. Don't set this directly, instead call the function `hywiki-mode' -with the value you want as its argument. See the docstring for -that function for valid values.") +with the value you want as its argument. See the documentation for the +customization, `hywiki-default-mode', for valid values.") + +(defun hywiki-mode-normalize (to-mode) + "Normalize `hywiki-mode' and TO-MODE values for `hywiki-mode' function. +See the documentation for the customization, `hywiki-default-mode', for +valid values." + ;; Normalize `hywiki-default-mode' setting + (cond + ((or (and (integerp hywiki-default-mode) (= hywiki-default-mode 1)) + (memq hywiki-default-mode '(:all all t))) + (setq hywiki-default-mode :all)) + ((or (null hywiki-default-mode) + (and (integerp hywiki-default-mode) (<= hywiki-default-mode 0))) + (setq hywiki-default-mode nil)) + (t ;; (> hywiki-default-mode 1) + (setq hywiki-default-mode :pages))) + + ;; Normalize `hywiki-mode' setting + (cond + ((or (and (integerp hywiki-mode) (= hywiki-mode 1)) + (memq hywiki-mode '(:all all t))) + ;; Enable across all editable buffers + (setq hywiki-mode :all)) + ((or (null hywiki-mode) + (and (integerp hywiki-mode) (<= hywiki-mode 0))) + ;; Disable mode flag + (setq hywiki-mode nil)) + (t ;; (> hywiki-mode 1) + ;; Enable in HyWiki page buffers only + (setq hywiki-mode :pages))) + + ;; Normalize `to-mode' and set mode + (when (eq to-mode 'toggle) + ;; Toggle across all editable buffers + (setq to-mode (if hywiki-mode + nil + (or hywiki--prior-mode hywiki-default-mode :pages)))) + + (cond + ((or (and (integerp to-mode) (= to-mode 1)) + (memq to-mode '(:all all t))) + ;; Enable across all editable buffers + (setq to-mode :all)) + ((or (null to-mode) + (and (integerp to-mode) (<= to-mode 0))) + ;; Disable across all editable buffers + (setq to-mode nil)) + (t ;; (> to-mode 1) + ;; Enable in HyWiki page buffers only + (setq to-mode :pages)))) ;;;###autoload (define-minor-mode hywiki-mode @@ -800,13 +860,9 @@ HyWiki minor mode automatically highlights and turns HyWikiWord references into implicit buttons that either link to HyWiki pages or activate typed referents such as bookmarks. -HyWiki minor mode has three states as tracked by the following values -of the `hywiki-mode' variable: - - :pages - highlight HyWikiWords in HyWiki pages only (Org files in - `hywiki-directory') - - :all - highlight HyWikiWords in all editable buffers except those - with a major mode in `hywiki-exclude-major-modes'. - - nil - no highlighting, the mode is disabled. +HyWiki minor mode has three states as tracked by the `hywiki-mode' +variable. See the documentation for the customization, `hywiki-default-mode', +for valid values. HyWikiWord references may also include optional suffixes: @@ -830,59 +886,38 @@ See the Info documentation at \"(hyperbole)HyWiki\". ;; customize this variable. :variable hywiki-mode (progn - (unless hywiki-mode-map - (setq hywiki-mode-map (make-sparse-keymap))) - ;; Normalize `hywiki-mode' setting - (cond - ((or (and (integerp hywiki-mode) (= hywiki-mode 1)) - (memq hywiki-mode '(:all t))) - ;; Enable across all editable buffers - (setq hywiki-mode :all)) - ((or (and (integerp hywiki-mode) (<= hywiki-mode 0)) - (null hywiki-mode)) - ;; Disable mode flag - (setq hywiki-mode nil)) - (t ;; (> hywiki-mode 1) - ;; Enable in HyWiki page buffers only - (setq hywiki-mode :pages))) - - ;; Normalize `arg' and set mode - (when (eq arg 'toggle) - ;; Toggle across all editable buffers - (setq arg hywiki-mode)) - (cond - ((or (and (integerp arg) (= arg 1)) - (memq arg '(:all t))) - ;; Enable across all editable buffers - (setq arg :all) - ;; Need hyperbole-mode - (unless hyperbole-mode - (hyperbole-mode 1)) - (hywiki-word-set-auto-highlighting hywiki--prior-mode arg) - (setq hywiki-mode arg)) - ((or (and (integerp arg) (<= arg 0)) - (null arg)) - ;; Disable across all editable buffers. - (setq arg nil) - ;; Dehighlight HyWikiWords in this buffer when 'hywiki-mode' is - ;; disabled and this is not a HyWiki page buffer. If this is a - ;; HyWiki page buffer, then dehighlight when `hywiki-mode' is nil. - (hywiki-word-set-auto-highlighting hywiki--prior-mode arg) - (setq hywiki-mode arg)) - (t ;; (> arg 1) - ;; Enable in HyWiki page buffers only - (setq arg :pages) - ;; Need hyperbole-mode - (unless hyperbole-mode - (hyperbole-mode 1)) - (hywiki-word-set-auto-highlighting hywiki--prior-mode arg) - (setq hywiki-mode arg))))) - -(defun hywiki-mode-around-advice (hywiki-mode-fn &optional arg) - (setq hywiki--prior-mode hywiki-mode) - (funcall hywiki-mode-fn arg)) - -(advice-add 'hywiki-mode :around #'hywiki-mode-around-advice) + ;; Set mode and highlighting + (pcase arg + (:all (progn + ;; Enable across all editable buffers + ;; Need hyperbole-mode + (unless hyperbole-mode + (hyperbole-mode 1)) + (hywiki-word-set-auto-highlighting hywiki--prior-mode arg) + (setq hywiki-mode arg))) + ('nil (progn + ;; Disable across all editable buffers. + ;; Dehighlight HyWikiWords in this buffer when 'hywiki-mode' is + ;; disabled and this is not a HyWiki page buffer. If this is a + ;; HyWiki page buffer, then dehighlight when `hywiki-mode' is nil. + (hywiki-word-set-auto-highlighting hywiki--prior-mode arg) + (setq hywiki-mode arg))) + (:pages (progn + ;; Enable in HyWiki page buffers only + ;; Need hyperbole-mode + (unless hyperbole-mode + (hyperbole-mode 1)) + (hywiki-word-set-auto-highlighting hywiki--prior-mode arg) + (setq hywiki-mode arg)))))) + +(defun hywiki-mode-around-advice (hywiki-mode-fn &optional to-mode) + (setq to-mode (hywiki-mode-normalize to-mode)) + (unless (eq hywiki-mode to-mode) + (setq hywiki--prior-mode hywiki-mode)) + (funcall hywiki-mode-fn to-mode)) + +(unless (advice-member-p #'hywiki-mode-around-advice #'hywiki-mode) + (advice-add 'hywiki-mode :around #'hywiki-mode-around-advice)) ;;; ************************************************************************ ;;; Public Implicit Button and Action Types @@ -1066,8 +1101,10 @@ Exclude the minibuffer if selected and return nil." (defun hywiki-potential-buffer-p () "Return non-nil if the current buffer can support HyWikiWords. -This does not mean `hywiki-mode' is presently active in that buffer. -Always exclude minibuffers." +Always exclude minibuffers. +This does not mean `hywiki-mode' is presently active in that buffer; +use 'hywiki-active-in-current-buffer-p' for that." + (and (not (minibufferp)) ;; (not (and (boundp 'edebug-active) edebug-active)) (not (apply #'derived-mode-p hywiki-exclude-major-modes)) @@ -3779,8 +3816,10 @@ occurs with one of these hooks, the problematic hook is removed." (hywiki-get-buffers-in-windows frame)))))) (defun hywiki-word-highlight-in-current-buffer () - (unless (minibufferp) - (hywiki-word-highlight-in-buffers (list (current-buffer))))) + "Auto-highlight HyWikiWords in the current buffer." + (and (not (minibufferp)) + (hywiki-active-in-current-buffer-p) + (hywiki-word-highlight-in-buffers (list (current-buffer))))) (defun hywiki-word-highlight-in-buffers (buffers) "Auto-highlight HyWikiWords in BUFFERS."