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

ruby-changes:31369

From: knu <ko1@a...>
Date: Mon, 28 Oct 2013 14:45:29 +0900 (JST)
Subject: [ruby-changes:31369] knu:r43448 (trunk): * misc/ruby-electric.el: Import ruby-electric.el 2.1 from

knu	2013-10-28 14:45:23 +0900 (Mon, 28 Oct 2013)

  New Revision: 43448

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

  Log:
    * misc/ruby-electric.el: Import ruby-electric.el 2.1 from
      https://github.com/knu/ruby-electric.el.
    
      * Hitting the newline-and-indent key within a comment fires
        comment-indent-new-line.
    
      * Introduce a new feature
        `ruby-electric-autoindent-on-closing-char`.
    
      * Fix fallback behavior of ruby-electric-space/return that
        caused error with auto-complete.

  Modified files:
    trunk/ChangeLog
    trunk/misc/ruby-electric.el
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43447)
+++ ChangeLog	(revision 43448)
@@ -1,3 +1,17 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Oct 28 14:41:27 2013  Akinori MUSHA  <knu@i...>
+
+	* misc/ruby-electric.el: Import ruby-electric.el 2.1 from
+	  https://github.com/knu/ruby-electric.el.
+
+	  * Hitting the newline-and-indent key within a comment fires
+	    comment-indent-new-line.
+
+	  * Introduce a new feature
+	    `ruby-electric-autoindent-on-closing-char`.
+
+	  * Fix fallback behavior of ruby-electric-space/return that
+	    caused error with auto-complete.
+
 Mon Oct 28 13:17:17 2013  Or Cohen  <orc@f...>
 
 	* error.c (name_err_to_s): remove no longer needed overriding, since
Index: misc/ruby-electric.el
===================================================================
--- misc/ruby-electric.el	(revision 43447)
+++ misc/ruby-electric.el	(revision 43448)
@@ -10,7 +10,7 @@ https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L10
 ;; URL: https://github.com/knu/ruby-electric.el
 ;; Keywords: languages ruby
 ;; License: The same license terms as Ruby
-;; Version: 2.0.1
+;; Version: 2.1
 
 ;;; Commentary:
 ;;
@@ -185,8 +185,8 @@ instead." https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L185
   "Keymap used in ruby-electric-mode")
 
 (defcustom ruby-electric-expand-delimiters-list '(all)
-  "*List of contexts where matching delimiter should be
-inserted. The word 'all' will do all insertions."
+  "*List of contexts where matching delimiter should be inserted.
+The word 'all' will do all insertions."
   :type `(set :extra-offset 8
               (const :tag "Everything" all)
               ,@(apply 'list
@@ -197,8 +197,13 @@ inserted. The word 'all' will do all ins https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L197
   :group 'ruby-electric)
 
 (defcustom ruby-electric-newline-before-closing-bracket nil
-  "*Controls whether a newline should be inserted before the
-closing bracket or not."
+  "*Non-nil means a newline should be inserted before an
+automatically inserted closing bracket."
+  :type 'boolean :group 'ruby-electric)
+
+(defcustom ruby-electric-autoindent-on-closing-char nil
+  "*Non-nil means the current line should be automatically
+indented when a closing character is manually typed in."
   :type 'boolean :group 'ruby-electric)
 
 (defvar ruby-electric-mode-hook nil
@@ -227,6 +232,17 @@ enabled." https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L232
   (if ruby-electric-mode
       (run-hooks 'ruby-electric-mode-hook)))
 
+(defun ruby-electric-space/return-fallback ()
+  (if (or (eq this-original-command 'ruby-electric-space/return)
+          (null (ignore-errors
+                  ;; ac-complete may fail if there is nothing left to complete
+                  (call-interactively this-original-command)
+                  (setq this-command this-original-command))))
+      ;; fall back to a globally bound command
+      (let ((command (global-key-binding (char-to-string last-command-event) t)))
+        (and command
+             (call-interactively (setq this-command command))))))
+
 (defun ruby-electric-space/return (arg)
   (interactive "*P")
   (and (boundp 'sp-last-operation)
@@ -257,13 +273,12 @@ enabled." https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L273
                     (ruby-insert-end)))
                  ((eq action 'reindent)
                   (ruby-indent-line)))
-           (if (char-equal last-command-event ?\s)
-               (insert " ")
-             (funcall this-original-command))))
+           (ruby-electric-space/return-fallback)))
+        ((and (eq this-original-command 'newline-and-indent)
+              (ruby-electric-comment-at-point-p))
+         (call-interactively (setq this-command 'comment-indent-new-line)))
         (t
-         (if (char-equal last-command-event ?\s)
-             (insert " ")
-           (funcall (setq this-command this-original-command))))))
+         (ruby-electric-space/return-fallback))))
 
 (defun ruby-electric-code-at-point-p()
   (and ruby-electric-mode
@@ -275,6 +290,10 @@ enabled." https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L290
   (and ruby-electric-mode
        (consp (memq 'font-lock-string-face (text-properties-at (point))))))
 
+(defun ruby-electric-comment-at-point-p()
+  (and ruby-electric-mode
+       (consp (memq 'font-lock-comment-face (text-properties-at (point))))))
+
 (defun ruby-electric-escaped-p()
   (let ((f nil))
     (save-excursion
@@ -413,7 +432,9 @@ enabled." https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L432
     (forward-char))
    (t
     (setq this-command 'self-insert-command)
-    (self-insert-command 1))))
+    (self-insert-command 1)
+    (if ruby-electric-autoindent-on-closing-char
+        (ruby-indent-line)))))
 
 (defun ruby-electric-bar(arg)
   (interactive "*P")

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

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