From b14c2d40d25b98e5f5b2959884e3f582cd745ca4 Mon Sep 17 00:00:00 2001 From: Mike Panitz Date: Sat, 24 Nov 2018 01:14:35 -0800 Subject: [PATCH 1/3] Tentative change: [,] adjust left edge for 'word' --- easy-kill.el | 125 ++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 93 insertions(+), 32 deletions(-) diff --git a/easy-kill.el b/easy-kill.el index c31af0d..c3a8850 100644 --- a/easy-kill.el +++ b/easy-kill.el @@ -40,6 +40,13 @@ ;;; Code: +;;; TODO: +;;;;;;; Add optional param to e-k-t-f to select the edge +;;;;;;;; Defaults to 'forward' +;;;;;;; how to only move 1 space forwards/back +;;;;;;; how to toggle between left edge and right edge? + + (require 'cl-lib) (require 'thingatpt) (require 'gv nil t) ;For `defsetf'. @@ -123,6 +130,8 @@ deprecated." (let ((map (make-sparse-keymap))) (define-key map "-" 'easy-kill-shrink) (define-key map "+" 'easy-kill-expand) + (define-key map "[" 'easy-kill-shrink-backward-edge) + (define-key map "]" 'easy-kill-expand-backward-edge) (define-key map "=" 'easy-kill-expand) (define-key map " " 'easy-kill-cycle) (define-key map "@" 'easy-kill-append) @@ -177,6 +186,7 @@ The value is the function's symbol if non-nil." (symbol (and (fboundp name) name)))) (defun easy-kill-pair-to-list (pair) + (message "easy-kill-pair-to-list\tpair=%s" pair) (pcase pair (`nil nil) (`(,beg . ,end) (list beg end)) @@ -341,13 +351,19 @@ If BEG is a string, shrink the overlay to zero length and set its candidate property instead." (setf (easy-kill-get thing) thing) (cond ((stringp beg) + (message "e-k-adjust-candidate [string]\tbeg=%s" beg) (setf (easy-kill-get bounds) (cons (point) (point))) (setf (easy-kill-get candidate) beg) (let ((easy-kill-inhibit-message nil)) (easy-kill-echo "%s" beg))) (t + (message "e-k-adjust-candidate t\tbeg=%s\tend=%s\texp=%s" beg end + (cons (or beg (easy-kill-get start)) + (or end (easy-kill-get end))) ) (setf (easy-kill-get bounds) (cons (or beg (easy-kill-get start)) (or end (easy-kill-get end)))))) + (message "\tBounds? = %s" (easy-kill-get bounds) ) + (message "\tMark? = %s" (easy-kill-get mark)) (cond ((easy-kill-get mark) (easy-kill-mark-region) (easy-kill-indicate-origin)) @@ -364,10 +380,10 @@ candidate property instead." (interprogram-paste-function nil)) (kill-new (if (and (easy-kill-get 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)))) + (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)) @@ -393,6 +409,10 @@ candidate property instead." (interactive) (easy-kill-thing nil '+)) +(defun easy-kill-expand-backward-edge () + (interactive) + (easy-kill-thing nil '+ nil 'backward)) + (defun easy-kill-cycle (&optional thing) "Cycle through things in `easy-kill-alist'. A thing is opted out of cycling if in `easy-kill-cycle-ignored'." @@ -433,6 +453,10 @@ expansion." (interactive) (easy-kill-thing nil '-)) +(defun easy-kill-shrink-backward-edge () + (interactive) + (easy-kill-thing nil '- nil 'backward)) + (defun easy-kill-thing-handler (base mode) "Get the handler for MODE or nil if none is defined. For example, if BASE is \"easy-kill-on-list\" and MODE is @@ -454,11 +478,12 @@ checked." ;; Work around a bug (fixed in 25.1, commit: 7a94f28a) in ;; `thing-at-point-bounds-of-url-at-point' that could return a ;; boundary not containing current point. + (message "e-k-bounds-of-thing-at-point\tthing=%s\tpoint=%s" thing (point)) (cl-flet ((chk (bound) - (pcase-let ((`(,b . ,e) bound)) - (and b e - (<= b (point)) (<= (point) e) - (cons b e))))) + (pcase-let ((`(,b . ,e) bound)) + (and b e + (<= b (point)) (<= (point) e) + (cons b e))))) (pcase (easy-kill-thing-handler (format "easy-kill-bounds-of-%s-at-point" thing) major-mode) @@ -467,6 +492,7 @@ checked." (defun easy-kill-thing-forward-1 (thing &optional n) "Easy Kill wrapper for `forward-thing'." + (message "e-k-thing-forward-1 thing=%s n=%s" thing n) (pcase (easy-kill-thing-handler (format "easy-kill-thing-forward-%s" thing) major-mode) @@ -474,38 +500,71 @@ checked." (_ (forward-thing thing n)))) ;; Helper for `easy-kill-thing'. -(defun easy-kill-thing-forward (n) + +;; which-edge: +;; nil or 'forward is the forward edge +;; (the right-most one on RTL text) +;; 'backward is the backward edge +;; (the left-most one on RTL text) +;; forward/backward is defined according to https://www.gnu.org/software/emacs/manual/html_node/emacs/Bidirectional-Editing.html +;; +(defun easy-kill-thing-forward (n &optional which-edge) + (message "In easy-kill-thing-forward\tn=%s\twhich-edge=%s\tpoint=%s" n which-edge (point)) (when (and (easy-kill-get thing) (/= n 0)) (let* ((step (if (cl-minusp n) -1 +1)) (thing (easy-kill-get thing)) (bounds1 (or (easy-kill-pair-to-list (easy-kill-bounds-of-thing-at-point thing)) (list (point) (point)))) + (origin-thing-start (car bounds1)) + (origin-thing-end (car (last bounds1))) (start (easy-kill-get start)) (end (easy-kill-get end)) - (front (or (car (cl-set-difference (list end start) bounds1)) - (pcase step - (`-1 start) - (`1 end)))) - (new-front (save-excursion - (goto-char front) - (with-demoted-errors - (dotimes (_ (abs n)) - (easy-kill-thing-forward-1 thing step))) - (point)))) + (front (cond + ( (eq which-edge 'backward) + (message "\tBackward edge!") + start) + ( t + (message "\tForward edges") + end))) + (UNUSED (progn + (message "\tstart=%s\tend=%s\tbounds1=%s\tfront=%s\tpoint=%s" start end bounds1 front (point) ) + (message "\torigin-thing-start=%s\torigin-thing-end=%s" origin-thing-start origin-thing-end) + ) ) + (new-front (save-excursion + (goto-char front) + (message "\tstarting point to %s" (point)) + (with-demoted-errors + (dotimes (_ (abs n)) + (easy-kill-thing-forward-1 thing step))) + (message "\tmoved point to %s" (point)) + (point)))) + (message "\tbefore adjust candidate\tstart=%s\tend=%s\tfront = %s new-front=%s" start end front new-front) + ;; (message "\tOLD list=%s" (sort (cons new-front bounds1) #'< )) + (message "(max new-front origin-thing-end )=%s" (max new-front origin-thing-end )) (pcase (and (/= front new-front) - (sort (cons new-front bounds1) #'<)) - (`(,start ,_ ,end) - (easy-kill-adjust-candidate thing start end) - t))))) - -(defun easy-kill-thing (&optional thing n inhibit-handler) + (cond + ( (eq which-edge 'backward) + (if (cl-minusp n) + (list new-front end)) + (list (min new-front origin-thing-start) end )) + ( (eq which-edge nil) + (if (cl-minusp n) + (list start (max new-front origin-thing-end )) + (list start new-front))))) + (`(,start ,end) + (message "about to adjust candidate\tstart=%s\tend=%s" start end) + (easy-kill-adjust-candidate thing start end) + t) ) ) ) ) + +(defun easy-kill-thing (&optional thing n inhibit-handler which-edge) ;; N can be -, + and digits (interactive (list (pcase (assq last-command-event easy-kill-alist) (`(,_ ,th . ,_) th) (`(,_ . ,th) th)) (prefix-numeric-value current-prefix-arg))) + (message "======================== easy-kill-thing =======================") (let* ((thing (or thing (easy-kill-get thing))) (n (or n 1)) (handler (and (not inhibit-handler) @@ -521,13 +580,15 @@ checked." (easy-kill-thing-forward (pcase n (`+ 1) (`- -1) - (_ n)))) + (_ n)) + which-edge + )) (t (pcase (easy-kill-bounds-of-thing-at-point thing) (`nil (easy-kill-echo "No `%s'" thing)) (`(,start . ,end) (easy-kill-adjust-candidate thing start end) (unless (zerop n) - (easy-kill-thing-forward (1- n))))))) + (easy-kill-thing-forward (1- n) which-edge)))))) (when (easy-kill-get mark) (easy-kill-adjust-candidate (easy-kill-get thing))))) @@ -690,11 +751,11 @@ inspected." (if (or (easy-kill-get mark) (easy-kill-bounds-of-thing-at-point 'url)) (easy-kill-thing 'url nil t) (cl-labels ((get-url (text) - (when (stringp text) - (with-temp-buffer - (insert text) - (pcase (easy-kill-bounds-of-thing-at-point 'url) - (`(,beg . ,end) (buffer-substring beg end))))))) + (when (stringp text) + (with-temp-buffer + (insert text) + (pcase (easy-kill-bounds-of-thing-at-point 'url) + (`(,beg . ,end) (buffer-substring beg end))))))) (cl-dolist (p '(help-echo shr-url w3m-href-anchor)) (pcase (get-char-property-and-overlay (point) p) (`(,text . ,ov) From bf44ddbcdb429e7188440d36d9ad4614ae5b4f8f Mon Sep 17 00:00:00 2001 From: Mike Panitz Date: Sun, 16 Dec 2018 23:55:39 -0800 Subject: [PATCH 2/3] Removed 'message' lines that were used for printf-style debugging --- easy-kill.el | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/easy-kill.el b/easy-kill.el index c3a8850..2612e65 100644 --- a/easy-kill.el +++ b/easy-kill.el @@ -44,7 +44,6 @@ ;;;;;;; Add optional param to e-k-t-f to select the edge ;;;;;;;; Defaults to 'forward' ;;;;;;; how to only move 1 space forwards/back -;;;;;;; how to toggle between left edge and right edge? (require 'cl-lib) @@ -186,7 +185,6 @@ The value is the function's symbol if non-nil." (symbol (and (fboundp name) name)))) (defun easy-kill-pair-to-list (pair) - (message "easy-kill-pair-to-list\tpair=%s" pair) (pcase pair (`nil nil) (`(,beg . ,end) (list beg end)) @@ -351,19 +349,13 @@ If BEG is a string, shrink the overlay to zero length and set its candidate property instead." (setf (easy-kill-get thing) thing) (cond ((stringp beg) - (message "e-k-adjust-candidate [string]\tbeg=%s" beg) (setf (easy-kill-get bounds) (cons (point) (point))) (setf (easy-kill-get candidate) beg) (let ((easy-kill-inhibit-message nil)) (easy-kill-echo "%s" beg))) (t - (message "e-k-adjust-candidate t\tbeg=%s\tend=%s\texp=%s" beg end - (cons (or beg (easy-kill-get start)) - (or end (easy-kill-get end))) ) (setf (easy-kill-get bounds) (cons (or beg (easy-kill-get start)) (or end (easy-kill-get end)))))) - (message "\tBounds? = %s" (easy-kill-get bounds) ) - (message "\tMark? = %s" (easy-kill-get mark)) (cond ((easy-kill-get mark) (easy-kill-mark-region) (easy-kill-indicate-origin)) @@ -478,7 +470,6 @@ checked." ;; Work around a bug (fixed in 25.1, commit: 7a94f28a) in ;; `thing-at-point-bounds-of-url-at-point' that could return a ;; boundary not containing current point. - (message "e-k-bounds-of-thing-at-point\tthing=%s\tpoint=%s" thing (point)) (cl-flet ((chk (bound) (pcase-let ((`(,b . ,e) bound)) (and b e @@ -492,7 +483,6 @@ checked." (defun easy-kill-thing-forward-1 (thing &optional n) "Easy Kill wrapper for `forward-thing'." - (message "e-k-thing-forward-1 thing=%s n=%s" thing n) (pcase (easy-kill-thing-handler (format "easy-kill-thing-forward-%s" thing) major-mode) @@ -509,7 +499,6 @@ checked." ;; forward/backward is defined according to https://www.gnu.org/software/emacs/manual/html_node/emacs/Bidirectional-Editing.html ;; (defun easy-kill-thing-forward (n &optional which-edge) - (message "In easy-kill-thing-forward\tn=%s\twhich-edge=%s\tpoint=%s" n which-edge (point)) (when (and (easy-kill-get thing) (/= n 0)) (let* ((step (if (cl-minusp n) -1 +1)) (thing (easy-kill-get thing)) @@ -522,26 +511,15 @@ checked." (end (easy-kill-get end)) (front (cond ( (eq which-edge 'backward) - (message "\tBackward edge!") start) ( t - (message "\tForward edges") end))) - (UNUSED (progn - (message "\tstart=%s\tend=%s\tbounds1=%s\tfront=%s\tpoint=%s" start end bounds1 front (point) ) - (message "\torigin-thing-start=%s\torigin-thing-end=%s" origin-thing-start origin-thing-end) - ) ) (new-front (save-excursion (goto-char front) - (message "\tstarting point to %s" (point)) (with-demoted-errors (dotimes (_ (abs n)) (easy-kill-thing-forward-1 thing step))) - (message "\tmoved point to %s" (point)) (point)))) - (message "\tbefore adjust candidate\tstart=%s\tend=%s\tfront = %s new-front=%s" start end front new-front) - ;; (message "\tOLD list=%s" (sort (cons new-front bounds1) #'< )) - (message "(max new-front origin-thing-end )=%s" (max new-front origin-thing-end )) (pcase (and (/= front new-front) (cond ( (eq which-edge 'backward) @@ -553,7 +531,6 @@ checked." (list start (max new-front origin-thing-end )) (list start new-front))))) (`(,start ,end) - (message "about to adjust candidate\tstart=%s\tend=%s" start end) (easy-kill-adjust-candidate thing start end) t) ) ) ) ) @@ -564,7 +541,6 @@ checked." (`(,_ ,th . ,_) th) (`(,_ . ,th) th)) (prefix-numeric-value current-prefix-arg))) - (message "======================== easy-kill-thing =======================") (let* ((thing (or thing (easy-kill-get thing))) (n (or n 1)) (handler (and (not inhibit-handler) From bba0622854df825c88339a8bc7025efaa5f8876d Mon Sep 17 00:00:00 2001 From: Mike Panitz Date: Mon, 17 Dec 2018 13:43:34 -0800 Subject: [PATCH 3/3] Remove my 'todo' comment from the top of the file --- easy-kill.el | 5 ----- 1 file changed, 5 deletions(-) diff --git a/easy-kill.el b/easy-kill.el index 2612e65..1b2d3bc 100644 --- a/easy-kill.el +++ b/easy-kill.el @@ -40,11 +40,6 @@ ;;; Code: -;;; TODO: -;;;;;;; Add optional param to e-k-t-f to select the edge -;;;;;;;; Defaults to 'forward' -;;;;;;; how to only move 1 space forwards/back - (require 'cl-lib) (require 'thingatpt)