This package provides a handy way to supply Org link description. It is done by setting regex-based rules to supply initial input to the description prompt.
The following installation relies on quelpa-use-package, but it is
straightforward to clone this repo locally and use use-package
instead.
(use-package org-desc-initial
:ensure t
:quelpa (org-desc-initial :fetcher github :repo "firmart/org-desc-initial")
:config
;; See below
)
The configuration of this package depends on the associated list
org-desc-initial-alist
whose the element is of the form (link-regex
. initial-input)
.
LINK-REGEX
is a regex which is intended to match an Org link. It can contain group\\(...\\)
.INITIAL-INPUT
is either a string or a function. If it is a string, the initial input will be simply the string. On the other hand, if it is a function, it should takeLINK
,REGEX
andREGION
as arguments.LINK
is the supplied Org link.REGEX
is the regex which matchedLINK
.REGION
is the string of the current region,nil
otherwise.
(setq org-desc-initial-alist
'(("https://en.wikipedia\\.org.*" . my/org-desc-en-wiki)
("https://www.emacswiki.org/emacs/\\(.*\\)" . my/org-desc-emacs-wiki)
("file:.*" . "FILE: ")
("pdf:.*" . "PDF: ")))
(defun my/org-desc-emacs-wiki (link regex region)
(string-match regex link)
(concat "Emacs Wiki: "
(or region (match-string 1 link))))
(defun my/org-desc-en-wiki (link regex region)
(string-match regex link)
(concat "Wikipedia: "
(or region (replace-regexp-in-string "_" " "
(match-string 1 link)))))
You can try the result by calling org-desc-initial-insert
.
With the above configuration, the initial input of the following links are
https://en.wikipedia.org/wiki/Johann_Sebastian_Bach
->Wikipedia: Johann Sebastian Bach
https://www.emacswiki.org/emacs/PatternMatching
->Emacs Wiki: PatternMatching
org-desc-initial-insert (&optional link)
: insert at point an Org link
- README:Tips: default initial input
(".*" . "")
- GIF.