0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-08-21 12:18:36 +00:00

org.el: Make links more readable when selecting them for insertion.

* org.el (org-link-prettify): New function to prettify links
while displaying them with `org-insert-link'.
(org-insert-link): Use the new function.

TINYCHANGE
This commit is contained in:
Dave Abrahams 2012-04-20 19:41:02 +02:00 committed by Bastien Guerry
parent a9d3ce0bcd
commit a84fa6eccd

View file

@ -9103,6 +9103,14 @@ Note: this function also decodes single byte encodings like
(setq s (replace-match "%40" t t s)))
s)
(defun org-link-prettify (link)
"Return a human-readable representation of LINK.
The car of LINK must be a raw link the cdr of LINK must be either
a link description or nil."
(let ((desc (or (cadr link) "<no description>")))
(concat (format "%-45s" (substring desc 0 (min (length desc) 40)))
"[[" (car link) "]]")))
;;;###autoload
(defun org-insert-link-global ()
"Insert a link like Org-mode does.
@ -9185,9 +9193,7 @@ be used as the default description."
Use TAB to complete link prefixes, then RET for type-specific completion support\n")
(when org-stored-links
(princ "\nStored links are available with <up>/<down> or M-p/n (most recent with RET):\n\n")
(princ (mapconcat
(lambda (x)
(if (nth 1 x) (concat (car x) " (" (nth 1 x) ")") (car x)))
(princ (mapconcat 'org-link-prettify
(reverse org-stored-links) "\n"))))
(let ((cw (selected-window)))
(select-window (get-buffer-window "*Org Links*" 'visible))
@ -9196,7 +9202,7 @@ Use TAB to complete link prefixes, then RET for type-specific completion support
(org-fit-window-to-buffer))
(and (window-live-p cw) (select-window cw)))
;; Fake a link history, containing the stored links.
(setq tmphist (append (mapcar 'car org-stored-links)
(setq tmphist (append (mapcar 'org-link-prettify org-stored-links)
org-insert-link-history))
(setq all-prefixes (append (mapcar 'car org-link-abbrev-alist-local)
(mapcar 'car org-link-abbrev-alist)