Function: help-make-xrefs

help-make-xrefs is an autoloaded, interactive and byte-compiled function defined in help-mode.el.gz.

Signature

(help-make-xrefs &optional BUFFER)

Documentation

Parse and hyperlink documentation cross-references in the given BUFFER.

Find cross-reference information in a buffer and activate such cross references for selection with help-follow-symbol. Cross-references have the canonical form ... and the type of reference may be disambiguated by the preceding word(s) used in help-xref-symbol-regexp. Faces only get cross-referenced if preceded or followed by the word face. Variables without variable documentation do not get cross-referenced, unless preceded by the word variable or option.

If the variable help-xref-mule-regexp is non-nil, find also cross-reference information related to multilingual environment
(e.g., coding-systems). This variable is also used to disambiguate
the type of reference as the same way as help-xref-symbol-regexp.

A special reference back is made to return back through a stack of help buffers. Variable help-back-label specifies the text for that.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/help-mode.el.gz
;;;###autoload
(defun help-make-xrefs (&optional buffer)
  "Parse and hyperlink documentation cross-references in the given BUFFER.

Find cross-reference information in a buffer and activate such cross
references for selection with `help-follow-symbol'.  Cross-references have
the canonical form `...'  and the type of reference may be
disambiguated by the preceding word(s) used in
`help-xref-symbol-regexp'.  Faces only get cross-referenced if
preceded or followed by the word `face'.  Variables without
variable documentation do not get cross-referenced, unless
preceded by the word `variable' or `option'.

If the variable `help-xref-mule-regexp' is non-nil, find also
cross-reference information related to multilingual environment
\(e.g., coding-systems).  This variable is also used to disambiguate
the type of reference as the same way as `help-xref-symbol-regexp'.

A special reference `back' is made to return back through a stack of
help buffers.  Variable `help-back-label' specifies the text for
that."
  (interactive "b")
  (with-current-buffer (or buffer (current-buffer))
    (save-excursion
      (goto-char (point-min))
      ;; Skip the first bit, which has already been buttonized.
      (forward-paragraph)
      (let ((old-modified (buffer-modified-p)))
        (let ((stab (syntax-table))
              (case-fold-search t)
              (inhibit-read-only t))
          (set-syntax-table help-mode-syntax-table)
          ;; The following should probably be abstracted out.
          (unwind-protect
              (progn
                ;; Info references
                (save-excursion
                  (while (re-search-forward help-xref-info-regexp nil t)
                    (let ((data (match-string 2)))
                      (save-match-data
                        (unless (string-match "^([^)]+)" data)
                          (setq data (concat "(emacs)" data)))
			(setq data ;; possible newlines if para filled
			      (replace-regexp-in-string "[ \t\n]+" " " data t t)))
                      (help-xref-button 2 'help-info data))))
                ;; Man references
                (save-excursion
                  (while (re-search-forward help-xref-man-regexp nil t)
                    (help-xref-button 1 'help-man (match-string 1))))
                ;; Customization groups.
                (save-excursion
                  (while (re-search-forward
                          help-xref-customization-group-regexp nil t)
                    (help-xref-button 1 'help-customization-group
                                      (intern (match-string 1)))))
                ;; URLs
                (save-excursion
                  (while (re-search-forward help-xref-url-regexp nil t)
                    (let ((data (match-string 1)))
                      (help-xref-button 1 'help-url data))))
                ;; Mule related keywords.  Do this before trying
                ;; `help-xref-symbol-regexp' because some of Mule
                ;; keywords have variable or function definitions.
                (if help-xref-mule-regexp
                    (save-excursion
                      (while (re-search-forward help-xref-mule-regexp nil t)
                        (let* ((data (match-string 7))
                               (sym (intern-soft data)))
                          (cond
                           ((match-string 3) ; coding system
                            (and sym (coding-system-p sym)
                                 (help-xref-button 6 'help-coding-system sym)))
                           ((match-string 4) ; input method
                            (and (assoc data input-method-alist)
                                 (help-xref-button 7 'help-input-method data)))
                           ((or (match-string 5) (match-string 6)) ; charset
                            (and sym (charsetp sym)
                                 (help-xref-button 7 'help-character-set sym)))
                           ((assoc data input-method-alist)
                            (help-xref-button 7 'help-input-method data))
                           ((and sym (coding-system-p sym))
                            (help-xref-button 7 'help-coding-system sym))
                           ((and sym (charsetp sym))
                            (help-xref-button 7 'help-character-set sym)))))))
                ;; Quoted symbols
                (save-excursion
                  (while (re-search-forward help-xref-symbol-regexp nil t)
                    (when-let ((sym (intern-soft (match-string 9))))
                      (if (match-string 8)
                          (delete-region (match-beginning 8)
                                         (match-end 8))
                        (cond
                         ((match-string 3)        ; `variable' &c
                          (and (or (boundp sym) ; `variable' doesn't ensure
                                        ; it's actually bound
                                   (get sym 'variable-documentation))
                               (help-xref-button 9 'help-variable sym)))
                         ((match-string 4)     ; `function' &c
                          (and (fboundp sym)   ; similarly
                               (help-xref-button 9 'help-function sym)))
                         ((match-string 5) ; `face'
                          (and (facep sym)
                               (help-xref-button 9 'help-face sym)))
                         ((match-string 6)) ; nothing for `symbol'
                         ((match-string 7)
                          (help-xref-button 9 'help-function-def sym))
                         ((cl-some (lambda (x) (funcall (nth 1 x) sym))
                                   describe-symbol-backends)
                          (help-xref-button 9 'help-symbol sym)))))))
                ;; An obvious case of a key substitution:
                (save-excursion
                  (while (re-search-forward
                          ;; Assume command name is only word and symbol
                          ;; characters to get things like `use M-x foo->bar'.
                          ;; Command required to end with word constituent
                          ;; to avoid `.' at end of a sentence.
                          "\\<M-x\\s-+\\(\\sw\\(\\sw\\|\\s_\\)*\\sw\\)" nil t)
                    (let ((sym (intern-soft (match-string 1))))
                      (if (fboundp sym)
                          (help-xref-button 1 'help-function sym))))))
            (set-syntax-table stab))
          ;; Delete extraneous newlines at the end of the docstring
          (goto-char (point-max))
          (while (and (not (bobp)) (bolp))
            (delete-char -1))
          (insert "\n")
          (help-xref--navigation-buttons))
        (set-buffer-modified-p old-modified)))))