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

ruby-changes:28254

From: knu <ko1@a...>
Date: Mon, 15 Apr 2013 22:15:30 +0900 (JST)
Subject: [ruby-changes:28254] knu:r40306 (trunk): misc/ruby-electric.el: Minor refactoring.

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

  New Revision: 40306

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

  Log:
    misc/ruby-electric.el: Minor refactoring.
    
    * misc/ruby-electric.el (ruby-electric-insert): Check
      ruby-electric-is-last-command-char-expandable-punct-p here.

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

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40305)
+++ ChangeLog	(revision 40306)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Apr 15 21:55:12 2013  Akinori MUSHA  <knu@i...>
+
+	* misc/ruby-electric.el (ruby-electric-insert): Check
+	  ruby-electric-is-last-command-char-expandable-punct-p here.
+
 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 40305)
+++ misc/ruby-electric.el	(revision 40306)
@@ -184,59 +184,60 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L184
 (defmacro ruby-electric-insert (arg &rest body)
   `(cond ((ruby-electric-cua-replace-region-p)
           (ruby-electric-cua-replace-region))
-         ((null ,arg)
+         ((and
+           (null ,arg)
+           (ruby-electric-is-last-command-char-expandable-punct-p))
           (self-insert-command 1)
           ,@body)
          (t
+          (setq this-command 'self-insert-command)
           (self-insert-command (prefix-numeric-value ,arg)))))
 
 (defun ruby-electric-curlies(arg)
   (interactive "P")
   (ruby-electric-insert
    arg
-   (if (ruby-electric-is-last-command-char-expandable-punct-p)
+   (cond
+    ((ruby-electric-code-at-point-p)
+     (insert "}")
+     (backward-char 1)
+     (redisplay)
+     (cond
+      ((ruby-electric-string-at-point-p) ;; %w{}, %r{}, etc.
+       t)
+      (ruby-electric-newline-before-closing-bracket
+       (insert " ")
+       (save-excursion
+         (newline)
+         (ruby-indent-line t)))
+      (t
+       (insert "  ")
+       (backward-char 1))))
+    ((ruby-electric-string-at-point-p)
+     (save-excursion
+       (backward-char 1)
        (cond
-        ((ruby-electric-code-at-point-p)
-         (insert "}")
-         (backward-char 1)
-         (redisplay)
-         (cond
-          ((ruby-electric-string-at-point-p) ; %w{}, %r{}, etc.
-           t)
-          (ruby-electric-newline-before-closing-bracket
-           (insert " ")
-           (save-excursion
-             (newline)
-             (ruby-indent-line t)))
-          (t
-           (insert "  ")
-           (backward-char 1))))
-        ((ruby-electric-string-at-point-p)
-         (save-excursion
-           (backward-char 1)
-           (cond
-            ((char-equal ?\# (preceding-char))
-             (unless (save-excursion
-                       (backward-char 1)
-                       (ruby-electric-escaped-p))
-               (forward-char 1)
-               (insert "}")))
-            ((ruby-electric-command-char-expandable-punct-p ?\#)
-             t) ; no need for the following if ruby-electric-hash is enabled
-            ((ruby-electric-escaped-p)
-             t)
-            (t
-             (insert "#")
-             (forward-char 1)
-             (insert "}")))))))))
+        ((char-equal ?\# (preceding-char))
+         (unless (save-excursion
+                   (backward-char 1)
+                   (ruby-electric-escaped-p))
+           (forward-char 1)
+           (insert "}")))
+        ((or
+          (ruby-electric-command-char-expandable-punct-p ?\#)
+          (ruby-electric-escaped-p))
+         t)
+        (t
+         (insert "#")
+         (forward-char 1)
+         (insert "}"))))))))
 
 (defun ruby-electric-hash(arg)
   (interactive "P")
   (ruby-electric-insert
    arg
-   (and (ruby-electric-is-last-command-char-expandable-punct-p)
-        (ruby-electric-string-at-point-p)
-        (or (looking-at "'") ; likely to be in ''
+   (and (ruby-electric-string-at-point-p)
+        (or (char-equal (following-char) ?') ;; likely to be in ''
             (save-excursion
               (backward-char 1)
               (ruby-electric-escaped-p))
@@ -246,22 +247,21 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L247
 
 (defun ruby-electric-matching-char(arg)
   (interactive "P")
-  (ruby-electric-insert arg
-    (and (ruby-electric-is-last-command-char-expandable-punct-p)
-         (ruby-electric-code-at-point-p)
-         (save-excursion
-           (insert (cdr (assoc last-command-event
-                               ruby-electric-matching-delimeter-alist)))))))
+  (ruby-electric-insert
+   arg
+   (and (ruby-electric-code-at-point-p)
+        (save-excursion (insert (cdr (assoc last-command-event
+                                            ruby-electric-matching-delimeter-alist)))))))))
 
 (defun ruby-electric-bar(arg)
   (interactive "P")
-  (ruby-electric-insert arg
-    (and (ruby-electric-is-last-command-char-expandable-punct-p)
-         (ruby-electric-code-at-point-p)
-         (and (save-excursion (re-search-backward ruby-electric-expandable-bar nil t))
-              (= (point) (match-end 0))) ;looking-back is missing on XEmacs
-         (save-excursion
-           (insert "|")))))
+  (ruby-electric-insert
+   arg
+   (and (ruby-electric-code-at-point-p)
+        (save-excursion (re-search-backward ruby-electric-expandable-bar nil t))
+        (= (point) (match-end 0)) ;; looking-back is missing on XEmacs
+        (save-excursion
+          (insert "|")))))
 
 
 (provide 'ruby-electric)

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

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