org-link: Improve UX of 'org-insert-link'

* lisp/ol.el (org-insert-link): Shorten the text in the *Org Links*
buffer to avoid unnecessary line breaks, reword it to better align
with the rest of Emacs, and propertize its key bindings to improve
readability.  Further, move the default link to the minibuffer, as
seen elsewhere in Emacs, and make the *Org Links* buffer read-only.
This commit is contained in:
Rudolf Adamkovič 2023-12-10 00:51:31 +01:00 committed by Ihor Radchenko
parent b77f991c02
commit 664ffde149
No known key found for this signature in database
GPG key ID: 6470762A7DA11D8B

View file

@ -1868,16 +1868,32 @@ non-interactively, don't allow to edit the default description."
(org-link--fontify-links-to-this-file) (org-link--fontify-links-to-this-file)
(org-switch-to-buffer-other-window "*Org Links*") (org-switch-to-buffer-other-window "*Org Links*")
(with-current-buffer "*Org Links*" (with-current-buffer "*Org Links*"
(erase-buffer) (read-only-mode 1)
(insert "Insert a link. (let ((inhibit-read-only t)
Use TAB to complete link prefixes, then RET for type-specific completion support\n") ;; FIXME Duplicate: Also in 'ox.el'.
(when org-stored-links (propertize-help-key
(insert "\nStored links are available with <up>/<down> or M-p/n \ (lambda (key)
\(most recent with RET):\n\n") ;; Add `face' *and* `font-lock-face' to "work
(insert (mapconcat #'org-link--prettify ;; reliably in any buffer", per a comment in
(reverse org-stored-links) ;; `help--key-description-fontified'.
"\n"))) (propertize key
(goto-char (point-min))) 'font-lock-face 'help-key-binding
'face 'help-key-binding))))
(erase-buffer)
(insert
(apply #'format "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 "\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) (when (get-buffer-window "*Org Links*" 'visible)
(let ((cw (selected-window))) (let ((cw (selected-window)))
(select-window (get-buffer-window "*Org Links*" 'visible)) (select-window (get-buffer-window "*Org Links*" 'visible))
@ -1892,7 +1908,7 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
org-link--insert-history))) org-link--insert-history)))
(setq link (setq link
(org-completing-read (org-completing-read
"Link: " (org-format-prompt "Insert link" (caar org-stored-links))
(append (append
(mapcar (lambda (x) (concat x ":")) all-prefixes) (mapcar (lambda (x) (concat x ":")) all-prefixes)
(mapcar #'car org-stored-links) (mapcar #'car org-stored-links)