mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
misc/ruby-electric.el: Avoid electric insertion in some cases.
* misc/ruby-electric.el (ruby-electric-curlies) (ruby-electric-matching-char, ruby-electric-bar): Avoid electric insertion when there is a prefix argument. * misc/ruby-electric.el (ruby-electric-insert) (ruby-electric-cua-replace-region-p) (ruby-electric-cua-replace-region): Avoid electric insertion and fall back when cua-mode is enabled and a region is active. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39419 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c2204ca328
commit
5b7d2440ca
2 changed files with 59 additions and 32 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
||||||
|
Sat Feb 23 12:26:43 2013 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
|
* misc/ruby-electric.el (ruby-electric-curlies)
|
||||||
|
(ruby-electric-matching-char, ruby-electric-bar): Avoid electric
|
||||||
|
insertion when there is a prefix argument.
|
||||||
|
|
||||||
|
* misc/ruby-electric.el (ruby-electric-insert)
|
||||||
|
(ruby-electric-cua-replace-region-p)
|
||||||
|
(ruby-electric-cua-replace-region): Avoid electric insertion and
|
||||||
|
fall back when cua-mode is enabled and a region is active.
|
||||||
|
|
||||||
Sat Feb 23 12:35:00 2013 Zachary Scott <zachary@zacharyscott.net>
|
Sat Feb 23 12:35:00 2013 Zachary Scott <zachary@zacharyscott.net>
|
||||||
|
|
||||||
* array.c: Document #<=> return values and formatting
|
* array.c: Document #<=> return values and formatting
|
||||||
|
|
|
@ -159,47 +159,63 @@ strings. Note that you must have Font Lock enabled."
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(looking-at ruby-electric-single-keyword-in-line-re))))))))
|
(looking-at ruby-electric-single-keyword-in-line-re))))))))
|
||||||
|
|
||||||
|
(defun ruby-electric-cua-replace-region-p()
|
||||||
|
(eq (key-binding "a") 'cua-replace-region))
|
||||||
|
|
||||||
|
(defun ruby-electric-cua-replace-region()
|
||||||
|
(setq this-original-command 'self-insert-command)
|
||||||
|
(setq this-command 'cua-replace-region)
|
||||||
|
(cua-replace-region))
|
||||||
|
|
||||||
|
(defmacro ruby-electric-insert (arg &rest body)
|
||||||
|
`(cond ((ruby-electric-cua-replace-region-p)
|
||||||
|
(ruby-electric-cua-replace-region))
|
||||||
|
((null ,arg)
|
||||||
|
(self-insert-command 1)
|
||||||
|
,@body)
|
||||||
|
(t
|
||||||
|
(self-insert-command (prefix-numeric-value ,arg)))))
|
||||||
|
|
||||||
(defun ruby-electric-curlies(arg)
|
(defun ruby-electric-curlies(arg)
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(self-insert-command (prefix-numeric-value arg))
|
(ruby-electric-insert arg
|
||||||
(if (ruby-electric-is-last-command-char-expandable-punct-p)
|
(if (ruby-electric-is-last-command-char-expandable-punct-p)
|
||||||
(cond ((ruby-electric-code-at-point-p)
|
(cond ((ruby-electric-code-at-point-p)
|
||||||
(insert " ")
|
(insert " ")
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(if ruby-electric-newline-before-closing-bracket
|
(if ruby-electric-newline-before-closing-bracket
|
||||||
(progn
|
(progn
|
||||||
(newline)
|
(newline)
|
||||||
(insert "}")
|
(insert "}")
|
||||||
(ruby-indent-line t))
|
(ruby-indent-line t))
|
||||||
(insert "}"))))
|
(insert "}"))))
|
||||||
((ruby-electric-string-at-point-p)
|
((ruby-electric-string-at-point-p)
|
||||||
(if (eq last-command-event ?{)
|
(if (eq last-command-event ?{)
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(backward-char 1)
|
(backward-char 1)
|
||||||
(or (char-equal ?\# (preceding-char))
|
(or (char-equal ?\# (preceding-char))
|
||||||
(insert "#"))
|
(insert "#"))
|
||||||
(forward-char 1)
|
(forward-char 1)
|
||||||
(insert "}")))))))
|
(insert "}"))))))))
|
||||||
|
|
||||||
(defun ruby-electric-matching-char(arg)
|
(defun ruby-electric-matching-char(arg)
|
||||||
(interactive "P")
|
(interactive "P")
|
||||||
(self-insert-command (prefix-numeric-value arg))
|
(ruby-electric-insert arg
|
||||||
(and (ruby-electric-is-last-command-char-expandable-punct-p)
|
(and (ruby-electric-is-last-command-char-expandable-punct-p)
|
||||||
(ruby-electric-code-at-point-p)
|
(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")
|
||||||
(self-insert-command (prefix-numeric-value arg))
|
(ruby-electric-insert arg
|
||||||
(and (ruby-electric-is-last-command-char-expandable-punct-p)
|
(and (ruby-electric-is-last-command-char-expandable-punct-p)
|
||||||
(ruby-electric-code-at-point-p)
|
(ruby-electric-code-at-point-p)
|
||||||
(and (save-excursion (re-search-backward ruby-electric-expandable-bar nil t))
|
(and (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 "|")))))
|
||||||
|
|
||||||
|
|
||||||
(provide 'ruby-electric)
|
(provide 'ruby-electric)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue