[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 18/77: Consolidate all kill features in easy-kill-thing
From: |
Leo Liu |
Subject: |
[elpa] 18/77: Consolidate all kill features in easy-kill-thing |
Date: |
Sat, 05 Apr 2014 04:08:13 +0000 |
leoliu pushed a commit to branch master
in repository elpa.
commit 39b37b7489d7b3d3583b375b0d293b3926910c58
Author: Leo Liu <address@hidden>
Date: Tue Oct 8 15:05:48 2013 +0800
Consolidate all kill features in easy-kill-thing
Rename easy-kill-enlarge to easy-kill-expand.
---
easy-kill.el | 111 ++++++++++++++++++++++++++++++---------------------------
1 files changed, 58 insertions(+), 53 deletions(-)
diff --git a/easy-kill.el b/easy-kill.el
index 0185374..c81eab0 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -48,8 +48,8 @@ CHAR is used immediately following `easy-kill' to select
THING."
"Build the keymap according to `easy-kill-alist'."
(let ((map (make-sparse-keymap)))
(define-key map "-" 'easy-kill-shrink)
- (define-key map "+" 'easy-kill-enlarge)
- (define-key map "=" 'easy-kill-enlarge)
+ (define-key map "+" 'easy-kill-expand)
+ (define-key map "=" 'easy-kill-expand)
(define-key map "\C-w" 'easy-kill-region)
(mapc (lambda (d)
(define-key map (number-to-string d) 'easy-kill-digit-argument))
@@ -105,75 +105,82 @@ candidate property instead."
(move-overlay o (point) (point))
(overlay-put o 'candidate beg)
(easy-kill-message-nolog "%s" beg))
- (move-overlay o (or beg (overlay-start o)) (or end (overlay-end 0)))))
+ (move-overlay o (or beg (overlay-start o)) (or end (overlay-end o)))))
(and interprogram-cut-function
(not (string= (easy-kill-candidate) ""))
(funcall interprogram-cut-function (easy-kill-candidate))))
-(defun easy-kill-enlarge (n)
- (interactive "p")
- (let ((thing (overlay-get easy-kill-candidate 'thing)))
- (when thing
- (if (get thing 'easy-kill-enlarge)
- (funcall (get thing 'easy-kill-enlarge) n)
- (let ((direction (if (minusp n) -1 +1))
- (start (overlay-start easy-kill-candidate))
- (end (overlay-end easy-kill-candidate)))
- (when thing
- (save-excursion
- (goto-char end)
- (with-demoted-errors
- (dotimes (_ (abs n))
- (forward-thing thing direction)
- (when (<= (point) start)
- (forward-thing thing 1)
- (return))))
- (when (/= end (point))
- (easy-kill-adjust-candidate thing nil (point))
- t))))))))
-
-(defun easy-kill-shrink (n)
- (interactive "p")
- (easy-kill-enlarge (- n)))
+(defun easy-kill-expand ()
+ (interactive)
+ (easy-kill-thing nil '+))
-(defun easy-kill-digit-argument (&optional n)
+(defun easy-kill-digit-argument (n)
(interactive
(list (- (logand (if (integerp last-command-event)
last-command-event
(get last-command-event 'ascii-character))
?\177)
?0)))
- (easy-kill-thing (overlay-get easy-kill-candidate 'thing) n))
+ (easy-kill-thing nil 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)
- (easy-kill-message-nolog "Empty region")
- (setq easy-kill-exit t)
- (kill-region beg end))))
+(defun easy-kill-shrink ()
+ (interactive)
+ (easy-kill-thing nil '-))
-(defun easy-kill-thing (thing &optional n inhibit-handler)
+;; helper for `easy-kill-thing'.
+(defun easy-kill-thing-forward (n)
+ (let ((thing (overlay-get easy-kill-candidate 'thing))
+ (direction (if (minusp n) -1 +1))
+ (start (overlay-start easy-kill-candidate))
+ (end (overlay-end easy-kill-candidate)))
+ (when thing
+ (save-excursion
+ (goto-char end)
+ (with-demoted-errors
+ (dotimes (_ (abs n))
+ (forward-thing thing direction)
+ (when (<= (point) start)
+ (forward-thing thing 1)
+ (return))))
+ (when (/= end (point))
+ (easy-kill-adjust-candidate thing nil (point))
+ t)))))
+
+(defun easy-kill-thing (&optional thing n nomsg inhibit-handler)
+ ;; N can be -, + and digits
(interactive
(list (cdr (assoc (car (last (listify-key-sequence
(single-key-description last-command-event))))
easy-kill-alist))
(prefix-numeric-value current-prefix-arg)))
- (let ((n (or n 1)))
+ (let ((thing (or thing (overlay-get easy-kill-candidate 'thing)))
+ (n (or n 1)))
(cond
((and (not inhibit-handler)
(intern-soft (format "easy-kill-on-%s" thing)))
(funcall (intern-soft (format "easy-kill-on-%s" thing)) n))
- ((eq thing (overlay-get easy-kill-candidate 'thing))
- (easy-kill-enlarge n))
+ ((or (eq thing (overlay-get easy-kill-candidate 'thing))
+ (memq n '(+ -)))
+ (easy-kill-thing-forward (pcase n
+ (`+ 1)
+ (`- -1)
+ (n n))))
(t (let ((bounds (bounds-of-thing-at-point thing)))
(if (not bounds)
- (when (called-interactively-p 'interact)
+ (unless nomsg
(easy-kill-message-nolog "No `%s'" thing))
(easy-kill-adjust-candidate thing (car bounds) (cdr bounds))
- (easy-kill-enlarge (1- n))))))))
+ (easy-kill-thing-forward (1- 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)
+ (easy-kill-message-nolog "Empty region")
+ (setq easy-kill-exit t)
+ (kill-region beg end))))
(defun easy-kill-activate-keymap ()
(let ((map (easy-kill-map)))
@@ -217,7 +224,7 @@ Temporally activate additional key bindings as follows:
o))
(setq deactivate-mark t)
(dolist (thing '(region url email line))
- (easy-kill-thing thing n)
+ (easy-kill-thing thing n 'nomsg)
(or (string= (easy-kill-candidate) "")
(return)))
(when (zerop (buffer-size))
@@ -238,20 +245,18 @@ file name party; positive, full path."
(let ((file (or buffer-file-name default-directory)))
(when file
(let* ((file (directory-file-name file))
- (text (cond
- ((zerop n) (file-name-nondirectory file))
- ((plusp n) file)
- (t (file-name-directory file)))))
+ (text (pcase n
+ (`- (file-name-directory file))
+ ((pred (eq 0)) (file-name-nondirectory file))
+ (_ file))))
(easy-kill-adjust-candidate 'buffer-file-name text)))))
-(put 'buffer-file-name 'easy-kill-enlarge 'easy-kill-on-buffer-file-name)
-
(defun easy-kill-on-url (&optional _n)
"Get url at point or from char properties.
Char properties `help-echo', `shr-url' and `w3m-href-anchor' are
inspected."
(if (bounds-of-thing-at-point 'url)
- (easy-kill-thing 'url nil t)
+ (easy-kill-thing 'url nil nil t)
(let ((get-url (lambda (text)
(when (stringp text)
(with-temp-buffer
- [elpa] 17/77: Fix error: (args-out-of-range 1009 1035), (continued)
- [elpa] 17/77: Fix error: (args-out-of-range 1009 1035), Leo Liu, 2014/04/05
- [elpa] 15/77: Some string and comment fixes, Leo Liu, 2014/04/05
- [elpa] 23/77: Use parse-partial-sexp in easy-kill-bounds-of-list, Leo Liu, 2014/04/05
- [elpa] 20/77: Replace `enlarge' with `expand' in strings and comments, Leo Liu, 2014/04/05
- [elpa] 19/77: Add lispy treatment for +/- on list and sexp, Leo Liu, 2014/04/05
- [elpa] 14/77: Doc fix and release v0.7.0, Leo Liu, 2014/04/05
- [elpa] 22/77: Handle the case when overlay has already been destroyed, Leo Liu, 2014/04/05
- [elpa] 25/77: Fix thinko in easy-kill-backward-down, Leo Liu, 2014/04/05
- [elpa] 21/77: New command easy-kill-mark-region, Leo Liu, 2014/04/05
- [elpa] 24/77: Improve list expand/shrink support in smie-based modes, Leo Liu, 2014/04/05
- [elpa] 18/77: Consolidate all kill features in easy-kill-thing,
Leo Liu <=
- [elpa] 26/77: Fix #2: just call kill-ring-save when region is active, Leo Liu, 2014/04/05
- [elpa] 27/77: Declare dependency on emacs 24, Leo Liu, 2014/04/05
- [elpa] 29/77: Merge pull request #4 from purcell/patch-1, Leo Liu, 2014/04/05
- [elpa] 31/77: Simplify the interactive form of easy-kill-thing, Leo Liu, 2014/04/05
- [elpa] 28/77: [remap kill-ring-save] should be a better key binding for this feature., Leo Liu, 2014/04/05
- [elpa] 35/77: Doc fix and release v0.8.0, Leo Liu, 2014/04/05
- [elpa] 36/77: New variable easy-kill-base-map for customising key bindings, Leo Liu, 2014/04/05
- [elpa] 33/77: Support append kill for append-next-kill and easy-kill, Leo Liu, 2014/04/05
- [elpa] 34/77: Better support for defining commands that exit easy-kill, Leo Liu, 2014/04/05
- [elpa] 30/77: Merge pull request #6 from knu/usage-remap, Leo Liu, 2014/04/05