summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-18 17:38:04 +0000
committerknu <knu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-05-18 17:38:04 +0000
commit616084fd976a4e083722e32818f95c304903534f (patch)
treed6e6067074bf65c34eb876c078cd7ca903552ac8 /misc
parent30034b5536207c5a3fbc5ef8b8670cc74b96f382 (diff)
* misc/ruby-electric.el (ruby-electric-delete-backward-char):
Introduce electric DEL that deletes what the previous electric command has input. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'misc')
-rw-r--r--misc/ruby-electric.el31
1 files changed, 30 insertions, 1 deletions
diff --git a/misc/ruby-electric.el b/misc/ruby-electric.el
index ce2ac15ef7..2972651691 100644
--- a/misc/ruby-electric.el
+++ b/misc/ruby-electric.el
@@ -124,7 +124,8 @@ strings. Note that you must have Font Lock enabled."
(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-hash))
+ (define-key ruby-mode-map "#" 'ruby-electric-hash)
+ (define-key ruby-mode-map (kbd "DEL") 'ruby-electric-delete-backward-char))
(defun ruby-electric-space (arg)
(interactive "P")
@@ -184,6 +185,11 @@ strings. Note that you must have Font Lock enabled."
(setq this-command 'cua-replace-region)
(cua-replace-region))
+(defun ruby-electric-cua-delete-region()
+ (setq this-original-command 'delete-backward-char)
+ (setq this-command 'cua-delete-region)
+ (cua-delete-region))
+
(defmacro ruby-electric-insert (arg &rest body)
`(cond ((ruby-electric-cua-replace-region-p)
(ruby-electric-cua-replace-region))
@@ -312,5 +318,28 @@ strings. Note that you must have Font Lock enabled."
(save-excursion
(insert "|")))))
+(defun ruby-electric-delete-backward-char(arg)
+ (interactive "P")
+ (if (ruby-electric-cua-replace-region-p)
+ (ruby-electric-cua-delete-region)
+ (cond ((memq last-command '(ruby-electric-matching-char
+ ruby-electric-bar))
+ (delete-char 1))
+ ((eq last-command 'ruby-electric-curlies)
+ (cond ((eolp)
+ (cond ((char-equal (preceding-char) ?\s)
+ (setq this-command last-command))
+ ((char-equal (preceding-char) ?{)
+ (and (looking-at "[ \t\n]*}")
+ (delete-char (- (match-end 0) (match-beginning 0)))))))
+ ((char-equal (following-char) ?\s)
+ (setq this-command last-command)
+ (delete-char 1))
+ ((char-equal (following-char) ?})
+ (delete-char 1))))
+ ((eq last-command 'ruby-electric-hash)
+ (and (char-equal (preceding-char) ?{)
+ (delete-char 1))))
+ (delete-backward-char 1)))
(provide 'ruby-electric)