From 04cd02784b5d4339acbf0d5c74a3fd5451daded7 Mon Sep 17 00:00:00 2001 From: nex3 Date: Thu, 8 Mar 2007 06:50:46 +0000 Subject: [PATCH] Added a handy backspace binding to the haml-mode.el. git-svn-id: svn://hamptoncatlin.com/haml/trunk@401 7063305b-7217-0410-af8c-cdc13e5119b9 --- extra/haml-mode.el | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/extra/haml-mode.el b/extra/haml-mode.el index eebc7c5d..acc85118 100644 --- a/extra/haml-mode.el +++ b/extra/haml-mode.el @@ -25,6 +25,11 @@ :type 'integer :group 'haml) +(defcustom haml-backspace-function 'backward-delete-char-untabify + "*Function called by `haml-electric-backspace' when deleting backwards." + :type 'function + :group 'haml) + ;; Helper Functions (defun string-* (str i) @@ -42,7 +47,7 @@ (defconst haml-blank-line-re "^[ \t]*$" "Regexp matching a line containing only whitespace.") -(defconst haml-tag-re (hre "[%\\.#][^ \t]*\\({.*}\\)?\\(\\[.*\\]\\).?[ \t]*$") +(defconst haml-tag-re (hre "[%\\.#][^ \t]*\\({.*}\\)?\\(\\[.*\\]\\)?.?[ \t]*$") "Regexp matching a Haml tag.") (defconst haml-block-re (hre "[-=].*do[ \t]*\\(|.*|[ \t]*\\)?$") @@ -70,6 +75,9 @@ (if haml-mode-map nil (setq haml-mode-map (make-sparse-keymap)) + (define-key haml-mode-map [backspace] 'haml-electric-backspace) + (define-key haml-mode-map "\C-?" 'haml-electric-backspace) + (define-key haml-mode-map "\C-a" 'haml-electric-backspace) (define-key haml-mode-map "\C-j" 'newline-and-indent)) ;(defvar haml-mode-syntax-table nil @@ -129,6 +137,22 @@ back-dent the line by `haml-indent-offset' spaces. On reaching column (if (< (current-column) (current-indentation)) (forward-to-indentation 0)))) +(defun haml-electric-backspace (arg) + "Delete characters or back-dent the current line. +If invoked following only whitespace on a line, will back-dent to the +immediately previous multiple of `haml-indent-offset' spaces." + (interactive "*p") + (if (or (/= (current-indentation) (current-column)) (bolp)) + (funcall haml-backspace-function arg) + (let ((ci (current-column))) + (beginning-of-line) + (delete-horizontal-space) + (indent-to (* (/ (- ci (* arg haml-indent-offset)) + haml-indent-offset) + haml-indent-offset))))) + +;; Setup/Activation + (defun haml-mode-version () "Diplay version of `haml-mode'." (interactive)