org-man.el 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. ;;; org-man.el - Support for links to manpages in Org-mode
  2. (require 'org)
  3. (org-add-link-type "man" 'org-man-open)
  4. (add-hook 'org-store-link-functions 'org-man-store-link)
  5. (defcustom org-man-command 'man
  6. "The Emacs command to be used to display a man page."
  7. :group 'org-link
  8. :type '(choice (const man) (const woman)))
  9. (defun org-man-open (path)
  10. "Visit the manpage on PATH.
  11. PATH should be a topic that can be thrown at the man command."
  12. (funcall org-man-command path))
  13. (defun org-man-store-link ()
  14. "Store a link to a README file."
  15. (when (memq major-mode '(Man-mode woman-mode))
  16. ;; This is a man page, we do make this link
  17. (let* ((page (org-man-get-page-name))
  18. (link (concat "man:" page))
  19. (description (format "Manpage for %s" page)))
  20. (org-store-link-props
  21. :type "man"
  22. :link link
  23. :description description))))
  24. (defun org-man-get-page-name ()
  25. "Extract the page name from the buffer name."
  26. ;; This works for both `Man-mode' and `woman-mode'.
  27. (if (string-match " \\(\\S-+\\)\\*" (buffer-name))
  28. (match-string 1 (buffer-name))
  29. (error "Cannot create link to this man page")))
  30. (provide 'org-man)
  31. ;;; org-man.el ends here