branch: externals/hyperbole commit 5999198ba65fc991839e18841d5b68a94a9df718 Author: Bob Weiner <r...@gnu.org> Commit: Bob Weiner <r...@gnu.org>
Fix issues with Action Buttons; don't add 'action' to button attrs --- ChangeLog | 22 ++++++++++++++++++++++ hact.el | 47 ++++++++++++++++++++++++++++++----------------- hactypes.el | 6 +++--- hibtypes.el | 17 +++++++---------- hpath.el | 4 ++-- test/demo-tests.el | 6 +++--- test/hactypes-tests.el | 6 +++--- 7 files changed, 70 insertions(+), 38 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4bcc0b5c87..3540e73886 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2023-07-08 Bob Weiner <r...@gnu.org> + +* test/demo-tests.el (demo-implicit-button-action-button-boolean-function-call-test): + Rename to 'demo-implicit-button-action-button-display-boolean-test' so can + find when search for use of 'display-boolean'. + +* hactypes.el (display-boolean): Improve clarity of output message. + test/hactypes-tests.el (display-boolean-true-test, display-boolean-false-test): + Update to new output message format. + +* hpath.el (hpath:absolute-arguments): Fix to process only string arguments. + +* hibtypes.el (action): Fix 'args' not being set right after add display-* actypes. + Stop storing unneeded ibutton 'action attribute. + +* hact.el (actype:action): Fix doc to say may return actype's fboundp symbol. + Use 'actype:action-body' if always need the body of the function. + (symtable:actype-p): Fix to return Elisp function symbols as well + since 'actype:elisp-symbol' is an alias to this defsubst. + (symtable:hyperbole-actype-p): Add to exclude Elisp function symbols. + (actype:act): Use above new function. + * DEMO (Completion Selection): man/hkey-help.txt: man/hyperbole.texi (Smart Key Argument Selection): Update to new minibuffer diff --git a/hact.el b/hact.el index 3465e9fa2e..3fc3bfaff8 100644 --- a/hact.el +++ b/hact.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 18-Sep-91 at 02:57:09 -;; Last-Mod: 3-Jul-23 at 18:43:27 by Bob Weiner +;; Last-Mod: 8-Jul-23 at 13:19:37 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -115,9 +115,19 @@ with the `ibtypes::' prefix and one without. The value for both keys is the Elisp symbol for the type, which includes the prefix.") (defsubst symtable:actype-p (symbol-or-name) - "Return SYMBOL-OR-NAME if it is a Hyperbole action type, else nil." + "Return SYMBOL-OR-NAME if a Hyperbole action type or Elisp function, else nil." (when (or (symbolp symbol-or-name) (stringp symbol-or-name)) - (symtable:get symbol-or-name symtable:actypes))) + (or (symtable:get symbol-or-name symtable:actypes) + (and (stringp symbol-or-name) (fboundp (intern-soft symbol-or-name)) + (intern-soft symbol-or-name)) + (and (functionp symbol-or-name) symbol-or-name)))) + +(defsubst symtable:hyperbole-actype-p (symbol-or-name) + "Return SYMBOL-OR-NAME if a Hyperbole action type, else nil. +This excludes Emacs Lisp functions which may be used as action types. +Use `actype:elisp-symbol' to include these." + (when (or (symbolp symbol-or-name) (stringp symbol-or-name)) + (or (symtable:get symbol-or-name symtable:actypes)))) (defsubst symtable:ibtype-p (symbol-or-name) "Return SYMBOL-OR-NAME if it is a Hyperbole implicit button type, else nil." @@ -384,16 +394,15 @@ performing ACTION." ;; being used as a path. So do this only if actype is a defact ;; and not a defun to limit any potential impact. RSW - 9/22/2017 (and (symbolp action) - (symtable:actype-p action) + (symtable:hyperbole-actype-p action) (setq args (hpath:absolute-arguments actype args))) (let ((hist-elt (hhist:element))) (run-hooks 'action-act-hook) - (prog1 (or (if (and args - (or (symbolp action) (listp action) - (byte-code-function-p action) - (subrp action) - (and (stringp action) (not (integerp action)) - (setq action (key-binding action))))) + (prog1 (or (if (or (symbolp action) (listp action) + (byte-code-function-p action) + (subrp action) + (and (stringp action) (not (integerp action)) + (setq action (key-binding action)))) (eval (cons action args)) (eval action)) t) @@ -414,6 +423,9 @@ is returned." (defun actype:eval (actype &rest args) "Perform action formed from ACTYPE and rest of ARGS and return value. +This differs from `actype:act' in that it can return nil and does not +expand relative pathname ARGS. + ACTYPE may be a string containing a Lisp expression from which ACTYPE and ARGS are extracted. ACTYPE may be a symbol or symbol name for either an action type or a function. Run `action-act-hook' before @@ -425,18 +437,19 @@ performing ACTION." (let ((hist-elt (hhist:element))) (run-hooks 'action-act-hook) (prog1 (if (or (symbolp action) (listp action) - (byte-code-function-p action) - (subrp action) - (and (stringp action) (not (integerp action)) - (setq action (key-binding action)))) + (byte-code-function-p action) + (subrp action) + (and (stringp action) (not (integerp action)) + (setq action (key-binding action)))) (apply action args) (eval action)) (hhist:add hist-elt)))))) (defun actype:action (actype) - "Return action part (body) of ACTYPE. -ACTYPE is a bound function symbol, symbol name or function body. -ACTYPE may be a Hyperbole actype or Emacs Lisp function." + "If ACTYPE is a bound function symbol, return it. +Otherwise, return its body. ACTYPE must be a bound function +symbol, symbol name or function body. ACTYPE may be a Hyperbole +actype or Emacs Lisp function." (let (actname action) (cond ((stringp actype) diff --git a/hactypes.el b/hactypes.el index bf7744d347..761b1a5192 100644 --- a/hactypes.el +++ b/hactypes.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 23-Sep-91 at 20:34:36 -;; Last-Mod: 25-Jun-23 at 13:48:01 by Bob Weiner +;; Last-Mod: 8-Jul-23 at 14:07:17 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -66,8 +66,8 @@ inserted, delete the completions window." Return any non-nil value or t." (interactive "xDisplay bool expr value: ") (let ((result (eval bool-expr t))) - (message "Boolean result (%s) = %S; Expr: %S" - (if result "True" "False") result bool-expr) + (message "Result = %S; Boolean value = %s; Expr = %S" + result (if result "True" "False") bool-expr) (or result t))) (defact display-value (value) diff --git a/hibtypes.el b/hibtypes.el index 2f9814b458..629a02b23f 100644 --- a/hibtypes.el +++ b/hibtypes.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 19-Sep-91 at 20:45:31 -;; Last-Mod: 25-Jun-23 at 23:04:09 by Bob Weiner +;; Last-Mod: 8-Jul-23 at 14:02:33 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -1537,24 +1537,21 @@ arg1 ... argN '>'. For example, <mail nil \"u...@somewhere.org\">." (cond ((and (symbolp actype) (fboundp actype) (string-match "-p\\'" (symbol-name actype))) ;; Is a function with a boolean result - (setq args `(',args) - action `(display-boolean ',action) - actype #'display-boolean)) + (setq actype #'display-boolean + args `(',action))) ((and (null args) (symbolp actype) (boundp actype) (or var-flag (not (fboundp actype)))) ;; Is a variable, display its value as the action - (setq args `(',args) - action `(display-variable ',actype) + (setq args `(',actype) actype #'display-variable)) (t ;; All other expressions, display the action result in the minibuffer - (setq args `(',args) - action `(display-value ',action) - actype #'display-value)))) + (setq actype #'display-value + args `(',action))))) ;; Create implicit button object and store in symbol hbut:current. (ibut:create :lbl-key lbl-key :lbl-start start-pos :lbl-end end-pos - :categ 'ibtypes::action :actype actype :args args :action action) + :categ 'ibtypes::action :actype actype :args args) ;; Necessary so can return a null value, which actype:act cannot. (let ((hrule:action diff --git a/hpath.el b/hpath.el index e79fd29d59..42806577ff 100644 --- a/hpath.el +++ b/hpath.el @@ -3,7 +3,7 @@ ;; Author: Bob Weiner ;; ;; Orig-Date: 1-Nov-91 at 00:44:23 -;; Last-Mod: 19-Jun-23 at 14:29:44 by Bob Weiner +;; Last-Mod: 8-Jul-23 at 14:00:39 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -716,7 +716,7 @@ Uses optional DEFAULT-DIRS (a list of dirs or a single dir) or (make-list (max 0 (- (length arg-list) (length param-list))) (last param-list)))) (cl-mapcar (lambda (param arg) - (if (and arg + (if (and (stringp param) (or (string-match-p "file" param) (string-match-p "dir" param) (string-match-p "path" param))) diff --git a/test/demo-tests.el b/test/demo-tests.el index 1431c44c1d..7278704098 100644 --- a/test/demo-tests.el +++ b/test/demo-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@gnu.org> ;; ;; Orig-Date: 30-Jan-21 at 12:00:00 -;; Last-Mod: 22-Jun-23 at 20:35:55 by Mats Lidell +;; Last-Mod: 8-Jul-23 at 14:16:51 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -231,12 +231,12 @@ (string-match-p "hactypes\\.el" hactypes-buf) (string-match-p "hibtypes\\.el" hibtypes-buf)))))) -(ert-deftest demo-implicit-button-action-button-boolean-function-call-test () +(ert-deftest demo-implicit-button-action-button-display-boolean-test () (with-temp-buffer (insert "<string-empty-p \"False\">") (goto-char 2) (action-key) - (hy-test-helpers:should-last-message "Boolean result (False) = nil"))) + (hy-test-helpers:should-last-message "Result = nil; Boolean value = False"))) (ert-deftest demo-implicit-button-action-button-variable-display-test () (with-temp-buffer diff --git a/test/hactypes-tests.el b/test/hactypes-tests.el index e23980e11c..39a1ea098d 100644 --- a/test/hactypes-tests.el +++ b/test/hactypes-tests.el @@ -3,7 +3,7 @@ ;; Author: Mats Lidell <ma...@gnu.org> ;; ;; Orig-Date: 30-Jan-21 at 12:00:00 -;; Last-Mod: 6-Feb-22 at 00:56:35 by Bob Weiner +;; Last-Mod: 8-Jul-23 at 14:11:49 by Bob Weiner ;; ;; SPDX-License-Identifier: GPL-3.0-or-later ;; @@ -26,11 +26,11 @@ (ert-deftest display-boolean-true-test () (should (actypes::display-boolean t)) - (hy-test-helpers:should-last-message "Boolean result (True) = t")) + (hy-test-helpers:should-last-message "Result = t; Boolean value = True")) (ert-deftest display-boolean-false-test () (should (actypes::display-boolean nil)) - (hy-test-helpers:should-last-message "Boolean result (False) = nil")) + (hy-test-helpers:should-last-message "Result = nil; Boolean value = False")) (provide 'hactypes-tests) ;;; hactypes-tests.el ends here