1 ;;; org-man.el - Support for links to manpages in Org
5 (org-add-link-type "man" 'org-man-open)
6 (add-hook 'org-store-link-functions 'org-man-store-link)
8 (defcustom org-man-command 'man
9 "The Emacs command to be used to display a man page."
11 :type '(choice (const man) (const woman)))
13 (defun org-man-open (path)
14 "Visit the manpage on PATH.
15 PATH should be a topic that can be thrown at the man command."
16 (funcall org-man-command path))
18 (defun org-man-store-link ()
19 "Store a link to a manpage."
20 (when (memq major-mode '(Man-mode woman-mode))
21 ;; This is a man page, we do make this link
22 (let* ((page (org-man-get-page-name))
23 (link (concat "man:" page))
24 (description (format "Manpage for %s" page)))
28 :description description))))
30 (defun org-man-get-page-name ()
31 "Extract the page name from the buffer name."
32 ;; This works for both `Man-mode' and `woman-mode'.
33 (if (string-match " \\(\\S-+\\)\\*" (buffer-name))
34 (match-string 1 (buffer-name))
35 (error "Cannot create link to this man page")))
39 ;;; org-man.el ends here