Function: indent-relative

indent-relative is an interactive and byte-compiled function defined in indent.el.gz.

Signature

(indent-relative &optional FIRST-ONLY UNINDENTED-OK)

Documentation

Space out to under next indent point in previous nonblank line.

An indent point is a non-whitespace character following whitespace. The following line shows the indentation points in this line.
    ^ ^ ^ ^ ^ ^ ^ ^ ^
If FIRST-ONLY is non-nil, then only the first indent point is considered.

If the previous nonblank line has no indent points beyond the column point starts at, then tab-to-tab-stop is done, if both FIRST-ONLY and UNINDENTED-OK are nil, otherwise nothing is done. If there isn't a previous nonblank line and UNINDENTED-OK is nil, call tab-to-tab-stop.

See also indent-relative-first-indent-point.

View in manual

Probably introduced at or before Emacs version 1.9.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/indent.el.gz
(defun indent-relative (&optional first-only unindented-ok)
  "Space out to under next indent point in previous nonblank line.
An indent point is a non-whitespace character following whitespace.
The following line shows the indentation points in this line.
    ^         ^    ^     ^   ^           ^      ^  ^    ^
If FIRST-ONLY is non-nil, then only the first indent point is
considered.

If the previous nonblank line has no indent points beyond the
column point starts at, then `tab-to-tab-stop' is done, if both
FIRST-ONLY and UNINDENTED-OK are nil, otherwise nothing is done.
If there isn't a previous nonblank line and UNINDENTED-OK is nil,
call `tab-to-tab-stop'.

See also `indent-relative-first-indent-point'."
  (interactive "P")
  (if (and abbrev-mode
	   (eq (char-syntax (preceding-char)) ?w))
      (expand-abbrev))
  (let ((start-column (current-column))
	indent)
    (save-excursion
      (beginning-of-line)
      (if (re-search-backward "^[^\n]" nil t)
	  (let ((end (save-excursion (forward-line 1) (point))))
	    (move-to-column start-column)
	    ;; Is start-column inside a tab on this line?
	    (if (> (current-column) start-column)
		(backward-char 1))
	    (or (looking-at "[ \t]")
		first-only
		(skip-chars-forward "^ \t" end))
	    (skip-chars-forward " \t" end)
	    (or (= (point) end) (setq indent (current-column))))))
    (cond (indent
           (let ((opoint (point-marker)))
             (indent-to indent 0)
             (if (> opoint (point))
                 (goto-char opoint))
             (move-marker opoint nil)))
          (unindented-ok nil)
          (t (tab-to-tab-stop)))))