unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* `mouse-save-then-kill' changes
@ 2010-11-05 17:49 Drew Adams
  2010-11-07 19:01 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2010-11-05 17:49 UTC (permalink / raw)
  To: emacs-devel

`mouse-save-then-kill' has been changed quite a bit for Emacs 24.
I'm trying to adjust my code to the changes.

Until now, it called `mouse-save-then-kill-delete-region' to kill/delete the
text when you click the same spot.  (`mouse-secondary-save-then-kill' still does
this.)

This made it possible to simply flet-bind `mouse-save-then-kill-delete-region'
in order to get an alternative behavior to the killing/deleting part.

In my case, in *Completions* I flet-bind it to a command `foobar' that picks up
the selected candidates and saves them to a list for special processing.  That
is, in *Completions* I bind `mouse-3' to a command that does this:

(defun foo (&optional arg)
  (interactive "e\nP")
  (flet ((mouse-save-then-kill-delete-region (beg end)
           (foobar nil arg)))
      (mouse-save-then-kill click))
  (setq this-command  'mouse-save-then-kill))

Now (Emacs 24) I have to (a) duplicate all of the code of
`mouse-save-then-kill', (b) replace the 3 lines that delete or kill the region
by a call to `foobar', and (c) change references to `mouse-save-then-kill'
within the new command to the new command name - e.g. places where the code
checks `(eq last-command 'mouse-save-then-kill)'.

That's quite ugly, for something that used to be simple.  Any chance of your
moving the 3 kill/delete lines out of `mouse-save-then-kill' into a function,
like this?

(defun mouse-kill/delete-region (pt)
  "Kill or delete region, according to `mouse-drag-copy-region'."
  (if mouse-drag-copy-region
     (delete-region (mark t) (point))
   (kill-region (mark t) (point))))

