2019-03-01 19:01:32 -05:00
|
|
|
;;; ol-man.el - Links to man pages
|
2008-03-14 04:45:26 -04:00
|
|
|
;;
|
|
|
|
;; Author: Carsten Dominik <carsten at orgmode dot org>
|
|
|
|
;; Keywords: outlines, hypermedia, calendar, wp
|
2018-01-16 11:22:00 -05:00
|
|
|
;; Homepage: https://orgmode.org
|
2008-03-14 04:45:26 -04:00
|
|
|
;; Version: 1.0
|
|
|
|
;;
|
|
|
|
;; This file is not yet part of GNU Emacs.
|
|
|
|
;;
|
2013-03-10 12:57:47 -04:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
2008-03-14 04:45:26 -04:00
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
;; any later version.
|
|
|
|
|
2013-03-10 12:57:47 -04:00
|
|
|
;; This program is distributed in the hope that it will be useful,
|
2008-03-14 04:45:26 -04:00
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2013-03-10 12:57:47 -04:00
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
2008-03-14 04:45:26 -04:00
|
|
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
2008-01-31 10:04:26 -05:00
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
(require 'ol)
|
2008-01-31 10:04:26 -05:00
|
|
|
|
2016-08-07 21:24:23 -04:00
|
|
|
(org-link-set-parameters "man"
|
|
|
|
:follow #'org-man-open
|
|
|
|
:export #'org-man-export
|
|
|
|
:store #'org-man-store-link)
|
2008-01-31 10:04:26 -05:00
|
|
|
|
|
|
|
(defcustom org-man-command 'man
|
|
|
|
"The Emacs command to be used to display a man page."
|
|
|
|
:group 'org-link
|
|
|
|
:type '(choice (const man) (const woman)))
|
|
|
|
|
2020-02-17 05:28:50 -05:00
|
|
|
(defun org-man-open (path _)
|
2008-01-31 10:04:26 -05:00
|
|
|
"Visit the manpage on PATH.
|
2020-08-14 00:37:42 -04:00
|
|
|
PATH should be a topic that can be thrown at the man command.
|
|
|
|
If PATH contains extra ::STRING which will use `occur' to search
|
|
|
|
matched strings in man buffer."
|
|
|
|
(string-match "\\(.*?\\)\\(?:::\\(.*\\)\\)?$" path)
|
|
|
|
(let* ((command (match-string 1 path))
|
|
|
|
(search (match-string 2 path)))
|
|
|
|
(funcall org-man-command command)
|
|
|
|
(when search
|
|
|
|
(with-current-buffer (concat "*Man " command "*")
|
|
|
|
(goto-char (point-min))
|
|
|
|
(search-forward search)))))
|
2008-01-31 10:04:26 -05:00
|
|
|
|
|
|
|
(defun org-man-store-link ()
|
|
|
|
"Store a link to a README file."
|
|
|
|
(when (memq major-mode '(Man-mode woman-mode))
|
|
|
|
;; This is a man page, we do make this link
|
|
|
|
(let* ((page (org-man-get-page-name))
|
|
|
|
(link (concat "man:" page))
|
|
|
|
(description (format "Manpage for %s" page)))
|
2020-01-09 11:48:12 -05:00
|
|
|
(org-link-store-props
|
2008-01-31 10:04:26 -05:00
|
|
|
:type "man"
|
|
|
|
:link link
|
|
|
|
:description description))))
|
|
|
|
|
|
|
|
(defun org-man-get-page-name ()
|
|
|
|
"Extract the page name from the buffer name."
|
|
|
|
;; This works for both `Man-mode' and `woman-mode'.
|
|
|
|
(if (string-match " \\(\\S-+\\)\\*" (buffer-name))
|
|
|
|
(match-string 1 (buffer-name))
|
|
|
|
(error "Cannot create link to this man page")))
|
|
|
|
|
2013-01-24 10:09:12 -05:00
|
|
|
(defun org-man-export (link description format)
|
|
|
|
"Export a man page link from Org files."
|
|
|
|
(let ((path (format "http://man.he.net/?topic=%s§ion=all" link))
|
|
|
|
(desc (or description link)))
|
|
|
|
(cond
|
|
|
|
((eq format 'html) (format "<a target=\"_blank\" href=\"%s\">%s</a>" path desc))
|
2013-04-15 17:38:39 -04:00
|
|
|
((eq format 'latex) (format "\\href{%s}{%s}" path desc))
|
2013-04-16 06:51:08 -04:00
|
|
|
((eq format 'texinfo) (format "@uref{%s,%s}" path desc))
|
2013-01-24 10:09:12 -05:00
|
|
|
((eq format 'ascii) (format "%s (%s)" desc path))
|
2020-06-14 16:19:20 -04:00
|
|
|
((eq format 'md) (format "[%s](%s)" desc path))
|
2013-01-24 10:09:12 -05:00
|
|
|
(t path))))
|
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
(provide 'ol-man)
|
2008-01-31 10:04:26 -05:00
|
|
|
|
2019-03-01 19:01:32 -05:00
|
|
|
;;; ol-man.el ends here
|