Function: combobulate-indent-string-1

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

Signature

(combobulate-indent-string-1 LINE OPERATION AMOUNT)

Documentation

Indent LINE as per OPERATION and AMOUNT.

If OPERATION is add, then AMOUNT is added to the current indentation.

If OPERATION is subtract, then AMOUNT is subtracted from the current indentation.

If OPERATION is absolute, then AMOUNT is used as the new indentation.

Source Code

;; Defined in /nix/store/b5fvrwzi3zvkabyzx0in6gw1cj963z46-emacs-packages-deps/share/emacs/site-lisp/combobulate-manipulation.el
(defun combobulate-indent-string-1 (line operation amount)
  "Indent LINE as per OPERATION and AMOUNT.

If OPERATION is `add', then AMOUNT is added to the current
indentation.

If OPERATION is `subtract', then AMOUNT is subtracted from the
current indentation.

If OPERATION is `absolute', then AMOUNT is used as the new
indentation."
  ;; operation must be: `add', `subtract', `absolute'.
  (cl-assert (member operation '(add subtract absolute)))
  ;; see if we can invert operations if the amount warrants it.
  (cond
   ((and (eq operation 'add) (< amount 0))
    (setq operation 'subtract
          amount (- amount)))
   ((and (eq operation 'subtract) (< amount 0))
    (setq operation 'add
          amount (- amount))))
  (let ((current-indent (combobulate-indent-string--count-whitespace line))
        (line-without-indent (combobulate-indent-string--strip-whitespace line)))
    (cond ((eq operation 'add)
           ;; if the amount is zero, then there is nothing to add.
           (if (= amount 0) line
             (concat (make-string (+ current-indent amount) ? ) line-without-indent)))
          ((eq operation 'subtract)
           ;; check for whether we're subtracting more than we
           ;; have. If so, then we subtract the exact amount we need.
           (cond ((>= current-indent amount)
                  (concat (make-string (- current-indent amount) ? ) line-without-indent))
                 (t
                  (concat (make-string 0 ? ) line-without-indent))))
          ((eq operation 'absolute)
           (cl-assert (>= amount 0) "Absolute indentation must be positive.")
           (concat (make-string amount ? ) line-without-indent)))))