From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Mark Oteiza Newsgroups: gmane.emacs.devel Subject: [PATCH] teach browse-url about man pages Date: Fri, 14 Oct 2016 21:14:21 -0400 Message-ID: <87y41qxvki.fsf@udel.edu> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1476494108 1741 195.159.176.226 (15 Oct 2016 01:15:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 15 Oct 2016 01:15:08 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 15 03:15:04 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bvDYu-0007Cw-C8 for ged-emacs-devel@m.gmane.org; Sat, 15 Oct 2016 03:14:56 +0200 Original-Received: from localhost ([::1]:50073 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvDYr-0000PI-1R for ged-emacs-devel@m.gmane.org; Fri, 14 Oct 2016 21:14:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53940) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bvDYl-0000Ox-6E for emacs-devel@gnu.org; Fri, 14 Oct 2016 21:14:48 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bvDYh-0004rz-1m for emacs-devel@gnu.org; Fri, 14 Oct 2016 21:14:46 -0400 Original-Received: from mail-qk0-x244.google.com ([2607:f8b0:400d:c09::244]:35000) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1bvDYg-0004rF-TY for emacs-devel@gnu.org; Fri, 14 Oct 2016 21:14:42 -0400 Original-Received: by mail-qk0-x244.google.com with SMTP id v138so9714062qka.2 for ; Fri, 14 Oct 2016 18:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=udel-edu.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version; bh=6fQp5p+gPCcz+wmgdVSoFGcTPGFfytHS6dnx/W/TbgE=; b=w+jHLmUODeWk52Pal/hPYCkwCCOMZhpkkEtQ1NfGW2ETVQIEK5/gc5zmvkEuHzq4lR V3HEozT1vDL5q+jltLp0OddcPuGo2GyZI+cdUyW905qV0cp3U5LatfzfqhaTreSWiIk7 F6XudxMCmAVxOCdNgF1vHUFs7h002zcmN96E5ZYhEpzlXpVnfmP/QiV12lirQeSDZz3d m0BRTT5eSVp64djH4xxqe1xBL7CL4IYyyF8NcOvKuLUomsMosu8ez4xOTtHfAB1XpV/F 3Up2edPqsxEYDeR5iDqa6JpLatC3RyZTTHezO85f8MBUgwbpQTmiqmCHJPFuAbORcvIk L3bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=6fQp5p+gPCcz+wmgdVSoFGcTPGFfytHS6dnx/W/TbgE=; b=fLfHegzimxySqJey5Aai8DR19/32u+8kkc/L4ZjSJ0qInJx0H8Co2HDtKQimj+nqp6 65pUib7N4yvDgvgpIHLLXjyZGUohKQNpJy8VfqK/i1FDId/QXt+01BtKQ7g9KiQVuXjT S0TspThA/0qnmkdo5YEJgF397T9tLLtB8nx2Rx3pNyRWxfnByn045JE+FdMhgC8VFFR8 9eoZywks+JnJ/6f5RihJ5P/iXK6Rn+ZuS6+nzoFKO3hfUprd2/6w81iuVyeLiAkWS/Xo 7c1C/7UTZ8VLIf8R/5rxtn5LOQKjac3nl9xbShyO7A5dRYJHjCWDCxTyVsz05DF8PtoN /Ezw== X-Gm-Message-State: AA6/9RkzDxnqViiI2aDNKqU99zDhW7awfvBQG5w9ZJrRMhqEhsceo1T01PSWHas9SsucDJQw X-Received: by 10.55.190.193 with SMTP id o184mr14036889qkf.31.1476494063227; Fri, 14 Oct 2016 18:14:23 -0700 (PDT) Original-Received: from holos.localdomain ([69.250.222.218]) by smtp.gmail.com with ESMTPSA id u4sm8950728qka.9.2016.10.14.18.14.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Oct 2016 18:14:22 -0700 (PDT) Original-Received: by holos.localdomain (Postfix, from userid 1000) id 9C52F66398; Fri, 14 Oct 2016 21:14:21 -0400 (EDT) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400d:c09::244 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:208263 Archived-At: 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