2

I am talking about this to be precise.

Suppose there are an emacs installation and a web browser on an X session (desktop). I know you can open the manuals in emacs itself using M-x info, but is it possible to open the same manual in the browser (with the basic CSS, like in the website, one node per page)?

The default browser was set using XDG's mimeapps.list.

I searched emacs' package files, but there are no html files listed among them. However, there are a lot of gzipped files with "html" in their name.

Drew
  • 75,699
  • 9
  • 109
  • 225
nomad
  • 247
  • 1
  • 6
  • 1
    Are you asking how to produce the HTML manuals from the sources? `make html` makes a single `emacs.html` file - so I guess your question is how to split that into multiple html files (one per node)? – NickD Sep 28 '20 at 14:48
  • 1
    I think OP is asking how to view local Info manuals in a web browser (with hypertext links etc.). And I think the answer is that you cannot do so directly. An indirect answer would be, as you suggest, to create local HTML files from texinfo sources. – Drew Sep 28 '20 at 16:11
  • @Drew yes, that's what I wanted. And NickD, I hoped that one html file (or set of node files) was part of the package. Seems like that is not the case, atleast on my system. But `make html` will do I guess. – nomad Sep 28 '20 at 17:25
  • 1
    In case you're not already, I would urge anyone to get familiar with the Info reader -- when it comes to looking things up, a web browser doesn't hold a candle to using the Info reader inside Emacs, with its indexes and full-text-of-entire-manual isearch abilities. – phils Sep 29 '20 at 09:40
  • You can `make html HTML_OPTS=--html` in`emacs/doc/emacs` to do the emacs manual one node per page. Or download the compressed version of the HTMl manual from https://www.gnu.org/software/emacs/manual/emacs.html . – NickD Sep 30 '20 at 00:54

1 Answers1

2

I often need to link to the emacs manuals, for example, this markdown link: (emacs) Echo Area, is created via M-x chunyang-Info-markdown-current-node-html since it's difficult to do it manually. With the following, you can also type O to open the corresponding HTML manuals in your web browser.

(defvar chunyang-Info-html-alist
  '(
    ;; Special cases come first
    ("org"  . "http://orgmode.org/manual/%s")
    ("find" . "https://www.gnu.org/software/findutils/manual/html_node/find_html/%s")
    ("standards" . "https://www.gnu.org/prep/standards/html_node/%s")
    ("magit" . "https://magit.vc/manual/magit/%s")
    ("slime" . "https://www.common-lisp.net/project/slime/doc/html/%s")
    ;; Haha, just for some fun
    ("geiser" . (lambda (_)
                  ;; (info "(geiser) First aids")
                  ;; http://www.nongnu.org/geiser/geiser_3.html#First-aids
                  (if (string=  Info-current-node "Top")
                      "http://www.nongnu.org/geiser/"
                    (let ((node (replace-regexp-in-string " " "-" Info-current-node))
                          (number (save-excursion
                                    (goto-char (point-min))
                                    (re-search-forward "^[0-9]")
                                    (match-string 0))))

                      (format "http://www.nongnu.org/geiser/geiser_%s.html#%s" number node)))))
    ("gawk" . "https://www.gnu.org/software/tar/manual/html_node/%s")
    ;; GNU info documents.  Taken from my memory or see https://www.gnu.org/software/
    (("awk" "sed" "tar" "make" "m4" "grep" "coreutils" "guile" "screen"
      "libc" "make" "gzip" "diffutils" "wget" "grub") .
      (lambda (software)
        (format "https://www.gnu.org/software/%s/manual/html_node/%%s" software)))
    ("gcc-5" . "https://gcc.gnu.org/onlinedocs/gcc/%s")
    (("gdb" "stabs") .
     (lambda (software)
       (format "https://sourceware.org/gdb/onlinedocs/%s/%%s" software)))
    ;; Emacs info documents.  Taken from `org-info-emacs-documents'
    (("ada-mode" "auth" "autotype" "bovine" "calc" "ccmode" "cl" "dbus" "dired-x"
      "ebrowse" "ede" "ediff" "edt" "efaq-w32" "efaq" "eieio" "eintr" "elisp"
      "emacs-gnutls" "emacs-mime" "emacs" "epa" "erc" "ert" "eshell" "eudc" "eww"
      "flymake" "forms" "gnus" "htmlfontify" "idlwave" "ido" "info" "mairix-el"
      "message" "mh-e" "newsticker" "nxml-mode" "octave-mode" "org" "pcl-cvs"
      "pgg" "rcirc" "reftex" "remember" "sasl" "sc" "semantic" "ses" "sieve"
      "smtpmail" "speedbar" "srecode" "todo-mode" "tramp" "url" "vip" "viper"
      "widget" "wisent" "woman") .
      (lambda (package)
        (format "https://www.gnu.org/software/emacs/manual/html_node/%s/%%s" package)))))

(defun chunyang-org-info-map-anchor-url (node)
  "Return URL associated to Info NODE."
  (require 'org)                      ; for `org-trim'
  ;; See (info "(texinfo) HTML Xref Node Name Expansion") for the
  ;; expansion rule
  (let* ((node (replace-regexp-in-string "[ \t\n\r]+" " " (org-trim node)))
         (node (mapconcat (lambda (c)
                            (if (string-match "[a-zA-Z0-9 ]" (string c))
                                (string c)
                              (format "_%04x" c)))
                          (string-to-list node) ""))
         (node (replace-regexp-in-string " " "-" node))
         (url (if (string= node "")
                  ""
                (if (string-match "[0-9]" (substring node 0 1))
                    (concat "g_t" node)
                  node))))
    url))

(defun chunyang-Info-get-current-node-html ()
  (cl-assert (eq major-mode 'Info-mode))
  (let* ((file (file-name-nondirectory Info-current-file))
         (node Info-current-node)
         (html (if (string= node "Top")
                   ""
                 (concat (chunyang-org-info-map-anchor-url node) ".html")))
         (baseurl (cl-loop for (k . v) in chunyang-Info-html-alist
                           when (cond ((stringp k) (equal file k))
                                      ((listp k) (member file k)))
                           return (if (stringp v) v (funcall v file)))))
    ;; Maybe it's a good idea to assuming GNU softwares in this case
    (cl-assert baseurl nil "Unsupported info document '%s'" file)
    (format baseurl html)))

(defun chunyang-Info-browse-current-node-html ()
  (interactive)
  (let ((url (chunyang-Info-get-current-node-html)))
    (browse-url url)))

(bind-key "O" #'chunyang-Info-browse-current-node-html Info-mode-map)

(defun chunyang-Info-markdown-current-node-html (&optional arg)
  "ARG will be passed to `Info-copy-current-node-name'."
  (interactive "P")
  (let ((description (Info-copy-current-node-name arg))
        (link (chunyang-Info-get-current-node-html)))
    (let ((markdown (format "[%s](%s)" description link)))
      (kill-new markdown)
      (message "Copied: %s" markdown))))

If you need the offline HTML manuals, you need to get a local copy, the easiest is goto https://www.gnu.org/software/emacs/manual/elisp.html and click "HTML compressed" to download the HTML manual for Emacs Lisp manual, you need to do the same thing for Emacs manual, then change chunyang-Info-html-alist to your local file address.

You can also build the HTML manuals from source code, see https://github.com/casouri/emacs-manuals/blob/master/build.sh for example.

xuchunyang
  • 14,302
  • 1
  • 18
  • 39