From: Stefan Kangas <stefan@marxist.se>
To: Drew Adams <drew.adams@oracle.com>
Cc: 44895@debbugs.gnu.org, "積丹尼 Dan Jacobson" <jidanni@jidanni.org>
Subject: bug#44895: Add Info-copy-permalink
Date: Fri, 27 Nov 2020 11:44:10 +0100 [thread overview]
Message-ID: <CADwFkmk-Fx6fO=Kb6a1sQfs250dgh+NgwvnKzPCWGeEv570H8Q@mail.gmail.com> (raw)
In-Reply-To: <f0a9e6fb-8b09-4f2a-996a-4cf131d8bd6d@default>
[-- Attachment #1: Type: text/plain, Size: 328 bytes --]
Drew Adams <drew.adams@oracle.com> writes:
> If you use Info+ then `G' (`Info-goto-node-web')
> takes you to the Web version of the current node.
>
> It uses function `Info-url-for-node' (also from
> Info+) to get the URL for that.
I think this looks useful for Emacs itself. A rough attempt at doing
so attached.
Thoughts?
[-- Attachment #2: info-goto-web.diff --]
[-- Type: application/octet-stream, Size: 5918 bytes --]
diff --git a/lisp/info.el b/lisp/info.el
index c3684deb96..a3715942aa 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -1781,7 +1781,92 @@ Info-goto-node
(if trim (setq nodename (substring nodename 0 trim))))
(if transient-mark-mode (deactivate-mark))
(Info-find-node (if (equal filename "") nil filename)
- (if (equal nodename "") "Top" nodename) nil strict-case)))
+ (if (equal nodename "") "Top" nodename) nil strict-case)))
+
+;;;###autoload
+(defun Info-goto-node-web (node &optional flip-new-win)
+ "Use `browse-url' to go to Info node NODE using a Web browser.
+With a prefix arg, reverse the effect of option
+`browse-url-new-window-flag'.
+
+NODE is the name of a node in the GNU Emacs or Elisp manual.
+Alternatively, NODE can have the form (MANUAL)NODE, where MANUAL is
+\"emacs\" or \"elisp\" and NODE is the name of the node in that
+manual. Empty NODE in (MANUAL) defaults to the `Top' node."
+ (interactive (list (Info-read-node-name "Go to node: " Info-current-node) current-prefix-arg))
+ (require 'browse-url)
+ (unless Info-current-file (error "This command must be invoked from Info"))
+ (browse-url (Info-url-for-node node) (list (if flip-new-win
+ (not browse-url-new-window-flag)
+ browse-url-new-window-flag))))
+
+;; See https://www.gnu.org/software/texinfo/manual/texinfo/html_node/
+;; HTML-Xref-Node-Name-Expansion.html
+;;
+;; 1. The standard ASCII letters (a-z and A-Z) are not modified. All
+;; other characters may be changed as specified below.
+;;
+;; 2. The standard ASCII numbers (0-9) are not modified except when a
+;; number is the first character of the node name. In that case, see
+;; below.
+;;
+;; 3. Multiple consecutive space, tab and newline characters are
+;; transformed into just one space. (It’s not possible to have
+;; newlines in node names with the current implementation, but we
+;; specify it anyway, just in case.)
+;;
+;; 4. Leading and trailing spaces are removed.
+;;
+;; 5. After the above has been applied, each remaining space character is
+;; converted into a ‘-’ character.
+;;
+;; 6. Other ASCII 7-bit characters are transformed into ‘_00xx’, where xx
+;; is the ASCII character code in (lowercase) hexadecimal. This includes
+;; ‘_’, which is mapped to ‘_005f’.
+;;
+;; 7. If the node name does not begin with a letter, the literal string
+;; ‘g_t’ is prefixed to the result. (Due to the rules above, that
+;; string can never occur otherwise; it is an arbitrary choice,
+;; standing for “GNU Texinfo”.) This is necessary because XHTML
+;; requires that identifiers begin with a letter.
+;;
+;;;###autoload
+(defun Info-url-for-node (node)
+ "Return a URL for NODE, a node in the GNU Emacs or Elisp manual.
+Alternatively, NODE can have the form (MANUAL)NODE, where MANUAL is
+\"emacs\" or \"elisp\" and NODE is the name of the node in that
+manual. Empty NODE in (MANUAL) defaults to the `Top' node."
+ (interactive (list (Info-read-node-name "Node: " Info-current-node)))
+ (unless Info-current-file (error "This command must be invoked from Info"))
+ (let (file url)
+ (string-match "\\s *\\((\\s *\\([^\t)]*\\)\\s *)\\s *\\|\\)\\(.*\\)" node)
+ (setq file (if (= (match-beginning 1) (match-end 1)) "" (match-string 2 node))
+ node (match-string 3 node))
+ (when (equal node "") (setq node "index")) ; `Top' node.
+ (let ((trim (string-match "\\s +\\'" file)))
+ (when trim (setq file (substring file 0 trim))))
+ (let ((trim (string-match "\\s +\\'" node)))
+ (when trim (setq node (substring node 0 trim))))
+ (when (equal file "") (setq file Info-current-file))
+ (setq file (file-name-sans-extension (file-name-nondirectory file)))
+ (unless (member file '("emacs" "elisp"))
+ (error "Manual cannot be `%s'; it can only be `emacs' or `elisp'" file))
+ (setq node (mapconcat (lambda (ch)
+ (if (or (< ch 32) ; ^@^A-^Z^[^\^]^^^-
+ (and (<= 33 ch) (<= ch 47)) ; !"#$%&'()*+,-./
+ (and (<= 58 ch) (<= ch 64)) ; :;<=>?@
+ (and (<= 91 ch) (<= ch 96)) ; [\]_`
+ (and (<= 123 ch) (<= ch 127))) ; {|}~ DEL
+ (format "_00%x" ch)
+ (char-to-string ch)))
+ node
+ ""))
+ (setq node (replace-regexp-in-string "[ \t]+" "-" node t t))
+ (unless (string-match-p "[[:alpha:]]" node) (setq node (concat "g_t" node)))
+ (setq url (concat "https://www.gnu.org/software/emacs/manual/html_node/"
+ file "/" node ".html"))
+ (message "URL: %s" url)
+ url))
(defvar Info-read-node-completion-table)
@@ -1865,7 +1950,7 @@ Info-read-node-name-1
code Info-read-node-completion-table string predicate))))
;; Arrange to highlight the proper letters in the completion list buffer.
-(defun Info-read-node-name (prompt)
+(defun Info-read-node-name (prompt &optional default)
"Read an Info node name with completion, prompting with PROMPT.
A node name can have the form \"NODENAME\", referring to a node
in the current Info file, or \"(FILENAME)NODENAME\", referring to
@@ -1873,7 +1958,8 @@ Info-read-node-name
the Top node in FILENAME."
(let* ((completion-ignore-case t)
(Info-read-node-completion-table (Info-build-node-completions))
- (nodename (completing-read prompt #'Info-read-node-name-1 nil t)))
+ (nodename (completing-read prompt #'Info-read-node-name-1 nil t nil
+ 'Info-minibuf-history default)))
(if (equal nodename "")
(Info-read-node-name prompt)
nodename)))
next prev parent reply other threads:[~2020-11-27 10:44 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-26 21:39 bug#44895: Add Info-copy-permalink 積丹尼 Dan Jacobson
2020-11-26 23:06 ` Drew Adams
2020-11-26 23:20 ` 積丹尼 Dan Jacobson
2020-11-27 0:29 ` Drew Adams
2020-11-27 5:34 ` Richard Stallman
2020-11-27 7:24 ` Eli Zaretskii
2020-11-27 10:44 ` Stefan Kangas [this message]
2020-11-27 10:57 ` Jean Louis
2020-11-27 12:32 ` Eli Zaretskii
2020-11-28 7:47 ` Stefan Kangas
2020-11-28 8:21 ` Eli Zaretskii
2020-11-27 18:51 ` Drew Adams
2020-11-27 7:23 ` Eli Zaretskii
2020-11-27 8:14 ` Jean Louis
2020-11-27 8:40 ` Eli Zaretskii
2020-11-27 8:47 ` Jean Louis
2020-11-27 20:19 ` Tomas Nordin
2020-11-27 23:27 ` 積丹尼 Dan Jacobson
2020-11-27 9:45 ` Stephen Berman
2020-11-27 10:21 ` Jean Louis
2020-11-27 18:46 ` Drew Adams
2021-11-11 7:11 ` Lars Ingebrigtsen
2021-11-11 17:26 ` bug#44895: [External] : " Drew Adams
2021-11-11 17:40 ` Juri Linkov
2021-11-11 17:58 ` Drew Adams
2021-11-12 3:32 ` Lars Ingebrigtsen
2021-11-12 7:41 ` Robert Pluim
2021-11-12 7:48 ` Lars Ingebrigtsen
2021-11-12 17:17 ` Drew Adams
2021-11-14 0:06 ` 積丹尼 Dan Jacobson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADwFkmk-Fx6fO=Kb6a1sQfs250dgh+NgwvnKzPCWGeEv570H8Q@mail.gmail.com' \
--to=stefan@marxist.se \
--cc=44895@debbugs.gnu.org \
--cc=drew.adams@oracle.com \
--cc=jidanni@jidanni.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).