From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David De La Harpe Golden Newsgroups: gmane.emacs.bugs Subject: bug#6774: Cut and paste with C-w/mouse-2 not working? Date: Mon, 02 Aug 2010 21:30:30 +0100 Message-ID: <4C572AE6.7070104@harpegolden.net> References: <4C55EF50.3080100@alice.it> <4C5645A1.7000500@harpegolden.net> <87y6coby49.fsf@stupidchicken.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1280781534 598 80.91.229.12 (2 Aug 2010 20:38:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 2 Aug 2010 20:38:54 +0000 (UTC) Cc: 6774@debbugs.gnu.org, Angelo Graziosi To: Chong Yidong Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Aug 02 22:38:52 2010 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Og1mb-0001lF-0w for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Aug 2010 22:38:49 +0200 Original-Received: from localhost ([127.0.0.1]:43307 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Og1mZ-0006uN-PG for geb-bug-gnu-emacs@m.gmane.org; Mon, 02 Aug 2010 16:38:47 -0400 Original-Received: from [140.186.70.92] (port=60691 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Og1ls-0006TR-Er for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2010 16:38:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Og1lr-00030g-7h for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2010 16:38:04 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:52933) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Og1lr-00030b-5X for bug-gnu-emacs@gnu.org; Mon, 02 Aug 2010 16:38:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1Og1f3-0000zO-V3; Mon, 02 Aug 2010 16:31:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: David De La Harpe Golden Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 02 Aug 2010 20:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 6774 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 6774-submit@debbugs.gnu.org id=B6774.12807810123784 (code B ref 6774); Mon, 02 Aug 2010 20:31:01 +0000 Original-Received: (at 6774) by debbugs.gnu.org; 2 Aug 2010 20:30:12 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Og1eF-0000yz-Qj for submit@debbugs.gnu.org; Mon, 02 Aug 2010 16:30:12 -0400 Original-Received: from harpegolden.net ([65.99.215.13]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Og1eD-0000yb-E0 for 6774@debbugs.gnu.org; Mon, 02 Aug 2010 16:30:10 -0400 Original-Received: from [87.198.55.208] (87-198-55-208.ptr.magnet.ie [87.198.55.208]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "David De La Harpe Golden", Issuer "David De La Harpe Golden Personal CA rev 3" (verified OK)) by harpegolden.net (Postfix) with ESMTPSA id BB99268474; Mon, 2 Aug 2010 21:30:29 +0100 (IST) User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.10) Gecko/20100620 Icedove/3.0.5 In-Reply-To: <87y6coby49.fsf@stupidchicken.com> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Mon, 02 Aug 2010 16:31:01 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:39173 Archived-At: On 02/08/10 20:41, Chong Yidong wrote: > David De La Harpe Golden writes: > >> Yes, there's a problem here - I guess emacs is keeping primary bound >> to a span that's become zero-length. Again. > > After thinking about this, my opinion is that the Emacs command > loop---or rather prepare_to_modify_buffer in insdel.c---should make a > copy of the primary selection before running before-change-functions. > Then, deactivate-mark should check if the resulting string is empty; > and, if so, set the primary to that saved copy. > > I haven't looked at your branch; is this the approach you implemented? Not reallym, though my branch certainly ended up altering the command loop to save a copy of the primary selection before commands - doing that where you say may be more selective to commands that are going to modify, and therefore more efficient. Does your way work properly in a multi-window context on its own, though? I suspect not -that it will deactivate-mark on "boring" restored active regions (see below) and set the selection to the "boring" region, confounding user expectations, because the restored region could be non-empty. So I'll try and have a go explaining the key points of the branch, then, bearing in mind it was focussed mostly on making multi-window/frame stuff work, and the zero length fixes came along for the ride. On the whole, grabbing it locally and giving it a go may be worthwhile, might be faster than reading the below! At this stage, the sheer length of the explanation below suggests the approach is just too ugly. I may be stuck in a rut on it (the trouble is it _does_ give quite nice results...). Just doing it eagerly may be better. However, one of the non-efficiency reasons for the laziness was because certain gestures in emacs are really effectively "long running commands" that you can stop and switch to another application in the middle of (track-mouse...), and something happening purely before/after commands can leave the region stale, and the laziness skirted that. The thing is, if you use focus-follows-mouse between frames, or mouse autoselect-window between emacs windows, you select_window without going through "normal channels", so trying to do _anything_ smart in deactivate-mark tends to break - e.g. the mark is being deactivated in a window different to the last window bound to the selection. The selx branch just forces the selection to a string if it's lazy-bound to a window and emacs still owns it on deactivate mark. 1. Introduce a save/restore of mark and mark-active state as well as point on select_window window switching. The restore would be controversial, but could easily be made optional - the saving is the important bit for our purposes, the restore is a "new feature". This bit might be independently a nice feature, at least. 2. Allow selections to be lazy-bound to window rather than buffer. (this is unfinished - in both window and buffer cases should really walk the selection_alist and force the lazy selections before deletion of the window/buffer. When the selection is bound to a window, it is the span between the window-mark and window-point. 3. Introduce a x-force-lazy-selection to force a selection to a string if it is lazy-bound to a buffer. This is currently only a placeholder inefficient implementation, doing it even if unnecessary (i.e. selection is already a string), it could be made more efficient by checking if forcing is necessary - but owing to the split of the code between C and Lisp, that would probably mean moving it to C. 4. Introduce a notion of the region being "interesting" or "boring". If a region is zero-length _or_ matching the saved boring region extent, consider it boring. 6. make select_window set the region boring when it restores the region. This preserves temporal ordering of selection with respect to user explicit selection actions rather than programmatic restores. 5. If select-active-region is called, test if the region is interesting. If it isn't (boring/zero), don't select, just set a "select-active-region-maybe" flag. If it isn't boring, set it to the current window. 6. Before each command in the command loop, if select-active-region maybe, check again if the region is interesting. 7. Force the primary selection (ideally this would be more efficient as in 3), effectively freezing off a string. 8. After each command, call select-active-region again to check if the region is interesting and "thaw". 9. In deactivate mark, force the selection in case it's lazy. Since we can't actually tell if we're in the window that the selection was bound to, it's _un_safe to use buffer-substring, have to go through x-force-lazy-selection.