1 ;;; org-man.el - Support for links to manpages in Org-mode
3 ;; Author: Carsten Dominik <carsten at orgmode dot org>
4 ;; Keywords: outlines, hypermedia, calendar, wp
5 ;; Homepage: http://orgmode.org
8 ;; This file is not yet part of GNU Emacs.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 3, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 (org-add-link-type "man" 'org-man-open
'org-man-export
)
29 (add-hook 'org-store-link-functions
'org-man-store-link
)
31 (defcustom org-man-command
'man
32 "The Emacs command to be used to display a man page."
34 :type
'(choice (const man
) (const woman
)))
36 (defun org-man-open (path)
37 "Visit the manpage on PATH.
38 PATH should be a topic that can be thrown at the man command."
39 (funcall org-man-command path
))
41 (defun org-man-store-link ()
42 "Store a link to a README file."
43 (when (memq major-mode
'(Man-mode woman-mode
))
44 ;; This is a man page, we do make this link
45 (let* ((page (org-man-get-page-name))
46 (link (concat "man:" page
))
47 (description (format "Manpage for %s" page
)))
51 :description description
))))
53 (defun org-man-get-page-name ()
54 "Extract the page name from the buffer name."
55 ;; This works for both `Man-mode' and `woman-mode'.
56 (if (string-match " \\(\\S-+\\)\\*" (buffer-name))
57 (match-string 1 (buffer-name))
58 (error "Cannot create link to this man page")))
60 (defun org-man-export (link description format
)
61 "Export a man page link from Org files."
62 (let ((path (format "http://man.he.net/?topic=%s§ion=all" link
))
63 (desc (or description link
)))
65 ((eq format
'html
) (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc
))
66 ((eq format
'latex
) (format "\\href{%s}{%s}" path desc
))
67 ((eq format
'texinfo
) (format "@uref{%s,%s}" path desc
))
68 ((eq format
'ascii
) (format "%s (%s)" desc path
))
73 ;;; org-man.el ends here