(You cannot name this function `mouse-save-then-kill-delete-region' since that
function still exists and is used for the secondary selection.)




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: `mouse-save-then-kill' changes
  2010-11-05 17:49 `mouse-save-then-kill' changes Drew Adams
@ 2010-11-07 19:01 ` Stefan Monnier
  2010-11-07 20:36   ` Drew Adams
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2010-11-07 19:01 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

> Now (Emacs 24) I have to (a) duplicate all of the code of
> `mouse-save-then-kill', (b) replace the 3 lines that delete or kill
> the region by a call to `foobar', and (c) change references to
> `mouse-save-then-kill' within the new command to the new command
> name - e.g. places where the code checks `(eq last-command
> 'mouse-save-then-kill)'.

Maybe you can use buffer-substring-filters instead?


        Stefan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: `mouse-save-then-kill' changes
  2010-11-07 19:01 ` Stefan Monnier
@ 2010-11-07 20:36   ` Drew Adams
  2010-11-08  3:38     ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2010-11-07 20:36 UTC (permalink / raw)
  To: 'Stefan Monnier'; +Cc: emacs-devel

> > Now (Emacs 24) I have to (a) duplicate all of the code of
> > `mouse-save-then-kill', (b) replace the 3 lines that delete or kill
> > the region by a call to `foobar', and (c) change references to
> > `mouse-save-then-kill' within the new command to the new command
> > name - e.g. places where the code checks `(eq last-command
> > 'mouse-save-then-kill)'.
> 
> Maybe you can use buffer-substring-filters instead?

Thanks for suggesting something.  But I don't really see how that var might fit
in here.  Can you elaborate?

That var is used only by `filter-buffer-substring'.  That function is used in
`mouse-save-then-kill', but only in the calls to `kill-new', which are places
unrelated to the part that kills or deletes the region.  So I don't see how that
var would help.

[BTW - Dunno whether the suggested use of `b-s-f' would be only for Emacs 24+ or
also for other versions (since I don't know how you're suggesting to use it).
But if it is for Emacs 24+ then I guess you mean
`filter-buffer-substring-functions' - `b-s-f' is now obsolete. ;-)  And if for
other versions also then it won't work for Emacs 20 or 21 (no such var).]




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: `mouse-save-then-kill' changes
  2010-11-07 20:36   ` Drew Adams
@ 2010-11-08  3:38     ` Stefan Monnier
  2010-11-08  4:42       ` Drew Adams
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2010-11-08  3:38 UTC (permalink / raw)
  To: Drew Adams; +Cc: emacs-devel

>> > Now (Emacs 24) I have to (a) duplicate all of the code of
>> > `mouse-save-then-kill', (b) replace the 3 lines that delete or kill
>> > the region by a call to `foobar', and (c) change references to
>> > `mouse-save-then-kill' within the new command to the new command
>> > name - e.g. places where the code checks `(eq last-command
>> > 'mouse-save-then-kill)'.
>> Maybe you can use buffer-substring-filters instead?
> Thanks for suggesting something.  But I don't really see how that var
> might fit in here.  Can you elaborate?

I obviously can't, since I don't know what you're actually doing.
This said, rather than ask us to write the code differently so that you
can override an internal function (which is likely to get
renamed/inlined/changed at some point in the future), I recommend you
ask for a hook instead.


        Stefan



^ permalink raw reply	[flat|nested] 6+ messages in thread

* RE: `mouse-save-then-kill' changes
  2010-11-08  3:38     ` Stefan Monnier
@ 2010-11-08  4:42       ` Drew Adams
  2010-11-08  9:11         ` tomas
  0 siblings, 1 reply; 6+ messages in thread
From: Drew Adams @ 2010-11-08  4:42 UTC (permalink / raw)
  To: 'Stefan Monnier'; +Cc: emacs-devel

> I obviously can't, since I don't know what you're actually doing.

I think I was pretty clear.  I'm substituting another action for the delete/kill
region action that happens when you click `mouse-3' a second time at the same
place.  (I even mentioned what I'm substituting for it, although that is
irrelevant.)

In the past, the delete/kill region action was done by function
`mouse-save-then-kill-delete-region', so it was enough to bind that symbol to a
different function (using `flet').  Or to advise that function (`around' with no
`ad-do-it').  Trivial.

Now, that separate function (`m-s-t-k-d-r') is no longer used in
`mouse-save-then-kill' (it is still used for the secondary selection, however).
The delete/kill region code is now in line instead.  It is only 3 lines now, so
that is an understandable change.

Result: to substitute something (anything) for the delete/kill action now
requires copying all of the `m-s-t-k' code and replacing just those 3 lines.

> This said, rather than ask us to write the code differently 
> so that you can override an internal function (which is likely to get
> renamed/inlined/changed at some point in the future), I recommend you
> ask for a hook instead.

I don't see how a hook would help, since I want to do something other than, not
something in addition to, deleting/killing the region.

If there were a separate function for that action then I could either
`defadvice' it or `flet' the function symbol around a call to
`mouse-save-then-kill' (what I did previously).

Better yet would be for you to define a function _variable_ and have the
`m-s-t-k' code funcall that.  The default value would be a function that
deletes/kills the region: exactly the 3 lines used today.

Keep in mind that `mouse-save-then-kill' is a complex function that operates
differently depending on the historical context (e.g. whether it is called twice
in succession at the same position).  The code represents not one action but a
logical sequence of possible actions.

The action associated with a second `mouse-3' click at the same place is only
one part of that complex sequence: the part that deletes/kills the region.  That
particular action is almost an arbitrary choice for that particular click.

One can easily conceive of other, alternative actions for that final `mouse-3'
click, keeping the rest of the sequence: `mouse-1' (possibly double etc.
clicks)..., previous `mouse-3' click(s) at different positions....  That means
separating out the final `mouse-3' click action as something variable.

Anyway, I simply _asked if there was any chance_ of your creating a separate
function for those 3 lines.  I would like to see that.  And preferably with that
function being just the default value of a function variable that gets
funcalled.

If not, so be it.  I've already copied the code and modified it for my use.




^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: `mouse-save-then-kill' changes
  2010-11-08  4:42       ` Drew Adams
@ 2010-11-08  9:11         ` tomas
  0 siblings, 0 replies; 6+ messages in thread
From: tomas @ 2010-11-08  9:11 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Stefan Monnier', emacs-devel

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Sun, Nov 07, 2010 at 08:42:01PM -0800, Drew Adams wrote:
> > I obviously can't, since I don't know what you're actually doing.

[...]

> I don't see how a hook would help, since I want to do something other than, not
> something in addition to, deleting/killing the region.

I can see how a hook would help here: to the programmers of the "layer
below" it signals. "careful, the user is supposed to change
functionality here". Whereas your approach of flet-binding a function,
while cute, would prevent changing any innards of Emacs for the fear of
breaking some hack as this. I can understand that that does not fly.

A hook -- why not? When the hook is there, don't run those three lines
of code. Or more flexible: use an "abnormal hook" and decide depending
on the return value of the hook function(s) (they tell the lower layer
"I've taken care of this" vs. "Do your own default thing").

Regards
- -- tomás
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFM176lBcgs9XrR2kYRArrfAJoDPC9JzUp6WFE8VAAEm4Z2dFgNbgCcCmG2
3qgI7uTy+VyPSNC+7UNmT+U=
=N48m
-----END PGP SIGNATURE-----



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2010-11-08  9:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-11-05 17:49 `mouse-save-then-kill' changes Drew Adams
2010-11-07 19:01 ` Stefan Monnier
2010-11-07 20:36   ` Drew Adams
2010-11-08  3:38     ` Stefan Monnier
2010-11-08  4:42       ` Drew Adams
2010-11-08  9:11         ` tomas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).