1
0
Fork 0
mirror of https://github.com/haml/haml.git synced 2022-11-09 12:33:31 -05:00

[Emacs] Have haml-electric-backspace optionally back-dent the entire nested block.

This commit is contained in:
Nathan Weizenbaum 2008-05-04 13:03:06 -07:00
parent eab5520745
commit 7b9c2d5f1e

View file

@ -33,6 +33,13 @@
:type 'integer :type 'integer
:group 'haml) :group 'haml)
(defcustom haml-backspace-backdents-nesting t
"Non-nil to have `haml-electric-backspace' re-indent all code
nested beneath the backspaced line be re-indented along with the
line itself."
:type 'boolean
:group 'haml)
(defface haml-tab-face (defface haml-tab-face
'((((class color)) (:background "hotpink")) '((((class color)) (:background "hotpink"))
(t (:reverse-video t))) (t (:reverse-video t)))
@ -265,17 +272,33 @@ back-dent the line by `haml-indent-offset' spaces. On reaching column
(defun haml-electric-backspace (arg) (defun haml-electric-backspace (arg)
"Delete characters or back-dent the current line. "Delete characters or back-dent the current line.
If invoked following only whitespace on a line, will back-dent to the If invoked following only whitespace on a line, will back-dent
immediately previous multiple of `haml-indent-offset' spaces." the line and all nested lines to the immediately previous
multiple of `haml-indent-offset' spaces.
Set `haml-backspace-backdents-nesting' to nil to just back-dent
the current line."
(interactive "*p") (interactive "*p")
(if (or (/= (current-indentation) (current-column)) (bolp)) (if (or (/= (current-indentation) (current-column))
(bolp)
(looking-at "^[ \t]+$"))
(backward-delete-char arg) (backward-delete-char arg)
(let ((ci (current-column))) (let ((ci (current-column)))
(beginning-of-line) (beginning-of-line)
(delete-horizontal-space) (if (not haml-backspace-backdents-nesting)
(indent-to (* (/ (- ci (* arg haml-indent-offset)) (set-mark (save-excursion (end-of-line) (point)))
haml-indent-offset) (mark-sexp)
haml-indent-offset))))) (set-mark
(save-excursion
(goto-char (mark))
(beginning-of-line)
(point))))
(save-excursion
(replace-regexp (concat "^" (make-string ci ? ))
(make-string (max 0 (- ci (* arg haml-indent-offset))) ? )
nil (point) (mark)))
(back-to-indentation)
(pop-mark))))
;; Setup/Activation ;; Setup/Activation