Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added a option to allow backspace to delete a char/space or a column …

…based on tab-width when using spaces to indent
  • Loading branch information...
commit f48cc2c4f6a5c0b2796ac2febc38020dae61b82b 1 parent 500cc0a
authored October 09, 2009

Showing 1 changed file with 29 additions and 7 deletions. Show diff stats Hide diff stats

  1. 36  textmate.el
36  textmate.el
@@ -49,6 +49,11 @@
49 49
   :type 'boolean
50 50
   :group 'textmate)
51 51
 
  52
+(defcustom tm/backspace-delete-column nil
  53
+  "If set to t, backspace will delete a block os spaces based on tab-width"
  54
+  :type 'boolean
  55
+  :group 'textmate)
  56
+
52 57
 (defcustom tm/dont-activate nil
53 58
   "If set to t, don't activate tm/minor-mode automatically."
54 59
   :type 'boolean
@@ -60,8 +65,8 @@
60 65
   :type 'boolean
61 66
   :group 'textmate)
62 67
 
63  
-(defcustom tm/exempt-quote-modes '(emacs-lisp-mode 
64  
-                                   lisp-mode 
  68
+(defcustom tm/exempt-quote-modes '(emacs-lisp-mode
  69
+                                   lisp-mode
65 70
                                    lisp-interaction-mode)
66 71
   "Modes which in which to not auto-insert a quote"
67 72
   :type '(repeat symbol)
@@ -89,7 +94,7 @@
89 94
   "Toggle Textmate mode.
90 95
      With no argument, this command toggles the mode.
91 96
      Non-null prefix argument turns on the mode.
92  
-     Null prefix argument turns off the mode."     
  97
+     Null prefix argument turns off the mode."
93 98
   ;; The initial value.
94 99
   :init-value nil
95 100
   ;; The indicator for the mode line.
@@ -138,6 +143,21 @@
138 143
   "Check if a pair are next to each other. This is used to allow easy deletion"
139 144
   (interactive)
140 145
   (eq (cdr (assoc (char-before)  textmate-pairs)) (char-after)))
  146
+;; Thanks to Trey Jackson
  147
+;; http://stackoverflow.com/questions/1450169/how-do-i-emulate-vims-softtabstop-in-emacs/1450454#1450454
  148
+(defun tm/backward-delete-whitespace-to-column ()
  149
+  "delete back to the previous column of whitespace, or as much whitespace as possible,
  150
+or just one char if that's not possible"
  151
+  (interactive)
  152
+  (if indent-tabs-mode
  153
+      (call-interactively 'backward-delete-char-untabify)
  154
+    (let ((movement (% (current-column) tab-width))
  155
+          (p (point)))
  156
+      (when (= movement 0) (setq movement tab-width))
  157
+      (save-match-data
  158
+        (if (string-match "\\w*\\(\\s-+\\)$" (buffer-substring-no-properties (- p movement) p))
  159
+            (backward-delete-char-untabify (- (match-end 1) (match-beginning 1)))
  160
+        (call-interactively 'backward-delete-char-untabify))))))
141 161
 
142 162
 (defun tm/backspace ()
143 163
   (interactive)
@@ -145,7 +165,9 @@
145 165
       nil   ;; if char-after is nil, just backspace
146 166
     (if (tm/is-empty-pair)
147 167
         (delete-char 1)))
148  
-  (delete-backward-char 1))
  168
+  (if (eq tm/backspace-delete-column t)
  169
+      (tm/backward-delete-whitespace-to-column)
  170
+    (delete-backward-char 1)))
149 171
 
150 172
 ;; These are used when user has manually inserted the trailing char of a pair
151 173
 (setq pushovers
@@ -163,7 +185,7 @@
163 185
         (?\} . (lambda () (insert-char ?\} 1) ))))
164 186
 
165 187
 (defun tm/move-over (char)
166  
-  "If the user has manually inserted the trailing char, don't insert another 
  188
+  "If the user has manually inserted the trailing char, don't insert another
167 189
    one"
168 190
   (if (eq (char-after) char)
169 191
       (funcall (cdr (assoc char pushovers)))
@@ -178,11 +200,11 @@
178 200
 (defun tm/move-over-bracket ()  (interactive)(tm/move-over ?\)))
179 201
 (defun tm/move-over-curly ()  (interactive)(tm/move-over ?\}))
180 202
 (defun tm/move-over-square ()  (interactive)(tm/move-over ?\]))
181  
-(defun tm/move-over-quote ()  
  203
+(defun tm/move-over-quote ()
182 204
   (interactive)
183 205
   (if (eq (member major-mode tm/exempt-quote-modes) nil)
184 206
       (tm/move-over ?\')
185 207
     (insert-char ?\' 1)))
186  
-(defun tm/move-over-dbl-quote ()  (interactive)(tm/move-over ?\")) 
  208
+(defun tm/move-over-dbl-quote ()  (interactive)(tm/move-over ?\"))
187 209
 
188 210
 (provide 'textmate)

0 notes on commit f48cc2c

Please sign in to comment.
Something went wrong with that request. Please try again.