Function: Info-url-for-node

Info-url-for-node is a byte-compiled function defined in info.el.gz.

Signature

(Info-url-for-node NODE)

Documentation

Return the URL corresponding to NODE.

NODE should be a string of the form "(manual)Node".

Source Code

;; Defined in /usr/src/emacs/lisp/info.el.gz
(defun Info-url-for-node (node)
  "Return the URL corresponding to NODE.

NODE should be a string of the form \"(manual)Node\"."
  ;; GNU Texinfo skips whitespaces and newlines between the closing
  ;; parenthesis and the node-name, i.e. space, tab, line feed and
  ;; carriage return.
  (unless (string-match "\\`(\\(.+\\))[ \t\n\r]*\\(.+\\)\\'" node)
    (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 " " "-"
                       (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)))