bug-gnu-emacs
[Top][All Lists]
Advanced

[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: Sun, 10 Sep 2017 12:01:43 +0900 (JST)

Thank you for the response.

> In sum, I think these are too general: they talk about OVERLAY in
> general, whereas what you really mean is the special overlay used for
> secondary selection.  So how about these instead:
> 
>   secondary-selection-exist-p
>   secondary-selection-from-region
>   secondary-selection-to-region

OK. How about three functions like below?  I plan to send a patch
relative to lisp/mouse.el.

  (defun secondary-selection-exist-p ()
    "Return if there is the secondary selection in current buffer."
    (memq mouse-secondary-overlay (overlays-in (point-min) (point-max))))
  
  (defun secondary-selection-to-region ()
    "Set beginning and end of the region to those of the secondary selection.
  This works when the secondary selection exists and the region
  does not exist in current buffer.  The secondary selection will
  be deleted afterward."
    (when (and (not (region-active-p))
               (secondary-selection-exist-p))
      (let* ((beg (overlay-start mouse-secondary-overlay))
             (end (overlay-end mouse-secondary-overlay))
             ;; Restore point to whichever closer.
             (is-point-front (< (point) (/ (+ beg end) 2))))
        (push-mark (if is-point-front end beg) t t)
        (goto-char (if is-point-front beg end)))
      ; Delete the secondary selection on current buffer.
      (delete-overlay mouse-secondary-overlay)))
  
  (defun secondary-selection-from-region ()
    "Set beginning and end of the secondary selection to those of the region."
    (when (region-active-p) ; Create the secondary selection from region.
      (delete-overlay mouse-secondary-overlay) ; Delete the secondary selection 
even on a different buffer.
      (move-overlay mouse-secondary-overlay (region-beginning) (region-end))))


Point-to-point responses are shown below.

>>  -- Function: overlay-exchange-region overlay
>>      This function exchanges the region and OVERLAY.
>>      When the region is active, this sets OVERLAY from the region.
>>      When the region is not active but OVERLAY exists, this sets the
>>      region from OVERLAY.
> 
> Does this do anything but call overlay-to-region and
> overlay-from-region? 

Yes.  I agree to exclude this.

>> -- Function: overlay-exists-p overlay
>>     This function returns if OVERLAY exists in current buffer.
>>     When OVERLAY exists, this returns list of start and end of
>>     OVERLAY.
> 
> This is just
> 
>   (memq OVERLAY (overlays-in (point-min) (point-max)))
> 
> Right?

Yes, you are correct.

>> -- Function: overlay-to-region overlay
>>     This function sets the region to text in OVERLAY.
>>     This works when OVERLAY exists and the region does not exist in
>>     current buffer.  The OVERLAY will be deleted.
> 
> I don't understand this one.  I guess "text in OVERLAY" is confusing;
> did you mean OVERLAY's beginning and end?

Yes, sentence was vague.  It should have said as below.

   -- Function: overlay-to-region overlay
       This function sets beginning and end of the region to those of
       OVERLAY.  This works when OVERLAY exists and the region does not
       exist in current buffer.  The OVERLAY will be deleted afterward.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]