Ihor Radchenko <yanta...@posteo.net> writes:

> Patches welcome.

Please, see the attached patch.

> I see no obvious downsides. May as well.

Done.

> Currently, the minibuffer message is simply "Link: ". "Insert link:"
> is also ok.

Done.

> Maybe "Press" rather than "Type".

I went with "Type" to match other Emacs commands.

> We may, but the default link might sometimes be long. Not sure how it
> will look like.

All right, you be the judge.

Personally, I find this UI less disorienting, as opposed to the unclear
comment about RET in the *Org Links* buffer.  And it makes sense, given
I see the "VERB NOUN [default CANDIDATE]: " constantly, all throughout
in Emacs.

> AFAIK, this is already done. We already use `completing-read'. The UI
> is there historically and in addition to the normal Emacs completion.

Gotcha!

(It is quite confusing when using e.g. Vertico, but if we are optimizing
for the default Emacs completion system, then it makes sense.)

Rudy

>From 7bc8e913af0972f0d6119e45d4ecaf80835f2277 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rudolf=20Adamkovi=C4=8D?= <salu...@me.com>
Date: Sun, 10 Dec 2023 00:51:31 +0100
Subject: [PATCH] org-link: Prettify 'org-insert-link'

* lisp/ol.el (org-insert-link): Update the UI with text that is (1)
shorter, to avoid line breaks, (2) more standard, to match other Emacs
commands, and (3) more readable, with propertized key bindings.  Also,
show the default link in the minibuffer, as seen elsewhere in Emacs.
---
 lisp/ol.el | 44 +++++++++++++++++++++++++++++++++-----------
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/lisp/ol.el b/lisp/ol.el
index e684b9504..49499e932 100644
--- a/lisp/ol.el
+++ b/lisp/ol.el
@@ -1866,16 +1866,34 @@ non-interactively, don't allow to edit the default description."
       (org-link--fontify-links-to-this-file)
       (org-switch-to-buffer-other-window "*Org Links*")
       (with-current-buffer "*Org Links*"
-	(erase-buffer)
-	(insert "Insert a link.
-Use TAB to complete link prefixes, then RET for type-specific completion support\n")
-	(when org-stored-links
-	  (insert "\nStored links are available with <up>/<down> or M-p/n \
-\(most recent with RET):\n\n")
-	  (insert (mapconcat #'org-link--prettify
-			     (reverse org-stored-links)
-			     "\n")))
-	(goto-char (point-min)))
+        (read-only-mode 1)
+        (let ((inhibit-read-only t)
+              ;; FIXME Duplicate: Also in 'ox.el'.
+              (propertize-help-key
+               (lambda (key)
+                 ;; Add `face' *and* `font-lock-face' to "work
+                 ;; reliably in any buffer", per a comment in
+                 ;; `help--key-description-fontified'.
+                 (propertize key
+                             'font-lock-face 'help-key-binding
+                             'face 'help-key-binding))))
+          (erase-buffer)
+          (insert
+           (apply 'format
+                  (cons "Type %s to complete link type, then %s to complete destination.\n"
+                        (mapcar propertize-help-key
+                                (list "TAB" "RET")))))
+	  (when org-stored-links
+            (insert (apply 'format
+                           (cons "\nStored links accessible with %s/%s or %s/%s are:\n\n"
+                                 (mapcar propertize-help-key
+                                         (list "<up>" "<down>"
+                                               "M-p" "M-n"
+                                               "RET")))))
+	    (insert (mapconcat #'org-link--prettify
+			       (reverse org-stored-links)
+			       "\n"))))
+        (goto-char (point-min)))
       (when (get-buffer-window "*Org Links*" 'visible)
         (let ((cw (selected-window)))
 	  (select-window (get-buffer-window "*Org Links*" 'visible))
@@ -1890,7 +1908,11 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
 			 org-link--insert-history)))
 	    (setq link
 		  (org-completing-read
-		   "Link: "
+                   (concat "Insert link"
+                           (if-let ((default (caar org-stored-links)))
+                               (format " [default %s]" default)
+                             "")
+                           ": ")
 		   (append
 		    (mapcar (lambda (x) (concat x ":")) all-prefixes)
 		    (mapcar #'car org-stored-links)
-- 
2.39.3 (Apple Git-145)

-- 
"Music is the mathematics of the sense, mathematics is the music of the
reason."  -- James Joseph Sylvester, 1814-1897

Rudolf Adamkovič <salu...@me.com> [he/him]
Studenohorská 25
84103 Bratislava
Slovakia

Reply via email to