Export: Enable new export switches in org-mtags.el.
[org-mode/org-tableheadings.git] / contrib / lisp / org-man.el
blob27e8cca246ccbae454a44116092358568bfed910
1 ;;; org-man.el - Support for links to manpages in Org-mode
2 ;;
3 ;; Author: Carsten Dominik <carsten at orgmode dot org>
4 ;; Keywords: outlines, hypermedia, calendar, wp
5 ;; Homepage: http://orgmode.org
6 ;; Version: 1.0
7 ;;
8 ;; This file is not yet part of GNU Emacs.
9 ;;
10 ;; GNU Emacs 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)
13 ;; any later version.
15 ;; GNU Emacs 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; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
26 ;;; Commentary:
28 (require 'org)
30 (org-add-link-type "man" 'org-man-open)
31 (add-hook 'org-store-link-functions 'org-man-store-link)
33 (defcustom org-man-command 'man
34 "The Emacs command to be used to display a man page."
35 :group 'org-link
36 :type '(choice (const man) (const woman)))
38 (defun org-man-open (path)
39 "Visit the manpage on PATH.
40 PATH should be a topic that can be thrown at the man command."
41 (funcall org-man-command path))
43 (defun org-man-store-link ()
44 "Store a link to a README file."
45 (when (memq major-mode '(Man-mode woman-mode))
46 ;; This is a man page, we do make this link
47 (let* ((page (org-man-get-page-name))
48 (link (concat "man:" page))
49 (description (format "Manpage for %s" page)))
50 (org-store-link-props
51 :type "man"
52 :link link
53 :description description))))
55 (defun org-man-get-page-name ()
56 "Extract the page name from the buffer name."
57 ;; This works for both `Man-mode' and `woman-mode'.
58 (if (string-match " \\(\\S-+\\)\\*" (buffer-name))
59 (match-string 1 (buffer-name))
60 (error "Cannot create link to this man page")))
62 (provide 'org-man)
64 ;;; org-man.el ends here