[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 80d0d0fe5ea 2/5: (tempo-user-elements): Make it a proper hook
From: |
Stefan Monnier |
Subject: |
master 80d0d0fe5ea 2/5: (tempo-user-elements): Make it a proper hook |
Date: |
Fri, 8 Sep 2023 19:44:37 -0400 (EDT) |
branch: master
commit 80d0d0fe5eadc0301d8679f9563d016c95b28103
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>
(tempo-user-elements): Make it a proper hook
* lisp/tempo.el (tempo-user-element-functions): Rename from
`tempo-user-elements`.
(tempo-user-elements): Preserve as obsolete alias.
(tempo-is-user-element): Use `run-hook-with-args-until-success`.
---
lisp/tempo.el | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/lisp/tempo.el b/lisp/tempo.el
index 762a9c5433f..7e4f5e50e47 100644
--- a/lisp/tempo.el
+++ b/lisp/tempo.el
@@ -185,11 +185,12 @@ returns a pair of the form (STRING . POS), where STRING
is the string
used for matching and POS is the buffer position after which text
should be replaced with a template.")
-(defvar tempo-user-elements nil
+(define-obsolete-variable-alias 'tempo-user-elements
'tempo-user-element-functions "30.1")
+(defvar tempo-user-element-functions nil
"Element handlers for user-defined elements.
-A list of symbols which are bound to functions that take one argument.
-This function should return something to be sent to `tempo-insert' if
-it recognizes the argument, and nil otherwise.")
+This is an abnormal hook where the functions are called with one argument
+\(an element in a template) and they should return something to be sent to
+`tempo-insert' if they recognize the argument, and nil otherwise.")
(defvar-local tempo-named-insertions nil
"Temporary storage for named insertions.")
@@ -258,7 +259,7 @@ The elements in ELEMENTS can be of several types:
- `n>': Inserts a newline and indents line.
- `o': Like `%' but leaves the point before the newline.
- nil: It is ignored.
- - Anything else: Each function in `tempo-user-elements' is called
+ - Anything else: Each function in `tempo-user-element-functions' is called
with it as argument until one of them returns non-nil, and the
result is inserted. If all of them return nil, it is evaluated and
the result is treated as an element to be inserted. One additional
@@ -441,14 +442,8 @@ never prompted."
;;; tempo-is-user-element
(defun tempo-is-user-element (element)
- "Try all the user-defined element handlers in `tempo-user-elements'."
- ;; Sigh... I need (some list)
- (catch 'found
- (mapc (lambda (handler)
- (let ((result (funcall handler element)))
- (if result (throw 'found result))))
- tempo-user-elements)
- (throw 'found nil)))
+ "Try all the user-defined element handlers in
`tempo-user-element-functions'."
+ (run-hook-with-args-until-success 'tempo-user-element-functions element))
;;;
;;; tempo-forget-insertions