aboutsummaryrefslogtreecommitdiffstats
path: root/misc
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-15 13:15:20 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-15 13:15:20 +0000
commit7190cc5df9a83db388311a6958b6449fbe23ca8b (patch)
tree2390e70d602d498f2d7b4a065dc46c3cb2217e25 /misc
parented3b657d7db2b62bd7bf80495417aea73d1ddd1e (diff)
downloadruby-7190cc5df9a83db388311a6958b6449fbe23ca8b.tar.gz
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 "{ } }". git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40307 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'misc')
-rw-r--r--misc/ruby-electric.el41
1 files changed, 37 insertions, 4 deletions
diff --git a/misc/ruby-electric.el b/misc/ruby-electric.el
index 994343dcb1..1e43de4b5f 100644
--- a/misc/ruby-electric.el
+++ b/misc/ruby-electric.el
@@ -120,6 +120,9 @@ strings. Note that you must have Font Lock enabled."
(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 Lock enabled."
((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 Lock enabled."
(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")