From 95a4c59bfe09c2a8baef0eb557d4853320916f32 Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Tue, 4 Oct 2022 17:42:27 -0400 Subject: [PATCH] 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. --- lisp/org-capture.el | 7 +------ lisp/org-compat.el | 20 ++++++++++++++++++++ lisp/org-refile.el | 5 +---- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/lisp/org-capture.el b/lisp/org-capture.el index 90a950f69..4ef5fea95 100644 --- a/lisp/org-capture.el +++ b/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) diff --git a/lisp/org-compat.el b/lisp/org-compat.el index b8ed3ddc3..53fe56ab9 100644 --- a/lisp/org-compat.el +++ b/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 diff --git a/lisp/org-refile.el b/lisp/org-refile.el index fdedd3822..edab0b225 100644 --- a/lisp/org-refile.el +++ b/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)