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.
This commit is contained in:
Kyle Meyer 2022-10-04 17:42:27 -04:00
parent 07b6a0e044
commit 95a4c59bfe
3 changed files with 22 additions and 10 deletions

View File

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

View File

@ -171,6 +171,26 @@ removed."
(string-trim (replace-regexp-in-string blank " " string t t) (string-trim (replace-regexp-in-string blank " " string t t)
blank blank)))) 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 ;;; Emacs < 27.1 compatibility

View File

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