[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 38/77: Fix #3: Add command easy-mark for marking
From: |
Leo Liu |
Subject: |
[elpa] 38/77: Fix #3: Add command easy-mark for marking |
Date: |
Sat, 05 Apr 2014 04:08:18 +0000 |
leoliu pushed a commit to branch master
in repository elpa.
commit 54fdc36479be86e5cba4dc60577ad44a5f92541a
Author: Leo Liu <address@hidden>
Date: Fri Oct 11 12:44:48 2013 +0800
Fix #3: Add command easy-mark for marking
---
easy-kill.el | 94 +++++++++++++++++++++++++++++++++++++--------------------
1 files changed, 61 insertions(+), 33 deletions(-)
diff --git a/easy-kill.el b/easy-kill.el
index 9b8a658..3f22f17 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -45,7 +45,7 @@ CHAR is used immediately following `easy-kill' to select
THING."
:type '(repeat (cons character symbol))
:group 'killing)
-(defface easy-kill-face '((t (:inherit 'secondary-selection)))
+(defface easy-kill-selection '((t (:inherit 'secondary-selection)))
"Faced used to highlight kill candidate."
:group 'killing)
@@ -85,8 +85,28 @@ CHAR is used immediately following `easy-kill' to select
THING."
(t "")))
(defvar easy-kill-candidate nil)
-
(defvar easy-kill-append nil)
+(defvar easy-kill-mark nil)
+
+(defun easy-kill-init-candidate (n)
+ (let ((o (make-overlay (point) (point))))
+ (unless easy-kill-mark
+ (overlay-put o 'face 'easy-kill-selection))
+ (overlay-put o 'origin (point))
+ ;; Use higher priority to avoid shadowing by, for example,
+ ;; `hl-line-mode'.
+ (overlay-put o 'priority 999)
+ (when easy-kill-mark
+ (let ((i (make-overlay (point) (point))))
+ (overlay-put i 'priority (1+ (overlay-get o 'priority)))
+ (overlay-put i 'after-string (propertize "_" 'face 'error))
+ (overlay-put o 'origin-indicator i)))
+ (setq easy-kill-candidate o)
+ (dolist (thing '(url email line))
+ (easy-kill-thing thing n 'nomsg)
+ (or (string= (easy-kill-candidate) "")
+ (return)))
+ o))
(defun easy-kill-candidate ()
"Get the kill candidate as a string.
@@ -105,20 +125,23 @@ Otherwise, it is the value of the overlay's candidate
property."
"Adjust kill candidate to THING, BEG, END.
If BEG is a string, shrink the overlay to zero length and set its
candidate property instead."
- (let ((o easy-kill-candidate))
+ (let* ((o easy-kill-candidate)
+ (beg (or beg (overlay-start o)))
+ (end (or end (overlay-end o))))
(overlay-put o 'thing thing)
(if (stringp beg)
(progn
(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 o)))))
- (and interprogram-cut-function
- (not (string= (easy-kill-candidate) ""))
- (funcall interprogram-cut-function (easy-kill-candidate))))
+ (move-overlay o beg end))
+ (cond (easy-kill-mark (easy-kill-mark-region))
+ ((and interprogram-cut-function
+ (not (string= (easy-kill-candidate) "")))
+ (funcall interprogram-cut-function (easy-kill-candidate))))))
(defun easy-kill-save-candidate ()
- (unless (string= (easy-kill-candidate) "")
+ (unless (or easy-kill-mark (string= (easy-kill-candidate) ""))
;; Do not modify the clipboard here because this may be called in
;; `pre-command-hook' and will confuse `yank' if it is the next
;; command. Also `easy-kill-adjust-candidate' already did the
@@ -134,8 +157,10 @@ candidate property instead."
(defun easy-kill-destroy-candidate ()
(let ((hook (make-symbol "easy-kill-destroy-candidate")))
(fset hook (lambda ()
- (and easy-kill-candidate
- (delete-overlay easy-kill-candidate))
+ (when easy-kill-candidate
+ (let ((i (overlay-get easy-kill-candidate
'origin-indicator)))
+ (and (overlayp i) (delete-overlay i)))
+ (delete-overlay easy-kill-candidate))
(setq easy-kill-candidate nil)
(remove-hook 'post-command-hook hook)))
(add-hook 'post-command-hook hook)))
@@ -164,16 +189,17 @@ candidate property instead."
(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))
+ (let ((new-end (save-excursion
+ (goto-char end)
+ (with-demoted-errors
+ (dotimes (_ (abs n))
+ (forward-thing thing direction)
+ (when (<= (point) start)
+ (forward-thing thing 1)
+ (return)))
+ (point)))))
+ (when (/= end new-end)
+ (easy-kill-adjust-candidate thing nil new-end)
t)))))
(defun easy-kill-thing (&optional thing n nomsg inhibit-handler)
@@ -183,6 +209,8 @@ candidate property instead."
(prefix-numeric-value current-prefix-arg)))
(let ((thing (or thing (overlay-get easy-kill-candidate 'thing)))
(n (or n 1)))
+ (when easy-kill-mark
+ (goto-char (overlay-get easy-kill-candidate 'origin)))
(cond
((and (not inhibit-handler)
(fboundp (intern-soft (format "easy-kill-on-%s" thing))))
@@ -198,7 +226,9 @@ candidate property instead."
(unless nomsg
(easy-kill-message-nolog "No `%s'" thing))
(easy-kill-adjust-candidate thing (car bounds) (cdr bounds))
- (easy-kill-thing-forward (1- n))))))))
+ (easy-kill-thing-forward (1- n))))))
+ (when easy-kill-mark
+ (easy-kill-adjust-candidate thing))))
(put 'easy-kill-region 'easy-kill-exit t)
(defun easy-kill-region ()
@@ -242,7 +272,8 @@ candidate property instead."
(easy-kill-destroy-candidate)
(unless (and (symbolp this-command)
(get this-command 'easy-kill-exit))
- (easy-kill-save-candidate)))))))))
+ (easy-kill-save-candidate))
+ (setq easy-kill-mark nil))))))))
;;;###autoload
(defun easy-kill (&optional n)
@@ -260,21 +291,18 @@ Temporally activate additional key bindings as follows:
(if (use-region-p)
(kill-ring-save (region-beginning) (region-end))
(setq easy-kill-append (eq last-command 'kill-region))
- (setq easy-kill-candidate
- (let ((o (make-overlay (point) (point))))
- (overlay-put o 'face 'easy-kill-face)
- ;; Use higher priority to avoid shadowing by, for example,
- ;; `hl-line-mode'.
- (overlay-put o 'priority 999)
- o))
- (dolist (thing '(url email line))
- (easy-kill-thing thing n 'nomsg)
- (or (string= (easy-kill-candidate) "")
- (return)))
+ (easy-kill-init-candidate n)
(when (zerop (buffer-size))
(easy-kill-message-nolog "Warn: `easy-kill' activated in empty buffer"))
(easy-kill-activate-keymap)))
+;;;###autoload
+(defun easy-mark (&optional n)
+ (interactive "p")
+ (setq easy-kill-mark t)
+ (easy-kill-init-candidate n)
+ (easy-kill-activate-keymap))
+
;;; Extended things
(defun easy-kill-on-buffer-file-name (n)
- [elpa] 29/77: Merge pull request #4 from purcell/patch-1, (continued)
- [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
- [elpa] 32/77: Improve easy-kill-bounds-of-list, Leo Liu, 2014/04/05
- [elpa] 37/77: Make easy-kill-backward-up work better when in strings, Leo Liu, 2014/04/05
- [elpa] 38/77: Fix #3: Add command easy-mark for marking,
Leo Liu <=
- [elpa] 39/77: Fix doc and buglets in last change, Leo Liu, 2014/04/05
- [elpa] 40/77: Some improvements based on comments in #3, Leo Liu, 2014/04/05
- [elpa] 42/77: Must reference the actual object in easy-kill-candidate, Leo Liu, 2014/04/05
- [elpa] 43/77: Add new command easy-mark-sexp, Leo Liu, 2014/04/05
- [elpa] 41/77: Tell easy-kill-append to deactivate-mark, Leo Liu, 2014/04/05
- [elpa] 44/77: Fix #7: Add new command easy-kill-abort for key C-g, Leo Liu, 2014/04/05
- [elpa] 45/77: Better origin indicator by easy-kill-indicate-origin, Leo Liu, 2014/04/05
- [elpa] 46/77: Teach easy-kill-abort to deactivate mark immediately, Leo Liu, 2014/04/05
- [elpa] 47/77: Doc fix and small tweaks, Leo Liu, 2014/04/05
- [elpa] 49/77: Work with `sexp' and `list' in nxml mode, Leo Liu, 2014/04/05