lisp/org-table.el: fix table alignment
[org-mode/org-tableheadings.git] / contrib / lisp / ol-man.el
blobcdbf47131bc4ff2421d03f6c8716fee025b803a4
1 ;;; ol-man.el - Links to man pages
2 ;;
3 ;; Author: Carsten Dominik <carsten at orgmode dot org>
4 ;; Keywords: outlines, hypermedia, calendar, wp
5 ;; Homepage: https://orgmode.org
6 ;; Version: 1.0
7 ;;
8 ;; This file is not yet part of GNU Emacs.
9 ;;
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)
13 ;; any later version.
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
24 ;;; Commentary:
26 (require 'ol)
27 (require 'org)
29 (org-link-set-parameters "man"
30 :follow #'org-man-open
31 :export #'org-man-export
32 :store #'org-man-store-link)
34 (defcustom org-man-command 'man
35 "The Emacs command to be used to display a man page."
36 :group 'org-link
37 :type '(choice (const man) (const woman)))
39 (defun org-man-open (path)
40 "Visit the manpage on PATH.
41 PATH should be a topic that can be thrown at the man command."
42 (funcall org-man-command path))
44 (defun org-man-store-link ()
45 "Store a link to a README file."
46 (when (memq major-mode '(Man-mode woman-mode))
47 ;; This is a man page, we do make this link
48 (let* ((page (org-man-get-page-name))
49 (link (concat "man:" page))
50 (description (format "Manpage for %s" page)))
51 (org-store-link-props
52 :type "man"
53 :link link
54 :description description))))
56 (defun org-man-get-page-name ()
57 "Extract the page name from the buffer name."
58 ;; This works for both `Man-mode' and `woman-mode'.
59 (if (string-match " \\(\\S-+\\)\\*" (buffer-name))
60 (match-string 1 (buffer-name))
61 (error "Cannot create link to this man page")))
63 (defun org-man-export (link description format)
64 "Export a man page link from Org files."
65 (let ((path (format "http://man.he.net/?topic=%s&section=all" link))
66 (desc (or description link)))
67 (cond
68 ((eq format 'html) (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc))
69 ((eq format 'latex) (format "\\href{%s}{%s}" path desc))
70 ((eq format 'texinfo) (format "@uref{%s,%s}" path desc))
71 ((eq format 'ascii) (format "%s (%s)" desc path))
72 (t path))))
74 (provide 'ol-man)
76 ;;; ol-man.el ends here