Browse Source

compat: Add compatibility wrapper for format-prompt

* lisp/org-compat.el (org-format-prompt): New compatibility
function.
* lisp/org-capture.el (org-capture-fill-template):
* lisp/org-refile.el (org-refile-get-location): Use org-format-prompt.

Prefer a wrapper to inlining compatibility kludges.

This is a follow-up to the port of Emacs's 664094222.
Kyle Meyer 1 year ago
parent
commit
95a4c59bfe
3 changed files with 22 additions and 10 deletions
  1. 1 6
      lisp/org-capture.el
  2. 20 0
      lisp/org-compat.el
  3. 1 4
      lisp/org-refile.el

+ 1 - 6
lisp/org-capture.el

@@ -1831,12 +1831,7 @@ Expansion occurs in a temporary Org mode buffer."
 		     (setq org-capture--prompt-history
 			   (gethash prompt org-capture--prompt-history-table))
                      (push (org-completing-read
-                            ;; `format-prompt' is new in Emacs 28.1.
-                            (if (fboundp 'format-prompt)
-                                (format-prompt (or prompt "Enter string") default)
-                              (concat (or prompt "Enter string")
-                                      (and default (format " [%s]" default))
-                                      ": "))
+                            (org-format-prompt (or prompt "Enter string") default)
 			    completions
 			    nil nil nil 'org-capture--prompt-history default)
 			   strings)

+ 20 - 0
lisp/org-compat.el

@@ -171,6 +171,26 @@ removed."
       (string-trim (replace-regexp-in-string blank " " string t t)
                    blank blank))))
 
+(if (fboundp 'format-prompt)
+    (defalias 'org-format-prompt #'format-prompt)
+  ;; From Emacs minibuffer.el, inlining
+  ;; `minibuffer-default-prompt-format' value and replacing `length<'
+  ;; (both new in Emacs 28.1).
+  (defun org-format-prompt (prompt default &rest format-args)
+    "Compatibility substitute for `format-prompt'."
+    (concat
+     (if (null format-args)
+         prompt
+       (apply #'format prompt format-args))
+     (and default
+          (or (not (stringp default))
+              (> (length default) 0))
+          (format " (default %s)"
+                  (if (consp default)
+                      (car default)
+                    default)))
+     ": ")))
+
 
 ;;; Emacs < 27.1 compatibility
 

+ 1 - 4
lisp/org-refile.el

@@ -645,10 +645,7 @@ this function appends the default value from
          (prompt (let ((default (or (car org-refile-history)
                                     (and (assoc cbnex tbl) (setq cdef cbnex)
                                          cbnex))))
-                   ;; `format-prompt' is new in Emacs 28.1.
-                   (if (fboundp 'format-prompt)
-                       (format-prompt prompt default)
-                     (concat prompt " (default " default ": "))))
+                   (org-format-prompt prompt default)))
 	 pa answ parent-target child parent old-hist)
     (setq old-hist org-refile-history)
     (setq answ (funcall cfunc prompt tbl nil (not new-nodes)