all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Suggestion to add before and after hooks to posn-set-point.
@ 2017-09-18 22:32 Robert Weiner
  2017-09-19  2:21 ` Stefan Monnier
  0 siblings, 1 reply; 3+ messages in thread
From: Robert Weiner @ 2017-09-18 22:32 UTC (permalink / raw)
  To: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 888 bytes --]

It seems as of Emacs 25, there are no hooks in posn-set-point to do
something custom before or after point has been set/moved.  How about
modifying posn-set-point like so:

(defun posn-set-point (position)
  "Move point to POSITION.
Select the corresponding window as well."
  (if (not (windowp (posn-window position)))
      (error "Position not in text area of window"))
  (run-hooks 'before-set-point-hook) ; <-- ADD
  (select-window (posn-window position))
  (if (numberp (posn-point position))
      (goto-char (posn-point position)))
  (run-hooks 'after-set-point-hook)) ; <-- AD

I can imagine both global and buffer-local uses of such hooks, such as
logging where point has been and highlighting elements selected within a
buffer.  I have done some testing with it and I like it.

If this is to be added, I would prefer that a core committer add it since
it is in core code.

Bob

[-- Attachment #2: Type: text/html, Size: 2114 bytes --]

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

* Re: Suggestion to add before and after hooks to posn-set-point.
  2017-09-18 22:32 Suggestion to add before and after hooks to posn-set-point Robert Weiner
@ 2017-09-19  2:21 ` Stefan Monnier
  2017-09-19  3:07   ` Robert Weiner
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Monnier @ 2017-09-19  2:21 UTC (permalink / raw)
  To: emacs-devel

> It seems as of Emacs 25, there are no hooks in posn-set-point to do
> something custom before or after point has been set/moved.

There are various ways to do things very similar to what posn-set-point
does, so a hook on this function seems rather odd to me: it will only
catch some window selections and some point movements.

IOW I find it difficult to characterize when these hooks will be run
(except with the trivial characterization that they're run when
posn-set-point is run, which is not very meaningful since no command is
documented to use this function).


        Stefan




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

* Re: Suggestion to add before and after hooks to posn-set-point.
  2017-09-19  2:21 ` Stefan Monnier
@ 2017-09-19  3:07   ` Robert Weiner
  0 siblings, 0 replies; 3+ messages in thread
From: Robert Weiner @ 2017-09-19  3:07 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1071 bytes --]

On Mon, Sep 18, 2017 at 10:21 PM, Stefan Monnier <monnier@iro.umontreal.ca>
wrote:

> > It seems as of Emacs 25, there are no hooks in posn-set-point to do
> > something custom before or after point has been set/moved.
>
> There are various ways to do things very similar to what posn-set-point
> does, so a hook on this function seems rather odd to me: it will only
> catch some window selections and some point movements.

​​


> ​​
> IOW I find it difficult to characterize when these hooks will be run

​​
> (except with the trivial characterization that they're run when
> ​​
> posn-set-point is run, which is not very meaningful since no command is
> ​​
> documented to use this function).
>

​FYI, the initial desire for these hooks came from wanting to do something
whenever the mouse set point.
Then I thought it would be more useful if it covered any interactive
setting of point, which led to posn-set-point
(called by mouse-set-point).  If there are better ways to do this, let's
discuss them.

Bob​​

[-- Attachment #2: Type: text/html, Size: 2642 bytes --]

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

end of thread, other threads:[~2017-09-19  3:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-09-18 22:32 Suggestion to add before and after hooks to posn-set-point Robert Weiner
2017-09-19  2:21 ` Stefan Monnier
2017-09-19  3:07   ` Robert Weiner

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.