org.el: New command org-insert-last-stored-link bound to `C-c M-l'

* org.el (org-insert-all-links): New parameters `pre' and
`post' to specify a string to preprend and append.
(org-insert-last-stored-link): New command.
(org-mode-map): Bind the new command to `C-c M-l'.

Thanks to Sébastien Vauban for requesting this and to Nick
Dokos for testing and fixing the patch.
This commit is contained in:
Bastien Guerry 2014-01-20 15:37:25 +01:00
parent 5a2d47e1ba
commit ea0d35674f
1 changed files with 26 additions and 6 deletions

View File

@ -9923,14 +9923,33 @@ This command can be called in any mode to insert a link in Org-mode syntax."
(org-load-modules-maybe)
(org-run-like-in-org-mode 'org-insert-link))
(defun org-insert-all-links (&optional keep)
"Insert all links in `org-stored-links'."
(defun org-insert-all-links (arg &optional pre post)
"Insert all links in `org-stored-links'.
When a universal prefix, do not delete the links from `org-stored-links'.
When `ARG' is a number, insert the last N link(s).
`PRE' and `POST' are optional arguments to define a string to
prepend or to append."
(interactive "P")
(let ((links (copy-sequence org-stored-links)) l)
(while (setq l (if keep (pop links) (pop org-stored-links)))
(insert "- ")
(let ((org-keep-stored-link-after-insertion (equal arg '(4)))
(links (copy-seq org-stored-links))
(pr (or pre "- "))
(po (or post "\n"))
(cnt 1) l)
(if (null org-stored-links)
(message "No link to insert")
(while (and (or (listp arg) (>= arg cnt))
(setq l (if (listp arg)
(pop links)
(pop org-stored-links))))
(setq cnt (1+ cnt))
(insert pr)
(org-insert-link nil (car l) (or (cadr l) "<no description>"))
(insert "\n"))))
(insert po)))))
(defun org-insert-last-stored-link (arg)
"Insert the last link stored in `org-stored-links'."
(interactive "p")
(org-insert-all-links arg "" "\n"))
(defun org-link-fontify-links-to-this-file ()
"Fontify links to the current file in `org-stored-links'."
@ -19191,6 +19210,7 @@ boundaries."
(org-defkey org-mode-map "\C-c\C-x\C-n" 'org-next-link)
(org-defkey org-mode-map "\C-c\C-x\C-p" 'org-previous-link)
(org-defkey org-mode-map "\C-c\C-l" 'org-insert-link)
(org-defkey org-mode-map "\C-c\M-l" 'org-insert-last-stored-link)
(org-defkey org-mode-map "\C-c\C-\M-l" 'org-insert-all-links)
(org-defkey org-mode-map "\C-c\C-o" 'org-open-at-point)
(org-defkey org-mode-map "\C-c%" 'org-mark-ring-push)