leoliu pushed a commit to branch master in repository elpa. commit c00060c7c9c1c97d86bdeb4ed1cd97174a0500bb Author: Leo Liu <sdl....@gmail.com> Date: Mon Oct 7 15:40:58 2013 +0800
New command easy-kill-region to kill current selection --- easy-kill.el | 26 +++++++++++++++++--------- 1 files changed, 17 insertions(+), 9 deletions(-) diff --git a/easy-kill.el b/easy-kill.el index 1a30d10..98a284c 100644 --- a/easy-kill.el +++ b/easy-kill.el @@ -47,6 +47,7 @@ (define-key map "-" 'easy-kill-shrink) (define-key map "+" 'easy-kill-enlarge) (define-key map "=" 'easy-kill-enlarge) + (define-key map "\C-w" 'easy-kill-region) (mapc (lambda (d) (define-key map (number-to-string d) 'easy-kill-digit-argument)) (number-sequence 0 9)) @@ -72,6 +73,9 @@ (error "`string-match' failed in `easy-kill-strip'"))) (t s))) +(defvar easy-kill-exit nil + "If non-nil tells `set-temporary-overlay-map' to exit.") + (defvar easy-kill-candidate nil) (defun easy-kill-candidate () @@ -136,6 +140,16 @@ candidate property instead." ?0))) (easy-kill-thing (overlay-get easy-kill-candidate 'thing) n)) +(defun easy-kill-region () + "Kill current selection and exit." + (interactive) + (let ((beg (overlay-start easy-kill-candidate)) + (end (overlay-end easy-kill-candidate))) + (if (/= beg end) + (kill-region beg end) + (easy-kill-message-nolog "Region empty"))) + (setq easy-kill-exit t)) + (defun easy-kill-thing (thing &optional n inhibit-handler) (interactive (list (cdr (assoc (car (last (listify-key-sequence @@ -163,15 +177,9 @@ candidate property instead." (lambda () ;; When any error happens the keymap is active forever. (with-demoted-errors - (or (let ((cmd (lookup-key map (this-command-keys)))) - (eq this-command - (if (and (numberp cmd) - universal-argument-num-events - (> (length (this-command-keys)) - universal-argument-num-events)) - (lookup-key map (substring (this-command-keys) - universal-argument-num-events)) - cmd))) + (or (and (not (prog1 easy-kill-exit + (setq easy-kill-exit nil))) + (eq this-command (lookup-key map (this-command-keys)))) (when easy-kill-candidate ;; Do not modify the clipboard here because it will ;; intercept pasting from other programs and