Function: texinfo-insert-node-lines

texinfo-insert-node-lines is an autoloaded, interactive and byte-compiled function defined in texnfo-upd.el.gz.

Signature

(texinfo-insert-node-lines BEGINNING END &optional TITLE-P)

Documentation

Insert missing @node lines in region of Texinfo file.

Non-nil argument (prefix, if interactive) means also to insert the section titles as node names; and also to insert the section titles as node names in pre-existing @node lines that lack names.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/texnfo-upd.el.gz
;;; Inserting `@node' lines
;; The `texinfo-insert-node-lines' function inserts `@node' lines as needed
;; before the `@chapter', `@section', and such like lines of a region
;; in a Texinfo file.

;;;###autoload
(defun texinfo-insert-node-lines (beginning end &optional title-p)
  "Insert missing `@node' lines in region of Texinfo file.
Non-nil argument (prefix, if interactive) means also to insert the
section titles as node names; and also to insert the section titles as
node names in pre-existing `@node' lines that lack names."
  (interactive "r\nP")

  ;; Use marker; after inserting node lines, leave point at end of
  ;; region and mark at beginning.

  (let (end-marker title last-section-position) ;; beginning-marker

    ;; Save current position on mark ring and set mark to end.
    (push-mark end t)
    (setq end-marker (mark-marker))

    (goto-char beginning)
    (while (re-search-forward
	    texinfo-section-types-regexp
	    end-marker
	    'end)
      ;; Copy title if desired.
      (if title-p
	  (progn
	    (beginning-of-line)
	    (forward-word-strictly 1)
	    (skip-chars-forward " \t")
	    (setq title (buffer-substring
			 (point)
			 (line-end-position)))))
      ;; Insert node line if necessary.
      (if (re-search-backward
	   "^@node"
	   ;; Avoid finding previous node line if node lines are close.
	   (or last-section-position
	       (line-beginning-position -1))
	   t)
	  ;;  @node is present, and point at beginning of that line
	  (forward-word-strictly 1) ; Leave point just after @node.
	;; Else @node missing; insert one.
	(beginning-of-line)         ; Beginning of `@section' line.
	(insert "@node\n")
	(backward-char 1))          ; Leave point just after `@node'.
      ;; Insert title if desired.
      (if title-p
	  (progn
	    (skip-chars-forward " \t")
	    ;; Use regexp based on what info looks for
	    ;; (alternatively, use "[a-zA-Z]+");
	    ;; this means we only insert a title if none exists.
	    (if (not (looking-at "[^,\t\n ]+"))
		(progn
		  (beginning-of-line)
		  (forward-word-strictly 1)
		  (insert " " title)
		  (message "Inserted title %s ... " title)))))
      ;; Go forward beyond current section title.
      (re-search-forward texinfo-section-types-regexp
			 (line-beginning-position 4) t)
      (setq last-section-position (point))
      (forward-line 1))

    ;; Leave point at end of region, mark at beginning.
    (set-mark beginning)

    (if title-p
      (message
       "Done inserting node lines and titles.  You may save the buffer.")
    (message "Done inserting node lines.  You may save the buffer."))))