Function: outline-demote

outline-demote is an interactive and byte-compiled function defined in outline.el.gz.

Signature

(outline-demote &optional WHICH)

Documentation

Demote headings lower down the tree.

If transient-mark-mode(var)/transient-mark-mode(fun) is on, and mark is active, demote headings in the region (from a Lisp program, pass region for WHICH). Otherwise: without prefix argument, demote current heading and all headings in the subtree (from a Lisp program, pass subtree for WHICH); with prefix argument, demote just the current heading (from a Lisp program, pass nil for WHICH, or do not pass any argument).

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/outline.el.gz
(defun outline-demote (&optional which)
  "Demote headings lower down the tree.
If `transient-mark-mode' is on, and mark is active, demote headings in
the region (from a Lisp program, pass `region' for WHICH).  Otherwise:
without prefix argument, demote current heading and all headings in the
subtree (from a Lisp program, pass `subtree' for WHICH); with prefix
argument, demote just the current heading (from a Lisp program, pass
nil for WHICH, or do not pass any argument)."
  (interactive
   (list (if (and transient-mark-mode mark-active) 'region
	   (outline-back-to-heading)
	   (if current-prefix-arg nil 'subtree))))
  (cond
   ((eq which 'region)
    (outline-map-region #'outline-demote (region-beginning) (region-end)))
   (which
    (outline-map-region #'outline-demote
			(point)
			(save-excursion (outline-get-next-sibling) (point))))
   (t
    (let* ((head (match-string-no-properties 0))
	   (level (save-match-data (funcall outline-level)))
	   (down-head
	    (or (outline-head-from-level (1+ level) head)
		(save-excursion
		  (save-match-data
		    (while (and (progn (outline-next-heading) (not (eobp)))
				(<= (funcall outline-level) level)))
		    (when (eobp)
		      ;; Try again from the beginning of the buffer.
		      (goto-char (point-min))
		      (while (and (progn (outline-next-heading) (not (eobp)))
				  (<= (funcall outline-level) level))))
		    (unless (eobp)
		      (if outline-search-function
                          (funcall outline-search-function nil nil nil t)
                        (looking-at outline-regexp))
		      (match-string-no-properties 0))))
                ;; Bummer!! There is no higher-level heading in the buffer.
                (outline-invent-heading head nil))))

      (unless (rassoc level outline-heading-alist)
	(push (cons head level) outline-heading-alist))
      (replace-match down-head nil t)))))