misc/ruby-electric.el: Minor refactoring.

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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40306 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2013-04-15 13:15:17 +00:00
parent d6b1ab91dc
commit ed3b657d7d
2 changed files with 56 additions and 51 deletions

View File

@ -1,3 +1,8 @@
Mon Apr 15 21:55:12 2013 Akinori MUSHA <knu@iDaemons.org>
* 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@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

@ -184,24 +184,26 @@ strings. Note that you must have Font Lock enabled."
(defmacro ruby-electric-insert (arg &rest body) (defmacro ruby-electric-insert (arg &rest body)
`(cond ((ruby-electric-cua-replace-region-p) `(cond ((ruby-electric-cua-replace-region-p)
(ruby-electric-cua-replace-region)) (ruby-electric-cua-replace-region))
((null ,arg) ((and
(null ,arg)
(ruby-electric-is-last-command-char-expandable-punct-p))
(self-insert-command 1) (self-insert-command 1)
,@body) ,@body)
(t (t
(setq this-command 'self-insert-command)
(self-insert-command (prefix-numeric-value ,arg))))) (self-insert-command (prefix-numeric-value ,arg)))))
(defun ruby-electric-curlies(arg) (defun ruby-electric-curlies(arg)
(interactive "P") (interactive "P")
(ruby-electric-insert (ruby-electric-insert
arg arg
(if (ruby-electric-is-last-command-char-expandable-punct-p)
(cond (cond
((ruby-electric-code-at-point-p) ((ruby-electric-code-at-point-p)
(insert "}") (insert "}")
(backward-char 1) (backward-char 1)
(redisplay) (redisplay)
(cond (cond
((ruby-electric-string-at-point-p) ; %w{}, %r{}, etc. ((ruby-electric-string-at-point-p) ;; %w{}, %r{}, etc.
t) t)
(ruby-electric-newline-before-closing-bracket (ruby-electric-newline-before-closing-bracket
(insert " ") (insert " ")
@ -221,22 +223,21 @@ strings. Note that you must have Font Lock enabled."
(ruby-electric-escaped-p)) (ruby-electric-escaped-p))
(forward-char 1) (forward-char 1)
(insert "}"))) (insert "}")))
((ruby-electric-command-char-expandable-punct-p ?\#) ((or
t) ; no need for the following if ruby-electric-hash is enabled (ruby-electric-command-char-expandable-punct-p ?\#)
((ruby-electric-escaped-p) (ruby-electric-escaped-p))
t) t)
(t (t
(insert "#") (insert "#")
(forward-char 1) (forward-char 1)
(insert "}"))))))))) (insert "}"))))))))
(defun ruby-electric-hash(arg) (defun ruby-electric-hash(arg)
(interactive "P") (interactive "P")
(ruby-electric-insert (ruby-electric-insert
arg arg
(and (ruby-electric-is-last-command-char-expandable-punct-p) (and (ruby-electric-string-at-point-p)
(ruby-electric-string-at-point-p) (or (char-equal (following-char) ?') ;; likely to be in ''
(or (looking-at "'") ; likely to be in ''
(save-excursion (save-excursion
(backward-char 1) (backward-char 1)
(ruby-electric-escaped-p)) (ruby-electric-escaped-p))
@ -246,20 +247,19 @@ strings. Note that you must have Font Lock enabled."
(defun ruby-electric-matching-char(arg) (defun ruby-electric-matching-char(arg)
(interactive "P") (interactive "P")
(ruby-electric-insert arg (ruby-electric-insert
(and (ruby-electric-is-last-command-char-expandable-punct-p) arg
(ruby-electric-code-at-point-p) (and (ruby-electric-code-at-point-p)
(save-excursion (save-excursion (insert (cdr (assoc last-command-event
(insert (cdr (assoc last-command-event ruby-electric-matching-delimeter-alist)))))))))
ruby-electric-matching-delimeter-alist)))))))
(defun ruby-electric-bar(arg) (defun ruby-electric-bar(arg)
(interactive "P") (interactive "P")
(ruby-electric-insert arg (ruby-electric-insert
(and (ruby-electric-is-last-command-char-expandable-punct-p) arg
(ruby-electric-code-at-point-p) (and (ruby-electric-code-at-point-p)
(and (save-excursion (re-search-backward ruby-electric-expandable-bar nil t)) (save-excursion (re-search-backward ruby-electric-expandable-bar nil t))
(= (point) (match-end 0))) ;looking-back is missing on XEmacs (= (point) (match-end 0)) ;; looking-back is missing on XEmacs
(save-excursion (save-excursion
(insert "|"))))) (insert "|")))))