Function: evil-maybe-remove-spaces

evil-maybe-remove-spaces is a byte-compiled function defined in evil-states.el.

Signature

(evil-maybe-remove-spaces &optional DO-REMOVE)

Documentation

Remove space from newly opened empty line.

This function removes (indentation) spaces that have been inserted by opening a new empty line. The behavior depends on the variable evil-maybe-remove-spaces(var)/evil-maybe-remove-spaces(fun). If this variable is nil the function does nothing. Otherwise the behavior depends on DO-REMOVE. If DO-REMOVE is non-nil the spaces are removed. Otherwise evil-maybe-remove-spaces(var)/evil-maybe-remove-spaces(fun) is set to nil unless the last command opened yet another new line.

This function should be added as a post-command-hook to track commands opening a new line.

Source Code

;; Defined in ~/.emacs.d/elpa/evil-20251108.138/evil-states.el
;;; Insert state

(defun evil-maybe-remove-spaces (&optional do-remove)
  "Remove space from newly opened empty line.
This function removes (indentation) spaces that have been
inserted by opening a new empty line. The behavior depends on the
variable `evil-maybe-remove-spaces'. If this variable is nil the
function does nothing. Otherwise the behavior depends on
DO-REMOVE.  If DO-REMOVE is non-nil the spaces are
removed. Otherwise `evil-maybe-remove-spaces' is set to nil
unless the last command opened yet another new line.

This function should be added as a post-command-hook to track
commands opening a new line."
  (cond
   ((not evil-maybe-remove-spaces)
    (remove-hook 'post-command-hook #'evil-maybe-remove-spaces))
   (do-remove
    (when (save-excursion
            (beginning-of-line)
            (looking-at "^\\s-*$"))
      (delete-region (line-beginning-position)
                     (line-end-position)))
    (setq evil-maybe-remove-spaces nil)
    (remove-hook 'post-command-hook #'evil-maybe-remove-spaces))
   ((not (memq this-command
               '(evil-open-above
                 evil-open-below
                 evil-append
                 evil-append-line
                 evil-change-whole-line
                 newline
                 newline-and-indent
                 indent-and-newline)))
    (setq evil-maybe-remove-spaces nil)
    (remove-hook 'post-command-hook #'evil-maybe-remove-spaces))))