Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2024-02-11 Mats Lidell <matsl@gnu.org>

* test/hbut-tests.el (hbut-tests--ebut-act-calls-hbut-act)
(hbut-tests--ibut-act-calls-hbut-act): Add test for new act functions
with error cases.

* hui-menu.el (hui-menu-explicit-buttons): Use ebut:act-label.

* hbut.el (ibut:act-label, ebut:act-label): Rename ebut:act and ibut:act
since they take a label as arg.
(ebut:act, ibut:act): Add new act functions taking a hbut as
arg. Allow only to be called with ebut or ibut respectively. If
falling back on hbut:current check that it is of the same type as the
call.

2024-02-08 Mats Lidell <matsl@gnu.org>

* test/hyrolo-tests.el: Make hide tests more forgiving about hiding
Expand Down
33 changes: 28 additions & 5 deletions hbut.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: 21-Jan-24 at 10:31:14 by Bob Weiner
;; Last-Mod: 11-Feb-24 at 23:43:08 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -122,7 +122,19 @@ indicating the source of any of its Hyperbole buttons.")
"*Non-nil value saves button data when button source is saved.
Nil disables saving.")

(defun ebut:act (label)
(defun ebut:act (&optional ebut)
"Perform action for optional explicit Hyperbole button symbol EBUT.
Default is the symbol hbut:current."
(interactive (list (hbut:get (hargs:read-match "Activate labeled Hyperbole button: "
(ebut:alist)
nil t nil 'ebut))))
(unless ebut
(setq ebut 'hbut:current))
(if (ebut:is-p ebut)
(hbut:act ebut)
(error "(ebut:act): Expected an ebut but got a but of type %s" (hattr:get ebut 'categ))))

(defun ebut:act-label (label)
"Activate Hyperbole explicit button with LABEL from the current buffer."
(interactive (list (hargs:read-match "Activate explicit button labeled: "
(ebut:alist)
Expand All @@ -131,7 +143,7 @@ Nil disables saving.")
(but (ebut:get lbl-key)))
(if but
(hbut:act but)
(error "(ebut:act): No explicit button labeled: %s" label))))
(error "(ebut:act-label): No explicit button labeled: %s" label))))

(defun ebut:alist (&optional file)
"Return alist of ebuts in FILE or the current buffer.
Expand Down Expand Up @@ -1692,8 +1704,19 @@ Keys in optional KEY-SRC or the current buffer."
;;; ibut class - Implicit Hyperbole Buttons
;;; ========================================================================

(defun ibut:act (&optional ibut)
"Perform action for optional implicit Hyperbole button symbol IBUT.
Default is the symbol hbut:current."
(interactive (list (hbut:get (hargs:read-match "Activate labeled Hyperbole button: "
(ibut:alist)
nil t nil 'ibut))))
(unless ibut
(setq ibut 'hbut:current))
(if (ibut:is-p ibut)
(hbut:act ibut)
(error "(ebut:act): Expected an ibut but got a but of type %s" (hattr:get ibut 'categ))))

(defun ibut:act (label)
(defun ibut:act-label (label)
"Activate Hyperbole implicit button with <[LABEL]> from the current buffer."
(interactive (list (hargs:read-match "Activate implicit button labeled: "
(ibut:alist)
Expand All @@ -1702,7 +1725,7 @@ Keys in optional KEY-SRC or the current buffer."
(but (ibut:get lbl-key)))
(if but
(hbut:act but)
(error "(ibut:act): No implicit button labeled: %s" label))))
(error "(ibut:act-label): No implicit button labeled: %s" label))))

(defun ibut:alist (&optional file)
"Return alist of labeled ibuts in FILE or the current buffer.
Expand Down
4 changes: 2 additions & 2 deletions hui-menu.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Bob Weiner
;;
;; Orig-Date: 28-Oct-94 at 10:59:44
;; Last-Mod: 21-Jan-24 at 10:31:58 by Bob Weiner
;; Last-Mod: 2-Feb-24 at 21:41:16 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -110,7 +110,7 @@ BROWSER-OPTION marks current active menu option as selected."
(not hui-menu-order-explicit-buttons))
:style toggle :selected hui-menu-order-explicit-buttons]
"Activate:")
(mapcar (lambda (label) (vector label `(ebut:act ,label) t))
(mapcar (lambda (label) (vector label `(ebut:act-label ,label) t))
(if hui-menu-order-explicit-buttons
(sort labels #'string-lessp)
labels))
Expand Down
32 changes: 31 additions & 1 deletion test/hbut-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
;; Author: Mats Lidell <matsl@gnu.org>
;;
;; Orig-Date: 30-may-21 at 09:33:00
;; Last-Mod: 20-Jan-24 at 15:43:50 by Mats Lidell
;; Last-Mod: 11-Feb-24 at 23:35:14 by Mats Lidell
;;
;; SPDX-License-Identifier: GPL-3.0-or-later
;;
Expand Down Expand Up @@ -738,6 +738,36 @@ See #10 for the proper way to add an ibutton name.
(hbut-tests:should-match-tmp-folder buf-str)
(should (null (hattr:get 'hbut:current 'name))))))

(ert-deftest hbut-tests--ebut-act-calls-hbut-act ()
"Verify `ebut:act' calls `hbut:act'."
(mocklet (((hbut:act 'button) => t)
((ebut:is-p 'button) => t))
(should (ebut:act 'button)))
(mocklet (((hbut:act 'hbut:current) => t)
((ebut:is-p 'hbut:current) => t))
(should (ebut:act)))
(mocklet ((ebut:is-p => nil))
(should-error (ebut:act 'button))
(should-error (ebut:act)))
(progn
(hattr:clear 'hbut:current)
(should-error (ebut:act))))

(ert-deftest hbut-tests--ibut-act-calls-hbut-act ()
"Verify `ibut:act' calls `hbut:act'."
(mocklet (((hbut:act 'button) => t)
((ibut:is-p 'button) => t))
(should (ibut:act 'button)))
(mocklet (((hbut:act 'hbut:current) => t)
((ibut:is-p 'hbut:current) => t))
(should (ibut:act)))
(mocklet ((ibut:is-p => nil))
(should-error (ibut:act 'button))
(should-error (ibut:act)))
(progn
(hattr:clear 'hbut:current)
(should-error (ibut:act))))

;; This file can't be byte-compiled without the `el-mock' package (because of
;; the use of the `with-mock' macro), which is not a dependency of Hyperbole.
;; Local Variables:
Expand Down