Function: reftex-toc-promote-prepare

reftex-toc-promote-prepare is a byte-compiled function defined in reftex-toc.el.gz.

Signature

(reftex-toc-promote-prepare X DELTA)

Documentation

Look at a TOC entry and see if we could pro/demote it.

This function prepares everything for the change, but does not do it. The return value is a list with information needed when doing the promotion/demotion later. DELTA is the level change.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/reftex-toc.el.gz
(defun reftex-toc-promote-prepare (x delta)
  "Look at a TOC entry and see if we could pro/demote it.
This function prepares everything for the change, but does not do it.
The return value is a list with information needed when doing the
promotion/demotion later.  DELTA is the level change."
  (let* ((data (car x))
         (toc-point (cdr x))
         (marker (nth 4 data))
         (literal (nth 7 data))
         (load nil)
         (name nil)
         ;; Here follows some paranoid code to make very sure we are not
         ;; going to break anything
         (_
          (if (and (markerp marker) (marker-buffer marker))
              ;; Buffer is still live and we have the marker.
              (progn
                (with-current-buffer (marker-buffer marker)
                  ;; Goto the buffer and check of section is unchanged
                  (goto-char (marker-position marker))
                  (if (looking-at (regexp-quote literal))
                      ;; OK, get the makro name
                      (progn
                        (beginning-of-line 1)
                        (if (looking-at reftex-section-regexp)
                            (setq name (reftex-match-string 2))
                          (error "Something is wrong!  Contact maintainer!")))
                    ;; Section has changed, request scan and loading
                    ;; We use a variable to delay until after the safe-exc.
                    ;; because otherwise we lose the region.
                    (setq load t)))
                ;; Scan document and load all files, this exits command
                (if load (reftex-toc-load-all-files-for-promotion))) ; exits
            ;; We don't have a live marker: scan and load files.
            (reftex-toc-load-all-files-for-promotion)))
         (level (cdr (assoc name reftex-section-levels-all)))
         (_ (if (not (integerp level))
                (progn
                  (goto-char toc-point)
                  (error "Cannot %smote special sections" reftex--pro-or-de))))
         (newlevel (if (>= level 0) (+ delta level) (- level delta)))
         (_ (if (or (and (>= level 0) (= newlevel -1))
                    (and (< level 0)  (= newlevel 0)))
                (error "Cannot %smote \\%s" reftex--pro-or-de name)))
         (newname (reftex-toc-newhead-from-alist newlevel name
                                                 reftex-section-levels-all)))
    (if (and name newname)
        (list data name newname toc-point)
      (goto-char toc-point)
      (error "Cannot %smote \\%s" reftex--pro-or-de name))))