Skip to content

Initial input for Org link description prompt depending upon link.

License

Notifications You must be signed in to change notification settings

firmart/org-desc-initial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 

Repository files navigation

org-desc-initial

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.

Installation

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
)

Configuration

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 take LINK, REGEX and REGION as arguments.
    • LINK is the supplied Org link.
    • REGEX is the regex which matched LINK.
    • 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

Function(s)

  • org-desc-initial-insert (&optional link): insert at point an Org link

Todo

  • README:Tips: default initial input (".*" . "")
  • GIF.

About

Initial input for Org link description prompt depending upon link.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published