branch: externals/hyperbole commit 7ccfb435ff649346e0ec62d6fdad4568113f1731 Merge: d9f7c7fb7a 598abd3ae7 Author: Robert Weiner <r...@gnu.org> Commit: GitHub <nore...@github.com>
Merge pull request #609 from rswgnu/rsw HyWiki - fix a number of edge cases with HyWiki highlighting --- ChangeLog | 21 +++++++++++++++++++++ hproperty.el | 7 ++++--- hui-mouse.el | 10 ++++++---- hywiki.el | 29 ++++++++++++++--------------- test/hsys-org-tests.el | 15 +++++---------- test/hywiki-tests.el | 8 ++++---- 6 files changed, 54 insertions(+), 36 deletions(-) diff --git a/ChangeLog b/ChangeLog index 432838e7cf..b2a7db01f2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,24 @@ +2024-11-17 Bob Weiner <r...@gnu.org> + +* hywiki.el (hywiki-word-at): Fix to exclude any char after the HyWikiWord, if any. + +* hproperty.el (hproperty:but-get-all-in-region): Return only overlays that still + point to some buffer (may have overlay references that have been deleted and point + to no buffer). + +* test/hywiki-tests.el (hywiki-tests--verify-face-property-when-editing-wikiword-first-char): + Fix middle test after delete-char from HyWikiWord. + +* hui-mouse.el (smart-eobp): Trigger only if eobp = eolp or if only + whitespace on line preceding eobp. + +2024-11-16 Bob Weiner <r...@gnu.org> + +* hywiki.el (hywiki-debuttonize-non-character-commands): + Remove (let ((hywiki-word-highlight-flag))) which was preventing + dehighlighting at the start of a WikiWord when the first character + was deleted. + 2024-11-17 Mats Lidell <ma...@gnu.org> * Makefile (run-emacs): Run Emacs as a make target for use with docker. diff --git a/hproperty.el b/hproperty.el index c8bef57e3a..5ca2c3d2f7 100644 --- a/hproperty.el +++ b/hproperty.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 21-Aug-92 -;; Last-Mod: 13-Oct-24 at 23:11:55 by Bob Weiner +;; Last-Mod: 17-Nov-24 at 10:31:59 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -249,8 +249,9 @@ first button with that PROPERTY and VALUE only." hproperty:flash-face)))) (delq nil (mapcar (lambda (overlay) - (when (memq (overlay-get overlay (or property 'face)) - val-list) + (when (and (bufferp (overlay-buffer overlay)) + (memq (overlay-get overlay (or property 'face)) + val-list)) (if property (throw 'first (list overlay)) overlay))) diff --git a/hui-mouse.el b/hui-mouse.el index 93c54adb83..f852e28701 100644 --- a/hui-mouse.el +++ b/hui-mouse.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 04-Feb-89 -;; Last-Mod: 15-Nov-24 at 23:01:31 by Mats Lidell +;; Last-Mod: 17-Nov-24 at 12:01:54 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -2218,8 +2218,8 @@ If key is pressed: ;;;###autoload (defun smart-eobp () - "Return t if point is past the last visible buffer line with text." - (and (or (eobp) + "Return t if point is past the last visible buffer line with non-whitespace characters." + (and (or (and (eobp) (bolp)) ;; On a blank line and nothing but whitespace until eob (save-excursion (beginning-of-line) @@ -2228,7 +2228,9 @@ If key is pressed: (not (smart-outline-char-invisible-p (1- (point))))))) (defun smart-eolp () - "Return t if point is at the end of a visible line but not the end of the buffer." + "Return t if point is at the end of a visible line. +This includes the last buffer line if it contains any non-whitespace +characters. It excludes a blank line at the end of the buffer." ;; smart-helm handles eol for helm buffers (unless (or (and (smart-helm-alive-p) (equal (helm-buffer-get) (buffer-name))) ;; Allow for org global cycling at start of buffer on a diff --git a/hywiki.el b/hywiki.el index 0f0db7ced2..1eb570ef5c 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-Nov-24 at 00:11:05 by Bob Weiner +;; Last-Mod: 17-Nov-24 at 10:27:44 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -451,13 +451,12 @@ deletion commands and those in `hywiki-non-character-commands'." ;; Use these to store any range of a delimited HyWikiWord#section (set-marker hywiki--buttonize-start start) (set-marker hywiki--buttonize-end end) - ;; Enable dehighlighting in HyWiki pages - (let ((hywiki-word-highlight-flag)) - (if (and start end) - (hywiki-maybe-dehighlight-page-names hywiki--buttonize-start - hywiki--buttonize-end) - ;; Dehighlight any page name at point - (hywiki-maybe-dehighlight-between-page-names)))))) + ;; Enable dehighlighting in HyWiki pages + (if (and start end) + (hywiki-maybe-dehighlight-page-names hywiki--buttonize-start + hywiki--buttonize-end) + ;; Dehighlight any page name at point + (hywiki-maybe-dehighlight-between-page-names))))) (defun hywiki-buttonize-word (func start end face) "Create a HyWikiWord button by calling FUNC with START and END positions. @@ -803,7 +802,7 @@ or this will return nil." (when (hywiki-maybe-at-wikiword-beginning) (cond ((looking-at hywiki--word-and-buttonize-character-regexp) (setq start (match-beginning 0) - end (1- (match-end 0)) + end (match-beginning 3) wikiword (string-trim (buffer-substring-no-properties start end)))) ((looking-at (concat hywiki-word-with-optional-section-regexp "\\'")) @@ -1263,8 +1262,8 @@ the current page unless they have sections attached." (progn (setq hywiki--page-name (match-string-no-properties 1) hywiki--start (match-beginning 0) - ;; This includes char after the page#section - hywiki--end (match-end 0)) + ;; This excludes optional char after the page#section + hywiki--end (match-beginning 3)) (hywiki-get-page hywiki--page-name))) (progn (setq hywiki--current-page (hywiki-get-buffer-page-name)) @@ -1272,7 +1271,7 @@ the current page unless they have sections attached." ;; include a #section. (unless (string-equal hywiki--current-page (buffer-substring-no-properties - hywiki--start (1- hywiki--end))) + hywiki--start hywiki--end)) (if (setq hywiki--buts (hproperty:but-get-all-in-region hywiki--start hywiki--end 'face hywiki-word-face)) @@ -1285,7 +1284,7 @@ the current page unless they have sections attached." hywiki--but-start (hproperty:but-start hywiki--buts) hywiki--but-end (hproperty:but-end hywiki--buts)) (unless (and (= hywiki--start hywiki--but-start) - (= (1- hywiki--end) hywiki--but-end)) + (= hywiki--end hywiki--but-end)) (hproperty:but-delete hywiki--buts) (hywiki-maybe-highlight-page-names hywiki--start hywiki--end))) @@ -2045,9 +2044,9 @@ DIRECTION-NUMBER is 1 for forward scanning and -1 for backward scanning." (setq hywiki--buttonize-characters (concat "[]()<>{} \t\r\n'" (hywiki-get-buttonize-characters)) hywiki--buttonize-character-regexp - (concat "[][" + (concat "\\([][" (regexp-quote (substring hywiki--buttonize-characters 2)) - "]") + "]\\|$\\)") hywiki--word-and-buttonize-character-regexp (concat hywiki-word-with-optional-section-regexp hywiki--buttonize-character-regexp))) diff --git a/test/hsys-org-tests.el b/test/hsys-org-tests.el index 79318e3a99..48117ee803 100644 --- a/test/hsys-org-tests.el +++ b/test/hsys-org-tests.el @@ -229,7 +229,7 @@ This is independent of the setting of `hsys-org-enable-smart-keys'." "Verify end-of-line behaves as `org-mode' when smart keys not enabled." (dolist (v '(nil :buttons)) (let ((hsys-org-enable-smart-keys v)) - ;;; One line no return + ;; One line with text, no return: smart-org triggers with nil or :buttons setting (with-temp-buffer (org-mode) (insert "* h1") @@ -239,7 +239,7 @@ This is independent of the setting of `hsys-org-enable-smart-keys'." (mock (hsys-org-meta-return) => t) (should (equal hsys-org-enable-smart-keys v)) ; Ert traceability (should (action-key)))) - ;;; Two lines + ;; Two lines with text and returns: smart-org triggers with nil or :buttons setting (with-temp-buffer (org-mode) (insert "* h1\n* h2\n") @@ -251,22 +251,17 @@ This is independent of the setting of `hsys-org-enable-smart-keys'." (should (action-key)))))) (let ((hsys-org-enable-smart-keys t) (v t)) - ;;; One line no return - ;; At end of line is also end of file so smart-eolp filters out - ;; this as a Hyperbole context and org instead picks it - ;; up. Possibly a confusing behavior!? Should eof only be when - ;; action is below last visible line to avoid this case? + ;; One line with text, no return: smart-eolp triggers with t setting (with-temp-buffer (org-mode) (insert "* h1") (goto-char 1) (end-of-line) (with-mock - (mock (hsys-org-meta-return) => t) + (mock (smart-scroll-up) => t) (should (equal hsys-org-enable-smart-keys v)) ; Ert traceability (should (action-key)))) - ;;; Two lines - ;; Hyperbole context is active and smart scroll is triggered. + ;; Two lines with text and returns: smart-eolp triggers with t setting (with-temp-buffer (org-mode) (insert "* h1\n* h2\n") diff --git a/test/hywiki-tests.el b/test/hywiki-tests.el index 946035851a..1c972d0a0e 100644 --- a/test/hywiki-tests.el +++ b/test/hywiki-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell ;; ;; Orig-Date: 18-May-24 at 23:59:48 -;; Last-Mod: 14-Nov-24 at 00:17:30 by Bob Weiner +;; Last-Mod: 17-Nov-24 at 12:53:21 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -292,8 +292,8 @@ Both mod-time and checksum must be changed for a test to return true." "Call BODY wrapped in hywiki hooks to simulate Emacs redisplay." (declare (indent 0) (debug t)) `(progn - (funcall 'hywiki-debuttonize-non-character-commands) (progn ,@body) + (funcall 'hywiki-debuttonize-non-character-commands) (funcall 'hywiki-buttonize-character-commands) (funcall 'hywiki-buttonize-non-character-commands))) @@ -371,7 +371,6 @@ Both mod-time and checksum must be changed for a test to return true." (ert-deftest hywiki-tests--verify-face-property-when-editing-wikiword-first-char () "Verify face property changes when WikiWord is edited in the first char position." - :expected-result :failed (let* ((hywiki-directory (make-temp-file "hywiki" t)) (wikipage (hywiki-add-page "WikiWord"))) (skip-unless (not noninteractive)) @@ -385,7 +384,8 @@ Both mod-time and checksum must be changed for a test to return true." (should (looking-at-p "Wiki")) (should (hproperty:but-get (point) 'face hywiki-word-face)) - (with-hywiki-buttonize-and-insert-hooks (delete-char 1)) + (delete-char 1) + (hywiki-maybe-dehighlight-page-name t) (should (looking-at-p "iki")) (should-not (hproperty:but-get (point) 'face hywiki-word-face))