leoliu pushed a commit to branch master
in repository elpa.
commit acfff098ccfb5df420190b1ba56083902659b5dd
Author: Leo Liu <[email protected]>
Date: Fri Apr 11 13:28:15 2014 +0800
New format of easy-kill-alist to support append separator
---
README.rst | 6 +++++-
easy-kill.el | 50 +++++++++++++++++++++++++++++++++++++-------------
2 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/README.rst b/README.rst
index 548b074..3d21e02 100644
--- a/README.rst
+++ b/README.rst
@@ -90,7 +90,11 @@ NEWS
+++++
#. Mouse over the selection now shows description.
-#. Echo js2 node name
+#. Echo js2 node name.
+#. Append now uses sensible separator (customisable via
+ ``easy-kill-alist``).
+#. The format of easy-kill-alist has changed. The old ``(CHAR .
+ THING)`` format is still supported but may be removed in future.
Bugs
~~~~
diff --git a/easy-kill.el b/easy-kill.el
index 6823d6a..c6989ab 100644
--- a/easy-kill.el
+++ b/easy-kill.el
@@ -71,16 +71,22 @@
(push alist emulation-mode-map-alists))))))
(defcustom easy-kill-alist
- '((?w . word)
- (?s . sexp)
- (?l . list)
- (?f . filename)
- (?d . defun)
- (?e . line)
- (?b . buffer-file-name))
- "A list of (CHAR . THING).
-CHAR is used immediately following `easy-kill' to select THING."
- :type '(repeat (cons character symbol))
+ '((?w word " ")
+ (?s sexp "\n")
+ (?l list "\n")
+ (?f filename "\n")
+ (?d defun "\n\n")
+ (?e line "\n")
+ (?b buffer-file-name))
+ "A list of (CHAR THING APPEND).
+CHAR is used immediately following `easy-kill' to select THING.
+APPEND is optional and if non-nil specifies the separator (a
+string) for appending current selection to previous kill.
+
+Note: each element can also be (CHAR . THING) but this is
+deprecated."
+ :type '(repeat (list character symbol
+ (choice string (const :tag "None" nil))))
:group 'killing)
(defcustom easy-kill-try-things '(url email line)
@@ -134,6 +140,14 @@ Do nothing if `easy-kill-inhibit-message' is non-nil."
(let (message-log-max)
(apply 'message format-string args))))
+(defun easy-kill-trim (s &optional how)
+ (let ((wchars "[ \t\n\r\f\v]*"))
+ (pcase how
+ (`left (and (string-match (concat "\\`" wchars) s)
+ (substring s (match-end 0))))
+ (`right (substring s 0 (string-match-p (concat wchars "\\'") s)))
+ (_ (easy-kill-trim (easy-kill-trim s 'left) 'right)))))
+
(defun easy-kill-interprogram-cut (text)
"Make non-empty TEXT available to other programs."
(cl-check-type text string)
@@ -260,8 +274,16 @@ candidate property instead."
;; `easy-kill-adjust-candidate' already did that.
(let ((interprogram-cut-function nil)
(interprogram-paste-function nil))
- (kill-new (if easy-kill-append
- (concat (car kill-ring) (easy-kill-candidate))
+ (kill-new (if (and easy-kill-append kill-ring)
+ (cl-labels ((join (x sep y)
+ (if sep (concat (easy-kill-trim x 'right)
+ sep
+ (easy-kill-trim y 'left))
+ (concat x y))))
+ (join (car kill-ring)
+ (nth 2 (cl-rassoc (easy-kill-get thing)
+ easy-kill-alist :key #'car))
+ (easy-kill-candidate)))
(easy-kill-candidate))
easy-kill-append))
t))
@@ -319,7 +341,9 @@ candidate property instead."
(defun easy-kill-thing (&optional thing n inhibit-handler)
;; N can be -, + and digits
(interactive
- (list (cdr (assq last-command-event easy-kill-alist))
+ (list (pcase (assq last-command-event easy-kill-alist)
+ (`(,_ ,th . ,_) th)
+ (`(,_ . ,th) th))
(prefix-numeric-value current-prefix-arg)))
(let ((thing (or thing (easy-kill-get thing)))
(n (or n 1)))