1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
knu 2013-04-15 13:15:20 +00:00
parent ed3b657d7d
commit 7190cc5df9
2 changed files with 44 additions and 5 deletions

View file

@ -1,8 +1,14 @@
Mon Apr 15 21:55:12 2013 Akinori MUSHA <knu@iDaemons.org> Mon Apr 15 22:01:02 2013 Akinori MUSHA <knu@iDaemons.org>
* misc/ruby-electric.el (ruby-electric-insert): Check * misc/ruby-electric.el (ruby-electric-insert): Check
ruby-electric-is-last-command-char-expandable-punct-p here. 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@gmail.com> Mon Apr 15 12:54:42 2013 Martin Bosslet <Martin.Bosslet@gmail.com>
* ext/openssl/ossl_ssl.c: Correct shutdown behavior w.r.t GC. * ext/openssl/ossl_ssl.c: Correct shutdown behavior w.r.t GC.

View file

@ -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-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-bar)
(define-key ruby-mode-map "#" 'ruby-electric-hash)) (define-key ruby-mode-map "#" 'ruby-electric-hash))
@ -226,7 +229,7 @@ strings. Note that you must have Font Lock enabled."
((or ((or
(ruby-electric-command-char-expandable-punct-p ?\#) (ruby-electric-command-char-expandable-punct-p ?\#)
(ruby-electric-escaped-p)) (ruby-electric-escaped-p))
t) (setq this-command 'self-insert-command))
(t (t
(insert "#") (insert "#")
(forward-char 1) (forward-char 1)
@ -249,10 +252,40 @@ strings. Note that you must have Font Lock enabled."
(interactive "P") (interactive "P")
(ruby-electric-insert (ruby-electric-insert
arg arg
(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) (and (ruby-electric-code-at-point-p)
(save-excursion (insert (cdr (assoc last-command-event (save-excursion (insert (cdr (assoc last-command-event
ruby-electric-matching-delimeter-alist))))))))) 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) (defun ruby-electric-bar(arg)
(interactive "P") (interactive "P")
(ruby-electric-insert (ruby-electric-insert