Function: combobulate-indent-string

combobulate-indent-string is a natively compiled function defined in combobulate-manipulation.el.

Signature

(combobulate-indent-string TEXT &key (FIRST-LINE-OPERATION nil) (FIRST-LINE-AMOUNT 0) (REST-LINES-OPERATION nil) (REST-LINES-AMOUNT 0))

Documentation

Indent TEXT specifically for the first and rest of the lines.

FIRST-LINE-OPERATION is the operation to perform on the first line of TEXT. It can be add, subtract, or absolute.

FIRST-LINE-AMOUNT is the amount to add, subtract, or set the first line's indentation to.

REST-LINES-OPERATION is the operation to perform on the rest of the lines of TEXT. It can be relative, add, subtract, or absolute. relative means that the indentation of the rest of the lines is relative to the first line's *changed* indentation. In other words, if the first line's indentation is changed by 2 spaces, then the rest of the lines' indentation will be changed by 2 spaces (in the same direction) as well.

REST-LINES-AMOUNT is the amount to add, subtract, or set the rest of the lines' indentation to. It cannot be used with relative.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-manipulation.el
(cl-defun combobulate-indent-string (text &key (first-line-operation nil)
                                          (first-line-amount 0)
                                          (rest-lines-operation nil)
                                          (rest-lines-amount 0))
  "Indent TEXT specifically for the first and rest of the lines.

FIRST-LINE-OPERATION is the operation to perform on the first
line of TEXT. It can be `add', `subtract', or `absolute'.

FIRST-LINE-AMOUNT is the amount to add, subtract, or set the
first line's indentation to.

REST-LINES-OPERATION is the operation to perform on the rest of
the lines of TEXT. It can be `relative', `add', `subtract', or
`absolute'. `relative' means that the indentation of the rest of
the lines is relative to the first line's *changed*
indentation. In other words, if the first line's indentation is
changed by 2 spaces, then the rest of the lines' indentation will
be changed by 2 spaces (in the same direction) as well.

REST-LINES-AMOUNT is the amount to add, subtract, or set the rest
of the lines' indentation to. It cannot be used with `relative'."
  (cl-assert (member first-line-operation '(add subtract absolute relative nil)))
  (cl-assert (member rest-lines-operation '(relative add subtract absolute nil)))
  ;; `rest-lines-amount'  cannot be used with `relative'.
  (cl-assert (or (not (eq rest-lines-operation 'relative))
                 (and (eq rest-lines-operation 'relative)
                      (eq rest-lines-amount 0))))
  (let* ((lines (split-string text "\n"))
         ;; indentation of the first line before we modify it
         (first-line-indentation (combobulate-indent-string--count-whitespace (car lines)))
         (first-line (if first-line-operation
                         (combobulate-indent-string-1
                          (car lines)
                          (if (equal first-line-operation 'relative) 'subtract first-line-operation)
                          (if (equal first-line-operation 'relative)
                              (- first-line-indentation first-line-amount)
                            first-line-amount))
                       (car lines)))
         (new-first-line-indentation (combobulate-indent-string--count-whitespace first-line))
         (rest-lines (if rest-lines-operation
                         (mapcar (lambda (line)
                                   (if (eq rest-lines-operation 'relative)
                                       (combobulate-indent-string-1 line 'add (- new-first-line-indentation
                                                                                 first-line-indentation))
                                     (combobulate-indent-string-1 line rest-lines-operation rest-lines-amount)))
                                 (cdr lines))
                       (cdr lines))))
    (string-join (cons first-line rest-lines) "\n")))