12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- (require 'org)
- (org-add-link-type "man" 'org-man-open 'org-man-export)
- (add-hook 'org-store-link-functions 'org-man-store-link)
- (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)))
- (defun org-man-open (path)
- "Visit the manpage on PATH.
- PATH should be a topic that can be thrown at the man command."
- (funcall org-man-command path))
- (defun org-man-store-link ()
- "Store a link to a README file."
- (when (memq major-mode '(Man-mode woman-mode))
-
- (let* ((page (org-man-get-page-name))
- (link (concat "man:" page))
- (description (format "Manpage for %s" page)))
- (org-store-link-props
- :type "man"
- :link link
- :description description))))
- (defun org-man-get-page-name ()
- "Extract the page name from the buffer name."
-
- (if (string-match " \\(\\S-+\\)\\*" (buffer-name))
- (match-string 1 (buffer-name))
- (error "Cannot create link to this man page")))
- (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))
- ((eq format 'latex) (format "\\href{%s}{%s}" path desc))
- ((eq format 'texinfo) (format "@uref{%s,%s}" path desc))
- ((eq format 'ascii) (format "%s (%s)" desc path))
- (t path))))
- (provide 'org-man)
|