[前][次][番号順一覧][スレッド一覧]

ruby-changes:28765

From: knu <ko1@a...>
Date: Sun, 19 May 2013 02:38:22 +0900 (JST)
Subject: [ruby-changes:28765] knu:r40817 (trunk): * misc/ruby-electric.el (ruby-electric-delete-backward-char):

knu	2013-05-19 02:38:04 +0900 (Sun, 19 May 2013)

  New Revision: 40817

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=40817

  Log:
    * misc/ruby-electric.el (ruby-electric-delete-backward-char):
      Introduce electric DEL that deletes what the previous electric
      command has input.

  Modified files:
    trunk/ChangeLog
    trunk/misc/ruby-electric.el

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40816)
+++ ChangeLog	(revision 40817)
@@ -1,4 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Sun May 19 02:27:21 2013  Akinori MUSHA  <knu@i...>
+Sun May 19 02:30:00 2013  Akinori MUSHA  <knu@i...>
+
+	* misc/ruby-electric.el (ruby-electric-delete-backward-char):
+	  Introduce electric DEL that deletes what the previous electric
+	  command has input.
 
 	* misc/ruby-electric.el (ruby-electric-matching-char): Make
 	  electric quotes work again at the end of buffer.
Index: misc/ruby-electric.el
===================================================================
--- misc/ruby-electric.el	(revision 40816)
+++ misc/ruby-electric.el	(revision 40817)
@@ -124,7 +124,8 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L124
   (define-key ruby-mode-map ")" 'ruby-electric-closing-char)
   (define-key ruby-mode-map "]" 'ruby-electric-closing-char)
   (define-key ruby-mode-map "|" 'ruby-electric-bar)
-  (define-key ruby-mode-map "#" 'ruby-electric-hash))
+  (define-key ruby-mode-map "#" 'ruby-electric-hash)
+  (define-key ruby-mode-map (kbd "DEL") 'ruby-electric-delete-backward-char))
 
 (defun ruby-electric-space (arg)
   (interactive "P")
@@ -184,6 +185,11 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L185
   (setq this-command 'cua-replace-region)
   (cua-replace-region))
 
+(defun ruby-electric-cua-delete-region()
+  (setq this-original-command 'delete-backward-char)
+  (setq this-command 'cua-delete-region)
+  (cua-delete-region))
+
 (defmacro ruby-electric-insert (arg &rest body)
   `(cond ((ruby-electric-cua-replace-region-p)
           (ruby-electric-cua-replace-region))
@@ -312,5 +318,28 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L318
         (save-excursion
           (insert "|")))))
 
+(defun ruby-electric-delete-backward-char(arg)
+  (interactive "P")
+  (if (ruby-electric-cua-replace-region-p)
+      (ruby-electric-cua-delete-region)
+    (cond ((memq last-command '(ruby-electric-matching-char
+                                ruby-electric-bar))
+           (delete-char 1))
+          ((eq last-command 'ruby-electric-curlies)
+           (cond ((eolp)
+                  (cond ((char-equal (preceding-char) ?\s)
+                         (setq this-command last-command))
+                        ((char-equal (preceding-char) ?{)
+                         (and (looking-at "[ \t\n]*}")
+                              (delete-char (- (match-end 0) (match-beginning 0)))))))
+                 ((char-equal (following-char) ?\s)
+                  (setq this-command last-command)
+                  (delete-char 1))
+                 ((char-equal (following-char) ?})
+                  (delete-char 1))))
+          ((eq last-command 'ruby-electric-hash)
+           (and (char-equal (preceding-char) ?{)
+                (delete-char 1))))
+    (delete-backward-char 1)))
 
 (provide 'ruby-electric)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]