[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 06/77: Various bug fixes and improvements
From: |
Leo Liu |
Subject: |
[elpa] 06/77: Various bug fixes and improvements |
Date: |
Sat, 05 Apr 2014 04:08:10 +0000 |
leoliu pushed a commit to branch master
in repository elpa.
commit 77b9e8fa77581672b2c21eb698f6b7abc58084b0
Author: Leo Liu <address@hidden>
Date: Sun Oct 6 17:17:39 2013 +0800
Various bug fixes and improvements
---
easy-kill.el | 120 +++++++++++++++++++++++++++++++++-------------------------
1 files changed, 68 insertions(+), 52 deletions(-)
diff --git a/easy-kill.el b/easy-kill.el
index a4922c2..cf853d2 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -42,6 +42,19 @@
:type '(repeat (cons character symbol))
:group 'killing)
+(defun easy-kill-map ()
+ (let ((map (make-sparse-keymap)))
+ (define-key map "-" 'easy-kill-backward)
+ (define-key map "+" 'easy-kill-forward)
+ (mapc (lambda (d)
+ (define-key map (number-to-string d) 'easy-kill-digit-argument))
+ (number-sequence 0 9))
+ (mapc (lambda (c)
+ ;; (define-key map (vector meta-prefix-char c) 'easy-kill-select)
+ (define-key map (char-to-string c) 'easy-kill-thing))
+ (mapcar 'car easy-kill-alist))
+ map))
+
(defface easy-kill-face '((t (:inherit 'secondary-selection)))
"Faced used to highlight kill candidate."
:group 'killing)
@@ -51,35 +64,25 @@
(let (message-log-max)
(apply 'message format-string args)))
+(defun easy-kill-strip-trailing (s)
+ (if (string-match "[ \t\f\r\n]*\\'" s)
+ (substring s 0 (match-beginning 0))
+ (error "`string-match' failed in `easy-kill-strip'")))
+
(defvar easy-kill-candidate nil)
(defun easy-kill-candidate ()
- (when (overlayp easy-kill-candidate)
- (if (eq (overlay-start easy-kill-candidate)
- (overlay-end easy-kill-candidate))
- (overlay-get easy-kill-candidate 'candidate)
- (buffer-substring (overlay-start easy-kill-candidate)
- (overlay-end easy-kill-candidate)))))
+ (easy-kill-strip-trailing
+ (if (/= (overlay-start easy-kill-candidate)
+ (overlay-end easy-kill-candidate))
+ (buffer-substring (overlay-start easy-kill-candidate)
+ (overlay-end easy-kill-candidate))
+ (overlay-get easy-kill-candidate 'candidate))))
(defun easy-kill-select-text ()
"Make current kill candidate available to other programs."
- (let ((candidate (easy-kill-candidate)))
- (and candidate
- interprogram-cut-function
- (funcall interprogram-cut-function candidate))))
-
-(defun easy-kill-map ()
- (let ((map (make-sparse-keymap)))
- (define-key map "-" 'easy-kill-backward)
- (define-key map "+" 'easy-kill-forward)
- (mapc (lambda (d)
- (define-key map (number-to-string d) 'easy-kill-digit-argument))
- (number-sequence 0 9))
- (mapc (lambda (c)
- ;; (define-key map (vector meta-prefix-char c) 'easy-kill-select)
- (define-key map (char-to-string c) 'easy-kill-select))
- (mapcar 'car easy-kill-alist))
- map))
+ (and interprogram-cut-function
+ (funcall interprogram-cut-function (easy-kill-candidate))))
(defun easy-kill-forward (n)
(interactive "p")
@@ -105,31 +108,40 @@
(interactive "p")
(easy-kill-forward (- n)))
+(defun easy-kill-digit-argument (&optional 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))
+
(defun easy-kill-thing (thing &optional n)
+ (interactive
+ (list (cdr (assoc (car (last (listify-key-sequence
+ (single-key-description last-command-event))))
+ easy-kill-alist))
+ (prefix-numeric-value current-prefix-arg)))
;; Return non-nil if succeed
- (when (and thing
- (let ((n (or n 1)))
- (cond
- ((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-forward n))
- (t (let ((bounds (bounds-of-thing-at-point thing)))
- (when bounds
- (move-overlay easy-kill-candidate (car bounds) (cdr
bounds))
- (overlay-put easy-kill-candidate 'thing thing)
- (easy-kill-forward (1- n))
- t))))))
- (easy-kill-select-text)
- t))
-
-(defun easy-kill-select (n)
- (interactive "p")
- (let ((thing (cdr (assoc (car (last (listify-key-sequence
- (single-key-description
last-command-event))))
- easy-kill-alist))))
- (or (easy-kill-thing thing n)
- (easy-kill-message-nolog "No `%s' at point." thing))))
+ (if (and thing
+ (let ((n (or n 1)))
+ (cond
+ ((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-forward n))
+ (t (let ((bounds (bounds-of-thing-at-point thing)))
+ (when bounds
+ (move-overlay easy-kill-candidate (car bounds) (cdr
bounds))
+ (overlay-put easy-kill-candidate 'thing thing)
+ (easy-kill-forward (1- n))
+ t))))))
+ (progn
+ (easy-kill-select-text)
+ t)
+ (ignore (when (called-interactively-p 'interact)
+ (easy-kill-message-nolog "No `%s'" thing)))))
(defun easy-kill-activate-keymap ()
(let ((map (easy-kill-map)))
@@ -153,8 +165,7 @@
;; `easy-kill-remember' already did the work.
(let ((interprogram-cut-function nil)
(interprogram-paste-function nil))
- (kill-ring-save (overlay-start easy-kill-candidate)
- (overlay-end easy-kill-candidate)))
+ (kill-new (easy-kill-candidate)))
(delete-overlay easy-kill-candidate)
(setq easy-kill-candidate nil)
nil)))))))
@@ -178,12 +189,17 @@
(put 'region 'bounds-of-thing-at-point
(lambda () (cons (region-beginning) (region-end))))
-(defun easy-kill-on-buffer-file-name (_n)
- (when buffer-file-name
+(defun easy-kill-on-buffer-file-name (n)
+ (when (or buffer-file-name default-directory)
(move-overlay easy-kill-candidate (point) (point))
- (overlay-put easy-kill-candidate 'candidate buffer-file-name)
(overlay-put easy-kill-candidate 'thing 'buffer-file-name)
- (easy-kill-message-nolog "%s" buffer-file-name)
+ (let* ((file (or buffer-file-name default-directory))
+ (text (and file (if (zerop n)
+ (file-name-nondirectory
+ (directory-file-name file))
+ (directory-file-name file)))))
+ (overlay-put easy-kill-candidate 'candidate text)
+ (easy-kill-message-nolog "%s" text))
t))
(provide 'easy-kill)
- [elpa] branch master updated (769f2f2 -> 0a73626), Leo Liu, 2014/04/05
- [elpa] 03/77: Fix error: wrong-type-argument number-or-marker-p nil, Leo Liu, 2014/04/05
- [elpa] 02/77: Fix error when interprogram-cut-function unset, Leo Liu, 2014/04/05
- [elpa] 05/77: Call interprogram-cut-function in easy-kill-forward, Leo Liu, 2014/04/05
- [elpa] 01/77: Initial commit, Leo Liu, 2014/04/05
- [elpa] 07/77: Rename easy-kill-forward/backward to easy-kill-enlarge/shrink, Leo Liu, 2014/04/05
- [elpa] 08/77: Give overlay by easy-kill-candidate higher priority, Leo Liu, 2014/04/05
- [elpa] 06/77: Various bug fixes and improvements,
Leo Liu <=
- [elpa] 09/77: Restore the ability to inspect char properties for URLs, Leo Liu, 2014/04/05
- [elpa] 04/77: Use overlay for storing kill candidate and change +/-, Leo Liu, 2014/04/05
- [elpa] 11/77: Minor tweaks to easy-kill-on-url, Leo Liu, 2014/04/05
- [elpa] 12/77: Tweak the definition of thing `region', Leo Liu, 2014/04/05
- [elpa] 13/77: New command easy-kill-region to kill current selection, Leo Liu, 2014/04/05
- [elpa] 10/77: New function easy-kill-adjust-candidate and doc fix, Leo Liu, 2014/04/05
- [elpa] 16/77: Make function easy-kill-candidate always return string, Leo Liu, 2014/04/05
- [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