When pressing backspace, it deletes a single character, however, I would like it to go back the the previous tab-stop level in the case there is only preceding white-space.

1 Answer 1


This can be done using this function, based on this answer on the Emacs wiki.

(defun my-backspace-whitespace-to-tab-stop ()
  "Delete whitespace backwards to the next tab-stop, otherwise delete one character."
  (if (or indent-tabs-mode (use-region-p)
          (> (point)
      (call-interactively 'backward-delete-char)
    (let ((step (% (current-column) tab-width))
          (pt (point)))
      (when (zerop step)
        (setq step tab-width))
      ;; Account for edge case near beginning of buffer.
      (setq step (min (- pt 1) step))
        (if (string-match "[^\t ]*\\([\t ]+\\)$"
                           (- pt step) pt))
            (backward-delete-char (- (match-end 1)
                                     (match-beginning 1)))
          (call-interactively 'backward-delete-char))))))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.