ruby-changes:27367
From: knu <ko1@a...>
Date: Sat, 23 Feb 2013 12:55:53 +0900 (JST)
Subject: [ruby-changes:27367] knu:r39419 (trunk): misc/ruby-electric.el: Avoid electric insertion in some cases.
knu 2013-02-23 12:55:39 +0900 (Sat, 23 Feb 2013) New Revision: 39419 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39419 Log: 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. Modified files: trunk/ChangeLog trunk/misc/ruby-electric.el Index: ChangeLog =================================================================== --- ChangeLog (revision 39418) +++ ChangeLog (revision 39419) @@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Feb 23 12:26:43 2013 Akinori MUSHA <knu@i...> + + * 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@z...> * array.c: Document #<=> return values and formatting Index: misc/ruby-electric.el =================================================================== --- misc/ruby-electric.el (revision 39418) +++ misc/ruby-electric.el (revision 39419) @@ -159,47 +159,63 @@ strings. Note that you must have Font Lo https://github.com/ruby/ruby/blob/trunk/misc/ruby-electric.el#L159 (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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/