[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#27530: patch to cut and copy secondary
From: |
Tak Kunihiro |
Subject: |
bug#27530: patch to cut and copy secondary |
Date: |
Tue, 1 Aug 2017 10:35:35 +0900 |
Please do not forget the patch that I have sent 4 weeks ago.
I suppose everyone is busy.
On Jul 1, 2017, at 09:45 , Tak Kunihiro <tkk@misasa.okayama-u.ac.jp> wrote:
> I re-send a patch to cut and copy the secondary.
>
> I saw https://www.emacswiki.org/emacs/second-sel.el and found it is a
> super super-set of this patch. As my submission, I try to maintain
> this patch small and fit into `simple.el' and `mouse.el'.
>
>> defun mouse-secondary-exists-p ()
>>
>> Name probably shouldn't end in `-p' if the return value is
>> mainly not a Boolean. Non-nil here means overlay limits.
>
> I changed docstring to match the name of function.
>
> Return if the secondary selection exists in current buffer.
> When exists, this returns start and end of the secondary selection.
>
>> defun mouse-set-mark-and-point-from-secondary ()
>>
>> Cf. `secondary-to-primary'.
>
> I changed the name to mouse-set-primary-from-secondary.
>
>> defun mouse-set-secondary-from-region ()
>>
>> Cf. `primary-to-secondary'.
>
> I changed the name to mouse-set-secondary-from-primary.
>
>> IMO, the first, and simplest, improvement to add to Emacs is
>> a way to create and yank the secondary selection using only
>> the keyboard, not the mouse. My guess is that the reason
>> more users do not use the secondary selection is that there
>> are no keyboard keybindings for it.
>
> I made following the two functions to be interactive to be called from
> keyboard.
>
> mouse-set-primary-from-secondary
> mouse-set-secondary-from-primary
>
> My local plan is to set secondary by hook something like below.
>
> (add-hook 'view-mode-hook 'mouse-set-secondary-from-primary)
>
>
> # Change log
>
> 2017-07-02 Tak Kunihiro <tkk@misasa.okayama-u.ac.jp>
>
> Cut and copy the secondary selection when the region does not exist.
>
> * doc/emacs/killing.texi (Secondary Selection): Document support of
> cut and copy the secondary selection.
> * lisp/simple.el (kill-secondary-flag): Use also the secondary
> selection not only the region to cut and copy.
> (kill-region): Set target to the secondary selection not only the
> primary selection if kill-secondary-flag is non-nil.
> (kill-ring-save): Set target to the secondary selection not only the
> primary selection if kill-secondary-flag is non-nil.
> * lisp/mouse.el (mouse-secondary-exists-p): Return if the secondary
> selection exists in current buffer.
> (mouse-set-primary-from-secondary): Set the region to text in the
> secondary selection.
> (mouse-set-secondary-from-primary): Set the secondary selection to
> text in the region.
>
> # NEWS
>
> ** Use can cut and copy secondary when region does not exist.
> To cut and copy secondary using C-w and M-w, set 'kill-secondary-flag' to t.
>
> # Code 1/2
>
> diff --git a/mouse.260.el b/mouse.el
> old mode 100644
> new mode 100755
> index 9b6b169..55357da
> --- a/mouse.260.el
> +++ b/mouse.el
> @@ -1545,6 +1545,51 @@ CLICK position, kill the secondary selection."
> (> (length str) 0)
> (gui-set-selection 'SECONDARY str))))
>
> +(defun mouse-secondary-exists-p ()
> + "Return if the secondary selection exists in current buffer.
> +When exists, this returns start and end of the secondary selection."
> + (let ((buf (overlay-buffer mouse-secondary-overlay))
> + (beg (overlay-start mouse-secondary-overlay))
> + (end (overlay-end mouse-secondary-overlay)))
> + (when (and buf beg end
> + (equal buf (current-buffer))
> + (/= beg end))
> + (list beg end))))
> +
> +(defun mouse-set-primary-from-secondary ()
> + "Set the region to text in the secondary selection.
> +This works when the secondary selection exists and the region
> +does not exist in current buffer. The mouse-secondary-overlay
> +will be deleted."
> + (interactive)
> + (let ((secondary-to-kill (and (not (region-active-p))
> + (mouse-secondary-exists-p))))
> + ;; Delete overlay even on different buffer.
> + ;; Deletion should be later than obtaining location.
> + (delete-overlay mouse-secondary-overlay)
> + (when secondary-to-kill
> + (push-mark (car secondary-to-kill) t t)
> + (goto-char (cadr secondary-to-kill)))))
> +
> +(defun mouse-set-secondary-from-primary ()
> + "Set the secondary selection to text in the region.
> +When region does not exists, set mouse-secondary-start to the point.
> +When point is in the secondary selection, do nothing."
> + (interactive)
> + (cond
> + ((region-active-p) ; Create mouse-secondary-overlay from region.
> + (delete-overlay mouse-secondary-overlay)
> + (move-overlay mouse-secondary-overlay (region-beginning) (region-end)))
> + ((member 'secondary-selection ; Do nothing.
> + (mapcar (lambda (xxx) (overlay-get xxx 'face))
> + (overlays-at (point)))))
> + (t (delete-overlay mouse-secondary-overlay) ; Create
> mouse-secondary-start from point.
> + (push-mark (point))
> + (setq mouse-secondary-start (make-marker))
> + (move-marker mouse-secondary-start (point)))))
> +
>
> (defcustom mouse-buffer-menu-maxlen 20
> "Number of buffers in one pane (submenu) of the buffer menu.
>
> # Code 2/2
>
> diff --git a/simple.252.el b/simple.el
> index 5f70ade..a80953a 100644
> --- a/simple.252.el
> +++ b/simple.el
> @@ -4287,11 +4287,21 @@ move the yanking point; just return the Nth kill
> forward."
> :type 'boolean
> :group 'killing)
>
> +(defcustom kill-secondary-flag nil
> + "Kill the secondary selection when it exists but the region does not
> exist."
> + :type 'boolean
> + :group 'mouse
> + :version "26.1")
> +
> (defun kill-region (beg end &optional region)
> "Kill (\"cut\") text between point and mark.
> This deletes the text from the buffer and saves it in the kill ring.
> The command \\[yank] can retrieve it from there.
> \(If you want to save the region without killing it, use \\[kill-ring-save].)
> +If `kill-secondary-flag' is non-nil, kill
> +mouse-secondary-overlay instead of the region.
>
> If you want to append the killed region to the last killed text,
> use \\[append-next-kill] before \\[kill-region].
> @@ -4317,7 +4327,12 @@ Supply two arguments, character positions BEG and END
> indicating the
> region instead."
> ;; Pass mark first, then point, because the order matters when
> ;; calling `kill-append'.
> - (interactive (list (mark) (point) 'region))
> + (interactive
> + (progn (when kill-secondary-flag
> + (mouse-set-primary-from-secondary)) ; no region but secondary
> + (list (mark) (point) 'region)))
> (unless (and beg end)
> (user-error "The mark is not set now, so there is no region"))
> (condition-case nil
> @@ -4387,6 +4402,8 @@ This command's old key binding has been given to
> `kill-ring-save'."
> In Transient Mark mode, deactivate the mark.
> If `interprogram-cut-function' is non-nil, also save the text for a window
> system cut and paste.
> +If `kill-secondary-flag' is non-nil, save
> +mouse-secondary-overlay instead of the region.
>
> If you want to append the killed line to the last killed text,
> use \\[append-next-kill] before \\[kill-ring-save].
> @@ -4404,8 +4421,13 @@ This command is similar to `copy-region-as-kill',
> except that it gives
> visual feedback indicating the extent of the region being copied."
> ;; Pass mark first, then point, because the order matters when
> ;; calling `kill-append'.
> - (interactive (list (mark) (point)
> - (prefix-numeric-value current-prefix-arg)))
> + (interactive
> + (progn (when kill-secondary-flag
> + (mouse-set-primary-from-secondary)) ; no region but secondary
> + (list (mark) (point)
> + (prefix-numeric-value current-prefix-arg))))
> (copy-region-as-kill beg end region)
> ;; This use of called-interactively-p is correct because the code it
> ;; controls just gives the user visual feedback.
>
>
> # Info
>
> diff --git a/killing.252.texi b/killing.texi
> index 47de053..f554adb 100755
> --- a/killing.252.texi
> +++ b/killing.texi
> @@ -624,6 +624,10 @@ end of the yanked text (@code{mouse-yank-secondary}).
> Double or triple clicking of @kbd{M-mouse-1} operates on words and
> lines, much like @kbd{mouse-1}.
>
> +If @code{kill-secondary-flag} is non-@code{nil}, a command @kbd{C-w}
> +(@code{kill-region}), and a command @kbd{M-w} (@code{kill-ring-save})
> +will target the secondary selection when region does not exist.
> +
> If @code{mouse-yank-at-point} is non-@code{nil}, @kbd{M-mouse-2} yanks
> at point. Then it does not matter precisely where you click, or even
> which of the frame's windows you click on. @xref{Mouse Commands}.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- bug#27530: patch to cut and copy secondary,
Tak Kunihiro <=