Function: ibtypes::text-toc

ibtypes::text-toc is a byte-compiled function defined in hibtypes.el.

Signature

(ibtypes::text-toc)

Documentation

Jump to the text file section referenced by a table of contents entry at point.

Buffer must be in a text mode or must contain DEMO, README or TUTORIAL and there must be a Table of Contents or Contents label on a line by itself (it optionally may begin with an asterisk), preceding the table of contents. Each toc entry must begin with optional whitespace followed by one or more asterisks, +, -, or the letter o (the leader character) followed by whitespace. Each section header linked to by the toc must start with optional whitespace and then one or more asterisks at the beginning of the line matching the number of leader characters matched in the toc.

Source Code

;; Defined in ~/.emacs.d/elpa/hyperbole-20261030.2317/hibtypes.el
;;; ========================================================================
;;; Makes README table of contents entries jump to associated sections.
;;; ========================================================================

(defib text-toc ()
  "Jump to the text file section referenced by a table of contents entry at point.
Buffer must be in a text mode or must contain DEMO, README or TUTORIAL
and there must be a `Table of Contents' or `Contents' label on a line by
itself (it optionally may begin with an asterisk), preceding the table
of contents.  Each toc entry must begin with optional whitespace
followed by one or more asterisks, +, -, or the letter `o' (the leader
character) followed by whitespace.  Each section header linked to by the
toc must start with optional whitespace and then one or more asterisks
at the beginning of the line matching the number of leader characters
matched in the toc."
  (let (section)
    (when (and (or (derived-mode-p 'text-mode)
		   (string-match "DEMO\\|README\\|TUTORIAL" (buffer-name)))
               (save-excursion (re-search-backward
                                "^\\*?*[ \t]*\\(Table of \\)?Contents[ \t]*$"
                                nil t))
               (save-excursion
                 (beginning-of-line)
                 ;; Entry line within a TOC
                 (when (and (or
			     ;; Next line is typically in RFCs,
			     ;; e.g. "1.1.  Scope ..... 1"
			     (looking-at "^[ \t]*\\([0-9.]+\\([ \t]+[^ \t\n\r]+\\)+\\) \\.+")
			     (looking-at "[ \t]+\\([-+*o]+[ \t]+.*\\)$"))
			    (setq section (string-trim (match-string-no-properties 1))))
		   (ibut:label-set section (match-beginning 1) (match-end 1))
                   t)))
      (hact 'text-toc section))))