unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Mekeor Melire <mekeor@posteo.de>
To: 67615@debbugs.gnu.org
Cc: Eli Zaretskii <eliz@gnu.org>
Subject: bug#67615: [PATCH v6] Add option Info-url-alist
Date: Sat, 20 Jan 2024 00:50:22 +0000	[thread overview]
Message-ID: <87edec3jcl.fsf@posteo.de> (raw)
In-Reply-To: <83a5p9h87s.fsf@gnu.org>

[-- Attachment #1: Type: text/plain, Size: 1406 bytes --]

2024-01-13 11:51 eliz@gnu.org:

> > From: Mekeor Melire <mekeor@posteo.de>
> > Cc: 67615@debbugs.gnu.org
> > Date: Mon, 08 Jan 2024 21:56:03 +0000

> I was going to install this, but it causes info-tests in the test
> suite to fail:

> If we want the result to include the "html" extension (which might not
> be correct, since perhaps we could have Minibuffer.htm?), then please
> update the test.  Otherwise, it sounds like the code needs some
> adjustment to behave as before?

I vote for keeping the ".html" suffix because I can imagine that Texinfo
creates only files with that suffix and it's depends on the web-server
and its configuration if the file is also served when the suffix is
missed in the URL.

Unfortunately, I was not able to verify this in the Texinfo
documentation or source code.

I had to make another adjustment info-test.el to make the test succeed:
Previously, Info-node-for-url failed when the passed manual-name was
neither "emacs" nor "elisp". In particular, it failed for "gnus". Now
that "gnus" is a handled manual-name, it succeeds. But it should still
error when the manual-name is not handled (by the default value of the
newly introduced Info-url-alist).

> Please also improve the commit log message to mention all the changes,
> not just the new option.  See CONTRIBUTE for details, and you can use
> "git log" to see many examples of how we do that.

I gave my best.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-option-Info-url-alist.patch --]
[-- Type: text/x-patch, Size: 8323 bytes --]

From 1e75f8397fb6396b2244e87d5a66062c8a11ee16 Mon Sep 17 00:00:00 2001
From: Mekeor Melire <mekeor@posteo.de>
Date: Mon, 4 Dec 2023 16:37:37 +0100
Subject: [PATCH] Add option Info-url-alist

* lisp/info.el (Info-url-alist): New option mapping manuals to URLs.
(Info-url-for-node): Use it.
* test/lisp/info-tests.el (test-info-urls): Info-url-for-node should
error when manual-name is not handled in Info-url-alist.
* etc/NEWS: Announce the change.
---
 etc/NEWS                |   9 ++++
 lisp/info.el            | 113 +++++++++++++++++++++++++++++++---------
 test/lisp/info-tests.el |   4 +-
 3 files changed, 100 insertions(+), 26 deletions(-)

diff --git a/etc/NEWS b/etc/NEWS
index a6b0beb6ee5..f0540df95f7 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -402,6 +402,15 @@ respectively, in addition to the existing translations 'C-x 8 / e' and
 \f
 * Changes in Specialized Modes and Packages in Emacs 30.1
 
+** Info
+
+---
+*** New user option 'Info-url-alist'.
+This user option associates manual-names with URLs.  It affects the
+'Info-goto-node-web' command.  By default, associations for all
+Emacs-included manuals are set.  Further associations can be added for
+arbitrary Info manuals.
+
 +++
 ** New command 'lldb'.
 Run the LLDB debugger, analogous to the 'gud-gdb' command.
