[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] teach browse-url about man pages
From: |
Mark Oteiza |
Subject: |
[PATCH] teach browse-url about man pages |
Date: |
Fri, 14 Oct 2016 21:14:21 -0400 |
We should be able to browse to man page urls within emacs.
Not sure about a couple things:
- whether something like browse-url-man-viewer should be added. Are
there some other commonly used man page reader? I don't know.
- the :version
but otherwise, pretty straightforward, mostly derived from the mailto:
bits.
diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index c0b3591..91f6f2f 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -184,6 +184,22 @@ browse-url-mailto-function
:version "24.1"
:group 'browse-url)
+(defcustom browse-url-man-function 'browse-url-man
+ "Function to display man: links."
+ :type '(choice
+ (function-item :tag "Emacs Man" :value browse-url-man)
+ (function-item :tag "None" nil))
+ :version "26.1"
+ :group 'browse-url)
+
+(defcustom browse-url-man-viewer 'man
+ "Function to display Un*x man pages."
+ :type '(radio (function-item man)
+ (function-item woman)
+ (function :tag "Other function"))
+ :version "26.1"
+ :group 'browse-url)
+
(defcustom browse-url-netscape-program "netscape"
;; Info about netscape-remote from Karl Berry.
"The name by which to invoke Netscape.
@@ -801,6 +817,8 @@ browse-url
(let ((process-environment (copy-sequence process-environment))
(function (or (and (string-match "\\`mailto:" url)
browse-url-mailto-function)
+ (and (string-match "\\`man:" url)
+ browse-url-man-function)
browse-url-browser-function))
;; Ensure that `default-directory' exists and is readable (b#6077).
(default-directory (or (unhandled-file-name-directory default-directory)
@@ -1588,6 +1606,20 @@ browse-url-mail
(unless (bolp)
(insert "\n"))))))))
+;; --- man ---
+
+(defvar manual-program)
+
+(defun browse-url-man (url &optional _new-window)
+ "Open a man page."
+ (interactive (browse-url-interactive-arg "Man page URL: "))
+ (require 'man)
+ (setq url (replace-regexp-in-string "\\`man:" "" url))
+ (pcase browse-url-man-viewer
+ (`man (man url))
+ (`woman (woman (replace-regexp-in-string "([[:alnum:]]+)" "" url)))
+ (_ (apply 'browse-url-man-viewer url))))
+
;; --- Random browser ---
;;;###autoload
- [PATCH] teach browse-url about man pages,
Mark Oteiza <=