]> git.eshelyaron.com Git - emacs.git/commitdiff
Pass lambdas to `skeleton-read'
authorHarald Hanche-Olsen <hanche@math.ntnu.no>
Thu, 23 Jul 2015 16:09:44 +0000 (18:09 +0200)
committerDmitry Gutov <dgutov@yandex.ru>
Fri, 24 Jul 2015 16:27:56 +0000 (19:27 +0300)
* lisp/skeleton.el (skeleton-read): Allow PROMPT to be a function.

* lisp/textmodes/sgml-mode.el (sgml-attributes, sgml-value): Pass
lambdas to `skeleton-read' (bug#20386).

Copyright-paperwork-exempt: yes

lisp/skeleton.el
lisp/textmodes/sgml-mode.el

index d23488bfd346431b595b24970c645d14c03990d1..2c017ddc2cdbb2f7908dd40f7dcea3ccb58e5512 100644 (file)
@@ -277,7 +277,8 @@ When done with skeleton, but before going back to `_'-point call
 (defun skeleton-read (prompt &optional initial-input recursive)
   "Function for reading a string from the minibuffer within skeletons.
 
-PROMPT must be a string or a form that evaluates to a string.
+PROMPT must be a string or a function that evaluates to a string.
+It may also be a form that evaluates to a string (deprecated).
 It may contain a `%s' which will be replaced by `skeleton-subprompt'.
 If non-nil second arg INITIAL-INPUT or variable `input' is a string or
 cons with index to insert before reading.  If third arg RECURSIVE is non-nil
@@ -306,12 +307,14 @@ automatically, and you are prompted to fill in the variable parts.")))
        ;; before point.
         (save-excursion (insert "\n")))
     (unwind-protect
-       (setq prompt (if (stringp prompt)
-                        (read-string (format prompt skeleton-subprompt)
-                                     (setq initial-input
-                                           (or initial-input
-                                               (symbol-value 'input))))
-                      (eval prompt)))
+       (setq prompt (cond ((stringp prompt)
+                            (read-string (format prompt skeleton-subprompt)
+                                         (setq initial-input
+                                               (or initial-input
+                                                   (symbol-value 'input)))))
+                           ((functionp prompt)
+                            (funcall prompt))
+                           (t (eval prompt))))
       (or eolp
          (delete-char 1))))
   (if (and recursive
index 2ffe9c1e7ed50e445b2366b5e7feac54e2af1dc3..6a14b52dc920a796e882b275aaffa831afe5b479 100644 (file)
@@ -759,9 +759,10 @@ If QUIET, do not print a message when there are no attributes for TAG."
            (insert ?\s)
            (insert (funcall skeleton-transformation-function
                             (setq attribute
-                                  (skeleton-read '(completing-read
-                                                   "Attribute: "
-                                                   alist)))))
+                                  (skeleton-read (lambda ()
+                                                    (completing-read
+                                                     "Attribute: "
+                                                     alist))))))
            (if (string= "" attribute)
                (setq i 0)
              (sgml-value (assoc (downcase attribute) alist))
@@ -1177,13 +1178,16 @@ See `sgml-tag-alist' for info about attribute rules."
     (if (and (eq (car alist) t) (not sgml-xml-mode))
        (when (cdr alist)
          (insert "=\"")
-         (setq alist (skeleton-read '(completing-read "Value: " (cdr alist))))
+         (setq alist (skeleton-read (lambda ()
+                                       (completing-read
+                                        "Value: " (cdr alist)))))
          (if (string< "" alist)
              (insert alist ?\")
            (delete-char -2)))
       (insert "=\"")
       (if (cdr alist)
-          (insert (skeleton-read '(completing-read "Value: " alist)))
+          (insert (skeleton-read (lambda ()
+                                   (completing-read "Value: " alist))))
         (when (null alist)
           (insert (skeleton-read '(read-string "Value: ")))))
       (insert ?\"))))