diff --git a/lisp/info.el b/lisp/info.el
index 39ca88c358c..78512d0d518 100644
--- a/lisp/info.el
+++ b/lisp/info.el
@@ -213,6 +213,53 @@ Info-additional-directory-list
 These directories are searched after those in `Info-directory-list'."
   :type '(repeat directory))
 
+(defcustom Info-url-alist
+  '((("auth" "autotype" "bovine" "calc" "ccmode" "cl" "dbus" "dired-x"
+      "ebrowse" "ede" "ediff" "edt" "efaq" "efaq-w32" "eglot" "eieio"
+      "eintr" "elisp" "emacs" "emacs-gnutls" "emacs-mime" "epa" "erc"
+      "ert" "eshell" "eudc" "eww" "flymake" "forms" "gnus"
+      "htmlfontify" "idlwave" "ido" "info" "mairix-el" "message"
+      "mh-e" "modus-themes" "newsticker" "nxml-mode" "octave-mode"
+      "org" "pcl-cvs" "pgg" "rcirc" "reftex" "remember" "sasl" "sc"
+      "semantic" "ses" "sieve" "smtpmail" "speedbar" "srecode"
+      "todo-mode" "tramp" "transient" "url" "use-package" "vhdl-mode"
+      "vip" "viper" "vtable" "widget" "wisent" "woman") .
+     "https://www.gnu.org/software/emacs/manual/html_node/%m/%e"))
+  "Alist telling `Info-mode' where manuals are accessible online.
+
+Each element of this list has the form (MANUALs . URL-SPEC).
+MANUALs represents the name of one or more manuals.  It can
+either be a string or a list of strings.  URL-SPEC can be a
+string in which the substring \"%m\" will be expanded to the
+manual-name, \"%n\" to the node-name, and \"%e\" to the
+URL-encoded node-name with a `.html' suffix.  (The URL-encoding
+of the node-name mimics GNU Texinfo, as documented at Info
+node `(texinfo)HTML Xref Node Name Expansion'.)  Alternatively,
+URL-SPEC can be a function which is given manual-name, node-name
+and URL-encoded node-name as arguments, and is expected to return
+the corresponding URL as a string.
+
+This variable particularly affects the command
+`Info-goto-node-web', which see.
+
+The default value of this variable refers to the official,
+HTTPS-accessible HTML-representations of all manuals that Emacs
+includes.  These URLs refer to the most recently released version
+of Emacs, disregarding the version of the running Emacs.  In
+other words, the content of your local Info node and the
+associated online node may differ.  The resource represented by
+the generated URL may even be not found by the gnu.org server."
+  :version "30.1"
+  :type '(alist
+           :tag "Mapping from manual-name(s) to URL-specification"
+           :key-type (choice
+                       (string :tag "A single manual-name")
+                       (repeat :tag "List of manual-names" string))
+           :value-type (choice
+                         (string :tag "URL-specification string")
+                         (function
+                           :tag "URL-specification function"))))
+
 (defcustom Info-scroll-prefer-subnodes nil
   "If non-nil, \\<Info-mode-map>\\[Info-scroll-up] in a menu visits subnodes.
 
@@ -1807,33 +1854,49 @@ Info-goto-node-web
      (Info-url-for-node (format "(%s)%s" filename node)))))
 
 (defun Info-url-for-node (node)
-  "Return a URL for NODE, a node in the GNU Emacs or Elisp manual.
-NODE should be a string on the form \"(manual)Node\".  Only emacs
-and elisp manuals are supported."
+  "Return the URL corresponding to NODE.
+
+NODE should be a string of the form \"(manual)Node\"."
   (unless (string-match "\\`(\\(.+\\))\\(.+\\)\\'" node)
