branch: externals/hyperbole commit 982b97512419a98c176783fa187b2bc5200f7a1b Author: bw <r...@gnu.org> Commit: bw <r...@gnu.org>
hui-select.el - Make Action Key on delimited pairs match hui-select --- ChangeLog | 22 +++++++++++ hui-mouse.el | 12 +++--- hui-select.el | 115 ++++++++++++++++++++++++++++++---------------------------- 3 files changed, 89 insertions(+), 60 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5c1393f608..4f99dc8c9f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +* hui-select.el (hui-select-punctuation): Add 'hui-select-markup-pair' so if + on the opening char of an HTML tag for example with punctuation syntax, + it is treated as a markup pair from `hui-select-thing'. + (hui-select-thing): Change return value to be the region selected + so can be used as a delimited regional selection predicate like so: + (hui-select-delimited-thing-call #'hui-select-thing). + +* hui-mouse.el (hkey-alist): Change action for 'hui-select-at-delimited-thing-p' + condition to call 'hui-select-thing' instead of 'hui-select-delimited-thing' + so does not include extra whitespace and matches the result when + 'hui-select-thing' is called interactively. + 2025-02-19 Bob Weiner <r...@gnu.org> * hyrolo.el (hyrolo-expand-path-list): Fix to include a default file name @@ -11,6 +23,16 @@ (hyrolo-get-file-list): Return a default rolo file when `hyrolo- file-list' is nil. +2025-02-16 Bob Weiner <r...@gnu.org> + +* hui-select.el (hui-select-punctuation): Add (hui-select-string pos) call + when on a double quote since sometimes double quotes have punctuation syntax, + e.g. text-mode. + (hui-select-string-p): Fix off-by-one error when scan-sexps + backwards with point after an ending double quote. + When compile, add (require 'hbut) for 'hbut:syntax-table'. Fix string + selection in 'text-mode' by using 'hbut:syntax-table'. + 2025-02-08 Mats Lidell <ma...@gnu.org> * hywiki.el (hywiki--sitemap-file): Helper function for getting the sitemap diff --git a/hui-mouse.el b/hui-mouse.el index da5a730829..8f5b775234 100644 --- a/hui-mouse.el +++ b/hui-mouse.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 04-Feb-89 -;; Last-Mod: 19-Jan-25 at 16:40:13 by Bob Weiner +;; Last-Mod: 22-Feb-25 at 16:18:02 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -292,7 +292,8 @@ Its default value is `smart-scroll-down'. To disable it, set it to (smart-helm-alive-p))) . ((funcall (key-binding (kbd "RET"))) . (funcall (key-binding (kbd "RET"))))) ;; - ;; If at the end of a line (eol), invoke the associated Smart Key handler EOL handler. + ;; If at the end of a line (eol), invoke the associated Smart Key + ;; handler EOL handler. ((and (smart-eolp) (not (and (funcall hsys-org-mode-function) (not (equal hsys-org-enable-smart-keys t))))) @@ -390,8 +391,8 @@ Its default value is `smart-scroll-down'. To disable it, set it to ;; ends at point. For markup pairs, point must be at the first ;; character of the opening or closing tag. ((hui-select-at-delimited-thing-p) - . ((hui-select-delimited-thing) . (progn (hui-select-delimited-thing) - (hmouse-kill-region)))) + . ((hui-select-thing) . (progn (hui-select-thing) + (hmouse-kill-region)))) ;; ;; If the prior test failed and point is at the start or end of an ;; sexpression, mark it for editing or kill it (assist key). This @@ -413,7 +414,8 @@ Its default value is `smart-scroll-down'. To disable it, set it to ((eq major-mode 'kotl-mode) . ((kotl-mode:action-key) . (kotl-mode:assist-key))) ;; - ;; If in the flymake linter list of issues buffer, jump to or show issue at point + ;; If in the flymake linter list of issues buffer, jump to or show + ;; issue at point. ((eq major-mode 'flymake-diagnostics-buffer-mode) . ((flymake-goto-diagnostic (point)) . (flymake-show-diagnostic (point) t))) ;; diff --git a/hui-select.el b/hui-select.el index fd949b42f8..e2556b7d90 100644 --- a/hui-select.el +++ b/hui-select.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 19-Oct-96 at 02:25:27 -;; Last-Mod: 7-Feb-25 at 00:15:47 by Bob Weiner +;; Last-Mod: 22-Feb-25 at 22:15:12 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -564,6 +564,7 @@ Also, add language-specific syntax setups to aid in thing selection." If invoked repeatedly, this selects bigger and bigger things. If `hui-select-display-type' is non-nil and this is called interactively, the type of selection is displayed in the minibuffer. +The region selected is returned in (start . end) form. If the key that invokes this command in `hyperbole-minor-mode' is also bound in the current major mode map, then interactively @@ -603,7 +604,7 @@ invoke that command instead. Typically prevents clashes over (and (called-interactively-p 'interactive) hui-select-display-type (message "%s" hui-select-previous)) (run-hooks 'hui-select-thing-hook) - t)))))) + region)))))) ;;;###autoload (defun hui-select-thing-with-mouse (event) @@ -783,8 +784,8 @@ The character at POS is selected if no other thing is matched." (mapc (lambda (sym-func) (setq region - (when (car (cdr sym-func)) - (funcall (car (cdr sym-func)) pos))) + (when (cadr sym-func) + (funcall (cadr sym-func) pos))) (when (and region (car region) (hui-select-region-bigger-p hui-select-old-region region) @@ -1037,7 +1038,6 @@ Return the updated cons cell." nil hui-select-region)) - (defun hui-select-string-p (&optional start-delim end-delim) "Return (start . end) of a string. Works when on a delim or on the first line with point in the @@ -1047,55 +1047,55 @@ and END-DELIM (strings) are given. Returns nil if not within a string." (unless start-delim (setq start-delim "\"")) (unless end-delim (setq end-delim "\"")) - (or (and (equal start-delim "\"") (equal end-delim "\"") - (ignore-errors - (cond ((and (= (char-after) ?\") - (/= (char-before) ?\\)) - (if (hypb:in-string-p) - (hui-select-set-region (scan-sexps (1+ (point)) -1) - (1+ (point))) - (hui-select-set-region (point) (scan-sexps (point) 1)))) - ((and (= (char-before) ?\") - (/= (char-before (1- (point))) ?\\)) - (if (hypb:in-string-p) - (hui-select-set-region (1- (point)) (scan-sexps (1- (point)) 1)) - (hui-select-set-region (scan-sexps (1- (point)) -1) - (point))))))) - (let ((opoint (point)) - (count 0) - bol start delim-regexp start-regexp end-regexp) - ;; Special case for the empty string. - (if (looking-at (concat (regexp-quote start-delim) - (regexp-quote end-delim))) - (hui-select-set-region (point) (match-end 0)) - (setq start-regexp (concat "\\(^\\|[^\\]\\)\\(" - (regexp-quote start-delim) "\\)") - end-regexp (concat "[^\\]\\(" (regexp-quote end-delim) "\\)") - delim-regexp (concat start-regexp "\\|" end-regexp)) - (save-excursion - (beginning-of-line) - (setq bol (point)) - (while (re-search-forward delim-regexp opoint t) - (setq count (1+ count)) - ;; This is so we don't miss the closing delimiter of an empty - ;; string. - (if (and (= (point) (1+ bol)) - (looking-at (regexp-quote end-delim))) - (setq count (1+ count)) - (unless (bobp) - (backward-char 1)))) - (goto-char opoint) - ;; If found an even # of starting and ending delimiters before - ;; opoint, then opoint is at the start of a string, where we want it. - (if (zerop (mod count 2)) - (unless (bobp) - (backward-char 1)) - (re-search-backward start-regexp nil t)) - ;; Point is now before the start of the string. - (when (re-search-forward start-regexp nil t) - (setq start (match-beginning 2)) - (when (re-search-forward end-regexp nil t) - (hui-select-set-region start (point))))))))) + (with-syntax-table hbut:syntax-table + (or (and (equal start-delim "\"") (equal end-delim "\"") + (ignore-errors + (cond ((and (= (char-after) ?\") + (/= (char-before) ?\\)) + (if (hypb:in-string-p) + (hui-select-set-region (1+ (point)) + (scan-sexps (1+ (point)) -1)) + (hui-select-set-region (point) (scan-sexps (point) 1)))) + ((and (= (char-before) ?\") + (/= (char-before (1- (point))) ?\\)) + (if (hypb:in-string-p) + (hui-select-set-region (1- (point)) (scan-sexps (1- (point)) 1)) + (hui-select-set-region (point) (scan-sexps (point) -1))))))) + (let ((opoint (point)) + (count 0) + bol start delim-regexp start-regexp end-regexp) + ;; Special case for the empty string. + (if (looking-at (concat (regexp-quote start-delim) + (regexp-quote end-delim))) + (hui-select-set-region (point) (match-end 0)) + (setq start-regexp (concat "\\(^\\|[^\\]\\)\\(" + (regexp-quote start-delim) "\\)") + end-regexp (concat "[^\\]\\(" (regexp-quote end-delim) "\\)") + delim-regexp (concat start-regexp "\\|" end-regexp)) + (save-excursion + (beginning-of-line) + (setq bol (point)) + (while (re-search-forward delim-regexp opoint t) + (setq count (1+ count)) + ;; This is so we don't miss the closing delimiter of an empty + ;; string. + (if (and (= (point) (1+ bol)) + (looking-at (regexp-quote end-delim))) + (setq count (1+ count)) + (unless (bobp) + (backward-char 1)))) + (goto-char opoint) + ;; If found an even # of starting and ending delimiters before + ;; opoint, then opoint is at the start of a string, where we want it. + (if (zerop (mod count 2)) + (unless (bobp) + (backward-char 1)) + (re-search-backward start-regexp nil t)) + ;; Point is now before the start of the string. + (when (re-search-forward start-regexp nil t) + (setq start (match-beginning 2)) + (when (re-search-forward end-regexp nil t) + (hui-select-set-region start (point)))))))))) ;;; ;;; Code selections ;;; @@ -1336,7 +1336,12 @@ included in the list, hui-select-brace-modes." (defun hui-select-punctuation (pos) "Return (start . end) region when at a punctuation character. The region includes sexpressions before and after POS" - (or (hui-select-comment pos) + (or (hui-select-markup-pair pos) + (hui-select-delimited-thing-call #'hui-select-thing) + (and (or (and (= (char-after) ?\") (/= (char-before) ?\\)) + (and (= (char-before) ?\") (/= (char-before (1- (point))) ?\\))) + (hui-select-string pos)) + (hui-select-comment pos) (hui-select-preprocessor-def pos) (hui-select-brace-def-or-declaration pos) ;; Might be on a C++ destructor ~. (save-excursion