Function: org-indent-line

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

Signature

(org-indent-line)

Documentation

Indent line depending on context.

Indentation is done according to the following rules:

  - Footnote definitions, diary sexps, headlines and inline tasks
    have to start at column 0.

  - On the very first line of an element, consider, in order, the
    next rules until one matches:

    1. If there's a sibling element before, ignoring footnote
       definitions and inline tasks, indent like its first line.

    2. If element has a parent, indent like its contents. More
       precisely, if parent is an item, indent after the bullet.
       Else, indent like parent's first line.

    3. Otherwise, indent relatively to current level, if
       org-adapt-indentation is t, or to left margin.

  - On a blank line at the end of an element, indent according to
    the type of the element. More precisely

    1. If element is a plain list, an item, or a footnote
       definition, indent like the very last element within.

    2. If element is a paragraph, indent like its last non blank
       line.

    3. Otherwise, indent like its very first line.

  - In the code part of a source block, use language major mode
    to indent current line if org-src-tab-acts-natively is
    non-nil. If it is nil, do nothing.

  - Otherwise, indent like the first non-blank line above.

The function doesn't indent an item as it could break the whole list structure. Instead, use C-c C-x L (org-shiftmetaleft) or C-c C-x R (org-shiftmetaright).

Also align node properties according to org-property-format.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/org/org.el.gz
(defun org-indent-line ()
  "Indent line depending on context.

Indentation is done according to the following rules:

  - Footnote definitions, diary sexps, headlines and inline tasks
    have to start at column 0.

  - On the very first line of an element, consider, in order, the
    next rules until one matches:

    1. If there's a sibling element before, ignoring footnote
       definitions and inline tasks, indent like its first line.

    2. If element has a parent, indent like its contents.  More
       precisely, if parent is an item, indent after the bullet.
       Else, indent like parent's first line.

    3. Otherwise, indent relatively to current level, if
       `org-adapt-indentation' is t, or to left margin.

  - On a blank line at the end of an element, indent according to
    the type of the element.  More precisely

    1. If element is a plain list, an item, or a footnote
       definition, indent like the very last element within.

    2. If element is a paragraph, indent like its last non blank
       line.

    3. Otherwise, indent like its very first line.

  - In the code part of a source block, use language major mode
    to indent current line if `org-src-tab-acts-natively' is
    non-nil.  If it is nil, do nothing.

  - Otherwise, indent like the first non-blank line above.

The function doesn't indent an item as it could break the whole
list structure.  Instead, use \\<org-mode-map>`\\[org-shiftmetaleft]' or \
`\\[org-shiftmetaright]'.

Also align node properties according to `org-property-format'."
  (interactive)
  (let* ((element (save-excursion (forward-line 0) (org-element-at-point-no-context)))
	 (type (org-element-type element)))
    (unless (or (org-at-heading-p) ; headline has no indent ever.
                ;; Do not indent first element after headline data.
                (and (eq org-adapt-indentation 'headline-data)
                     (not (org--at-headline-data-p nil element))
                     ;; Not at headline data and previous is headline data/headline.
                     (or (memq type '(headline inlinetask)) ; blank lines after heading
                         (and element
                              (save-excursion
                                (goto-char (1- (org-element-begin element)))
                                (or (org-at-heading-p)
                                    (org--at-headline-data-p)))))))
      (cond ((and (memq type '(plain-list item))
		  (= (line-beginning-position)
		     (org-element-post-affiliated element)))
	     nil)
	    ((and (eq type 'latex-environment)
		  (>= (point) (org-element-post-affiliated element))
		  (< (point)
		     (org-with-point-at (org-element-end element)
		       (skip-chars-backward " \t\n")
		       (line-beginning-position 2))))
	     nil)
	    ((and (eq type 'src-block)
		  org-src-tab-acts-natively
		  (> (line-beginning-position)
		     (org-element-post-affiliated element))
		  (< (line-beginning-position)
		     (org-with-point-at (org-element-end element)
		       (skip-chars-backward " \t\n")
		       (line-beginning-position))))
             (let ((block-content-ind
                    (when (not (org-src-preserve-indentation-p element))
                      (org-with-point-at (org-element-property :begin element)
                        (+ (org-current-text-indentation)
                           org-edit-src-content-indentation)))))
               (ignore-errors ; do not err when there is no proper major mode
                 ;; It is important to call `indent-according-to-mode'
                 ;; rather than `indent-line-function' here or we may
                 ;; sometimes break `electric-indent-mode'
                 ;; https://orgmode.org/list/5O9VMGb6WRaqeHR5_NXTb832Z2Lek_5L40YPDA52-S3kPwGYJspI8kLWaGtuq3DXyhtHpj1J7jTIXb39RX9BtCa2ecrWHjijZqI8QAD742U=@proton.me
                 (org-babel-do-in-edit-buffer (indent-according-to-mode)))
               (when (and block-content-ind (looking-at-p "^$"))
                 (indent-line-to block-content-ind))))
	    (t
	     (let ((column (org--get-expected-indentation element nil)))
	       ;; Preserve current column.
	       (if (<= (current-column) (current-indentation))
		   (indent-line-to column)
		 (save-excursion (indent-line-to column))))
	     ;; Align node property.  Also preserve current column.
	     (when (eq type 'node-property)
	       (let ((column (current-column)))
		 (org--align-node-property)
		 (org-move-to-column column))))))))