-    (error "Invalid node name %s" node))
-  (let ((manual (match-string 1 node))
-        (node (match-string 2 node)))
-    (unless (member manual '("emacs" "elisp"))
-      (error "Only emacs/elisp manuals are supported"))
-    ;; Encode a bunch of characters the way that makeinfo does.
-    (setq node
-          (mapconcat (lambda (ch)
-                       (if (or (< ch 32)        ; ^@^A-^Z^[^\^]^^^-
-                               (<= 33 ch 47)    ; !"#$%&'()*+,-./
-                               (<= 58 ch 64)    ; :;<=>?@
-                               (<= 91 ch 96)    ; [\]_`
-                               (<= 123 ch 127)) ; {|}~ DEL
-                           (format "_00%x" ch)
-                         (char-to-string ch)))
-                     node
-                     ""))
-    (concat "https://www.gnu.org/software/emacs/manual/html_node/"
-            manual "/"
-            (and (not (equal node "Top"))
+    (error "Invalid node-name %s" node))
+  ;; Use `if-let*' instead of `let*' so we check if an association was
+  ;; found.
+  (if-let* ((manual (match-string 1 node))
+             (node (match-string 2 node))
+             (association (seq-find
+                            (lambda (pair)
+                              (seq-contains-p (ensure-list (car pair))
+                                manual #'string-equal-ignore-case))
+                            Info-url-alist))
+             (url-spec (cdr association))
+             (encoded-node
+               ;; Reproduce GNU Texinfo's way of URL-encoding.
+               ;; (info "(texinfo) HTML Xref Node Name Expansion")
+               (if (equal node "Top")
+                 ""
                  (concat
-                  (url-hexify-string (string-replace " " "-" node))
-                  ".html")))))
+                   (url-hexify-string
+                     (string-replace " " "-"
+                       (mapconcat
+                         (lambda (ch)
+                           (if (or (< ch 32)      ; ^@^A-^Z^[^\^]^^^-
+                                 (<= 33 ch 47)    ; !"#$%&'()*+,-./
+                                 (<= 58 ch 64)    ; :;<=>?@
+                                 (<= 91 ch 96)    ; [\]_`
+                                 (<= 123 ch 127)) ; {|}~ DEL
+                             (format "_00%x" ch)
+                             (char-to-string ch)))
+                         node "")))
+                   ".html"))))
+    (cond
+      ((stringp url-spec)
+        (format-spec url-spec
+          `((?m . ,manual) (?n . ,node) (?e . ,encoded-node))))
+      ((functionp url-spec)
+        (funcall url-spec manual node encoded-node))
+      (t (error "URL-specification neither string nor function")))
+    (error "No URL-specification associated with manual-name `%s'"
+      manual)))
 
 (defvar Info-read-node-completion-table)
 
diff --git a/test/lisp/info-tests.el b/test/lisp/info-tests.el
index ebe718167bf..b4f94b77030 100644
--- a/test/lisp/info-tests.el
+++ b/test/lisp/info-tests.el
@@ -34,6 +34,8 @@ test-info-urls
                  "https://www.gnu.org/software/emacs/manual/html_node/emacs/Minibuffer-File.html"))
   (should (equal (Info-url-for-node "(elisp)Backups and Auto-Saving")
                  "https://www.gnu.org/software/emacs/manual/html_node/elisp/Backups-and-Auto_002dSaving.html"))
-  (should-error (Info-url-for-node "(gnus)Minibuffer File")))
+  (should (equal (Info-url-for-node  "(gnus)Don't Panic")
+                 "https://www.gnu.org/software/emacs/manual/html_node/gnus/Don_0027t-Panic.html"))
+  (should-error (Info-url-for-node "(nonexistent)Example")))
 
 ;;; info-tests.el ends here
-- 
2.41.0


  reply	other threads:[~2024-01-20  0:50 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04  0:04 bug#67615: [PATCH] * lisp/info.el (Info-url-for-node): Support all Emacs info manuals Mekeor Melire
2023-12-04  0:30 ` Mekeor Melire
2023-12-04 10:02   ` bug#67615: [PATCH v2] " Mekeor Melire
2023-12-04 15:51     ` Mekeor Melire
2023-12-04 16:24       ` Eli Zaretskii
2023-12-05  1:06         ` bug#67615: Org-Mode story on how I gathered the list of Emacs-contained online-manuals Mekeor Melire
2023-12-07  2:48       ` bug#67615: [PATCH v2] * lisp/info.el (Info-url-for-node): Support all Emacs info manuals Richard Stallman
2023-12-07  7:19         ` Eli Zaretskii
2023-12-07 11:56           ` Mekeor Melire
2023-12-07 17:02             ` Eli Zaretskii
2023-12-09  4:05               ` Richard Stallman
2023-12-08  0:15       ` bug#67615: [PATCH v3] * lisp/info.el (Info-url-alist): New option mapping manuals to URLs Mekeor Melire
2023-12-09  9:42         ` Eli Zaretskii
2023-12-09 11:21           ` Mekeor Melire
2023-12-19 23:08             ` bug#67615: [PATCH v4] " Mekeor Melire
2023-12-23 10:05               ` Eli Zaretskii
2024-01-08 21:56                 ` bug#67615: [PATCH v5] " Mekeor Melire
2024-01-13  9:51                   ` Eli Zaretskii
2024-01-20  0:50                     ` Mekeor Melire [this message]
2024-01-20  1:41                       ` bug#67615: [PATCH v6] Add option Info-url-alist Orhan Kemal Yüksel
2024-01-20  7:23                       ` Eli Zaretskii
2024-01-21  1:43                         ` bug#67615: [PATCH v7] " Mekeor Melire
2024-01-27 10:21                           ` Eli Zaretskii

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=87edec3jcl.fsf@posteo.de \
    --to=mekeor@posteo.de \
    --cc=67615@debbugs.gnu.org \
    --cc=eliz@gnu.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).