Function: texinfo-raise-lower-sections

texinfo-raise-lower-sections is a byte-compiled function defined in texinfmt.el.gz.

Signature

(texinfo-raise-lower-sections)

Documentation

Raise or lower the hierarchical level of chapters, sections, etc.

This function acts according to @raisesections and @lowersections commands in the Texinfo file.

For example, an @lowersections command is useful if you wish to include what is written as an outer or standalone Texinfo file in another Texinfo file as an inner, included file. The @lowersections command changes chapters to sections, sections to subsections and so on.

@raisesections changes @subsection to @section,
                       @section to @chapter,
                       @heading to @chapheading,
                       etc.

@lowersections changes @chapter to @section,
                       @subsection to @subsubsection,
                       @heading to @subheading,
                       etc.

An @raisesections or @lowersections command changes only those structuring commands that follow the @raisesections or
@lowersections command.

An @lowersections command cancels an @raisesections command, and vice versa.

Repeated use of the commands continue to raise or lower the hierarchical level a step at a time.

An attempt to raise above chapters reproduces chapter commands; an attempt to lower below subsubsections reproduces subsubsection commands.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/texinfmt.el.gz
;;; Handle `@raisesections' and `@lowersections' commands

;; These commands change the hierarchical level of chapter structuring
;; commands.
;;
;; @raisesections changes @subsection to @section,
;;                        @section    to @chapter,
;;                        etc.
;;
;; @lowersections changes @chapter    to @section
;;                        @subsection to @subsubsection,
;;                        etc.
;;
;; An @raisesections/@lowersections command changes only those
;; structuring commands that follow the @raisesections/@lowersections
;; command.
;;
;; Repeated @raisesections/@lowersections continue to raise or lower
;; the heading level.
;;
;; An @lowersections command cancels an @raisesections command, and
;; vice versa.
;;
;; You cannot raise or lower "beyond" chapters or subsubsections, but
;; trying to do so does not elicit an error---you just get more
;; headings that mean the same thing as you keep raising or lowering
;; (for example, after a single @raisesections, both @chapter and
;; @section produce chapter headings).

(defun texinfo-raise-lower-sections ()
  "Raise or lower the hierarchical level of chapters, sections, etc.

This function acts according to `@raisesections' and `@lowersections'
commands in the Texinfo file.

For example, an `@lowersections' command is useful if you wish to
include what is written as an outer or standalone Texinfo file in
another Texinfo file as an inner, included file.  The `@lowersections'
command changes chapters to sections, sections to subsections and so
on.

@raisesections changes @subsection to @section,
                       @section    to @chapter,
                       @heading    to @chapheading,
                       etc.

@lowersections changes @chapter    to @section,
                       @subsection to @subsubsection,
                       @heading    to @subheading,
                       etc.

An `@raisesections' or `@lowersections' command changes only those
structuring commands that follow the `@raisesections' or
`@lowersections' command.

An `@lowersections' command cancels an `@raisesections' command, and
vice versa.

Repeated use of the commands continue to raise or lower the hierarchical
level a step at a time.

An attempt to raise above `chapters' reproduces chapter commands; an
attempt to lower below subsubsections reproduces subsubsection
commands."

  ;; `texinfo-section-types-regexp' is defined in `texnfo-upd.el';
  ;; it is a regexp matching chapter, section, other headings
  ;; (but not the top node).

  (let (type (level 0))
    (while
        (re-search-forward
         (concat
          "\\(\\(^@\\(raise\\|lower\\)sections\\)\\|\\("
          texinfo-section-types-regexp
          "\\)\\)")
         nil t)
      (beginning-of-line)
      (save-excursion (setq type (read (current-buffer))))
      (cond

       ;; 1. Increment level
       ((eq type '@raisesections)
        (setq level (1+ level))
        (delete-region
         (point) (line-beginning-position 2)))

       ;; 2. Decrement level
       ((eq type '@lowersections)
        (setq level (1- level))
        (delete-region
         (point) (line-beginning-position 2)))

       ;; Now handle structuring commands
       ((cond

         ;; 3. Raise level when positive
         ((> level 0)
          (let ((count level)
                (new-level type))
            (while (> count 0)
              (setq new-level
                    (cdr (assq new-level texinfo-raisesections-alist)))
              (setq count (1- count)))
            (kill-word 1)
            (insert (symbol-name new-level))))

         ;; 4. Do nothing except move point when level is zero
         ((= level 0) (forward-line 1))

         ;; 5. Lower level when positive
         ((< level 0)
          (let ((count level)
                (new-level type))
            (while (< count 0)
              (setq new-level
                    (cdr (assq new-level texinfo-lowersections-alist)))
              (setq count (1+ count)))
            (kill-word 1)
            (insert (symbol-name new-level))))))))))