Function: reftex-toc-do-promote
reftex-toc-do-promote is a byte-compiled function defined in
reftex-toc.el.gz.
Signature
(reftex-toc-do-promote DELTA)
Documentation
Workhorse for reftex-toc-promote and reftex-toc-demote.
Changes the level of sections in the current region, or just the section at point.
Source Code
;; Defined in /usr/src/emacs/lisp/textmodes/reftex-toc.el.gz
(defun reftex-toc-do-promote (delta)
"Workhorse for `reftex-toc-promote' and `reftex-toc-demote'.
Changes the level of sections in the current region, or just the section at
point."
;; We should not do anything unless we are sure this is going to work for
;; each section in the region. Therefore we first collect information and
;; test.
(let* ((reftex--start-line (+ (count-lines (point-min) (point))
(if (bolp) 1 0)))
(reftex--mark-line
(if (region-active-p)
(save-excursion (goto-char (mark))
(+ (count-lines (point-min) (point))
(if (bolp) 1 0)))))
(start-pos (point))
(reftex--pro-or-de (if (> delta 0) "de" "pro"))
beg end entries data sections nsec msg)
(setq msg
(catch 'exit
(if (region-active-p)
;; A region is dangerous, check if we have a brand new scan,
;; to make sure we are not missing any section statements.
(if (not (reftex-toc-check-docstruct))
(reftex-toc-load-all-files-for-promotion) ;; exits
(setq beg (min (point) (mark))
end (max (point) (mark))))
(setq beg (point) end (point)))
(goto-char beg)
(while (and (setq data (get-text-property (point) :data))
(<= (point) end))
(if (eq (car data) 'toc) (push (cons data (point)) entries))
(goto-char (or (next-single-property-change (point) :data)
(point-max))))
(setq entries (nreverse entries))
;; Get the relevant section numbers, for an informative message
(goto-char start-pos)
(setq sections (reftex-toc-extract-section-number (car entries)))
(if (> (setq nsec (length entries)) 1)
(setq sections
(concat sections "-"
(reftex-toc-extract-section-number
(nth (1- nsec) entries)))))
;; Run through the list and prepare the changes.
(setq entries (mapcar
(lambda (e) (reftex-toc-promote-prepare e delta))
entries))
;; Ask for permission
(if (or (not reftex-toc-confirm-promotion) ; never confirm
(and (integerp reftex-toc-confirm-promotion) ; confirm if many
(< nsec reftex-toc-confirm-promotion))
(yes-or-no-p ; ask
(format "%s %d toc-entr%s (section%s %s)? "
(if (< delta 0) "Promote" "Demote")
nsec
(if (= 1 nsec) "y" "ies")
(if (= 1 nsec) "" "s")
sections)))
nil ; we have permission, do nothing
(error "Abort")) ; abort, we don't have permission
;; Do the changes
(mapc #'reftex-toc-promote-action entries)
;; Rescan the document and rebuilt the toc buffer
(save-window-excursion
(reftex-toc-Rescan))
(reftex-toc-restore-region reftex--start-line reftex--mark-line)
(message "%d section%s %smoted"
nsec (if (= 1 nsec) "" "s") reftex--pro-or-de)
nil))
(if msg (progn (ding) (message "%s" msg)))))