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

ruby-changes:28255

From: knu <ko1@a...>
Date: Mon, 15 Apr 2013 22:15:32 +0900 (JST)
Subject: [ruby-changes:28255] knu:r40307 (trunk): misc/ruby-electric.el: Decrease the excess voltage of automatic matching.

knu	2013-04-15 22:15:20 +0900 (Mon, 15 Apr 2013)

  New Revision: 40307

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

  Log:
    misc/ruby-electric.el: Decrease the excess voltage of automatic matching.
    
    * misc/ruby-electric.el (ruby-electric-closing-char): New
      interactive function bound to closing characters.  Typing one of
      those closing characters right after the matching counterpart
      cancels the effect of automatic closing.  For example, typing
      "{" followed by "}" simply makes "{}" instead of "{ } }".

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40306)
+++ ChangeLog	(revision 40307)
@@ -1,8 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Mon Apr 15 21:55:12 2013  Akinori MUSHA  <knu@i...>
+Mon Apr 15 22:01:02 2013  Akinori MUSHA  <knu@i...>
 
 	* misc/ruby-electric.el (ruby-electric-insert): Check
 	  ruby-electric-is-last-command-char-expandable-punct-p here.
 
+	* misc/ruby-electric.el (ruby-electric-closing-char): New
+	  interactive function bound to closing characters.  Typing one of
+	  those closing characters right after the matching counterpart
+	  cancels the effect of automatic closing.  For example, typing
+	  "{" followed by "}" simply makes "{}" instead of "{ } }".
+
 Mon Apr 15 12:54:42 2013  Martin Bosslet  <Martin.Bosslet@g...>
 
 	* ext/openssl/ossl_ssl.c: Correct shutdown behavior w.r.t GC.
Index: misc/ruby-electric.el
===================================================================
--- misc/ruby-electric.el	(revision 40306)
+++ misc/ruby-electric.el	(revision 40307)
@@ -120,6 +120,9 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L120
   (define-key ruby-mode-map "[" 'ruby-electric-matching-char)
   (define-key ruby-mode-map "\"" 'ruby-electric-matching-char)
   (define-key ruby-mode-map "\'" 'ruby-electric-matching-char)
+  (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-closing-char)
   (define-key ruby-mode-map "|" 'ruby-electric-bar)
   (define-key ruby-mode-map "#" 'ruby-electric-hash))
 
@@ -226,7 +229,7 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L229
         ((or
           (ruby-electric-command-char-expandable-punct-p ?\#)
           (ruby-electric-escaped-p))
-         t)
+         (setq this-command 'self-insert-command))
         (t
          (insert "#")
          (forward-char 1)
@@ -249,9 +252,39 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L252
   (interactive "P")
   (ruby-electric-insert
    arg
-   (and (ruby-electric-code-at-point-p)
-        (save-excursion (insert (cdr (assoc last-command-event
-                                            ruby-electric-matching-delimeter-alist)))))))))
+   (cond
+    ((and
+      (eq last-command 'ruby-electric-matching-char)
+      (char-equal last-command-event (following-char))) ;; repeated ' or "
+     (setq this-command 'self-insert-command)
+     (delete-forward-char 1))
+    (t
+     (and (ruby-electric-code-at-point-p)
+          (save-excursion (insert (cdr (assoc last-command-event
+                                              ruby-electric-matching-delimeter-alist)))))))))
+
+(defun ruby-electric-closing-char(arg)
+  (interactive "P")
+  (cond
+   ((ruby-electric-cua-replace-region-p)
+    (ruby-electric-cua-replace-region))
+   (arg
+    (setq this-command 'self-insert-command)
+    (self-insert-command (prefix-numeric-value arg)))
+   ((and
+     (eq last-command 'ruby-electric-curlies)
+     (= last-command-event ?})) ;; {}
+    (if (char-equal (following-char) ?\n) (delete-char 1))
+    (delete-horizontal-space)
+    (forward-char))
+   ((and
+     (= last-command-event (following-char))
+     (memq last-command '(ruby-electric-matching-char
+                          ruby-electric-closing-char))) ;; ()/[] and (())/[[]]
+    (forward-char))
+   (t
+    (setq this-command 'self-insert-command)
+    (self-insert-command 1))))
 
 (defun ruby-electric-bar(arg)
   (interactive "P")

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

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