summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-23 03:55:39 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-23 03:55:39 +0000
commit5b7d2440ca33f68c7b4b6c68553e75137b085666 (patch)
tree1fdcdd51d339c7d0f27931db0bd2dc5392146052 /misc
parentc2204ca328817f3d87232471a4e1de0334425752 (diff)
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
Diffstat (limited to 'misc')
-rw-r--r--misc/ruby-electric.el80
1 files changed, 48 insertions, 32 deletions
diff --git a/misc/ruby-electric.el b/misc/ruby-electric.el
index 95644e24cd..874c178cc6 100644
--- a/misc/ruby-electric.el
+++ b/misc/ruby-electric.el
@@ -159,47 +159,63 @@ strings. Note that you must have Font Lock enabled."
(beginning-of-line)
(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)
(interactive "P")
- (self-insert-command (prefix-numeric-value arg))
- (if (ruby-electric-is-last-command-char-expandable-punct-p)
- (cond ((ruby-electric-code-at-point-p)
- (insert " ")
- (save-excursion
- (if ruby-electric-newline-before-closing-bracket
- (progn
- (newline)
- (insert "}")
- (ruby-indent-line t))
- (insert "}"))))
- ((ruby-electric-string-at-point-p)
- (if (eq last-command-event ?{)
- (save-excursion
- (backward-char 1)
- (or (char-equal ?\# (preceding-char))
- (insert "#"))
- (forward-char 1)
- (insert "}")))))))
+ (ruby-electric-insert arg
+ (if (ruby-electric-is-last-command-char-expandable-punct-p)
+ (cond ((ruby-electric-code-at-point-p)
+ (insert " ")
+ (save-excursion
+ (if ruby-electric-newline-before-closing-bracket
+ (progn
+ (newline)
+ (insert "}")
+ (ruby-indent-line t))
+ (insert "}"))))
+ ((ruby-electric-string-at-point-p)
+ (if (eq last-command-event ?{)
+ (save-excursion
+ (backward-char 1)
+ (or (char-equal ?\# (preceding-char))
+ (insert "#"))
+ (forward-char 1)
+ (insert "}"))))))))
(defun ruby-electric-matching-char(arg)
(interactive "P")
- (self-insert-command (prefix-numeric-value arg))
- (and (ruby-electric-is-last-command-char-expandable-punct-p)
- (ruby-electric-code-at-point-p)
- (save-excursion
- (insert (cdr (assoc last-command-event
- ruby-electric-matching-delimeter-alist))))))
+ (ruby-electric-insert arg
+ (and (ruby-electric-is-last-command-char-expandable-punct-p)
+ (ruby-electric-code-at-point-p)
+ (save-excursion
+ (insert (cdr (assoc last-command-event
+ ruby-electric-matching-delimeter-alist)))))))
(defun ruby-electric-bar(arg)
(interactive "P")
- (self-insert-command (prefix-numeric-value arg))
- (and (ruby-electric-is-last-command-char-expandable-punct-p)
- (ruby-electric-code-at-point-p)
- (and (save-excursion (re-search-backward ruby-electric-expandable-bar nil t))
- (= (point) (match-end 0))) ;looking-back is missing on XEmacs
- (save-excursion
- (insert "|"))))
+ (ruby-electric-insert arg
+ (and (ruby-electric-is-last-command-char-expandable-punct-p)
+ (ruby-electric-code-at-point-p)
+ (and (save-excursion (re-search-backward ruby-electric-expandable-bar nil t))
+ (= (point) (match-end 0))) ;looking-back is missing on XEmacs
+ (save-excursion
+ (insert "|")))))
(provide 'ruby-electric)