diff -NarU 10 emacs-exs/lisp/simple.el emacs/lisp/simple.el --- emacs-exs/lisp/simple.el 2008-02-01 22:40:31.000000000 +0000 +++ emacs/lisp/simple.el 2008-02-01 23:31:52.000000000 +0000 @@ -3340,20 +3340,63 @@ (transient-mark-mode (setq mark-active nil) (run-hooks 'deactivate-mark-hook)))) (defcustom select-active-regions nil "If non-nil, an active region automatically becomes the window selection." :type 'boolean :group 'killing :version "23.1") + +;; Do we want to provide a general post-point-motion-hook ? +;; Easily abused, would at least have to come with dire warning +;; about performance implications of anything added. +;; +(defvar post-point-motion-hook nil + "Hook called after point movement. + +Keep hooks short, sweet and FAST, or better yet, don't use this +at all. Hooks here should NOT try to affect point position, +unless you want recursive trouble.") + +(defun post-point-motion () + "Internal Lisp function called after point movements. + +See e.g. `activate-mark-hook', `post-command-hook' and text properties +`point-entered' / `point-left' if you want to take action in +certain common point movement situations. + +`inhibit-point-motion-hooks' inhibits calling this +function and therefore anything it does. This function currently +just handles sending the highlighted regions to the window system +when the point is moved and `select-active-regions' is true" + + ;; Er. But Should inhibit-point-motion-hooks inhibit this? I just + ;; about argued myself into thinking it shouldt - if it shouldn't, + ;; change in C code intervals.c/set_point_both(), not here. + + (and select-active-regions + (region-active-p) + interprogram-highlight-function + (funcall interprogram-highlight-function + (buffer-substring (region-beginning) (region-end)))) + ;; activate-mark-hook is defined in its docstring to run + ;; after commands when the region may have changed, not just when + ;; the mark activates. Does moving the point + ;; and thus changing the region count as such a command - probably? + (and (region-active-p) + (run-hooks 'activate-mark-hook)) + ;; if you want post-point-motion-hook above... + (run-hooks 'post-point-motion-hook)) + + (defun set-mark (pos) "Set this buffer's mark to POS. Don't use this function! That is to say, don't use this function unless you want the user to see that the mark has moved, and you want the previous mark position to be lost. Normally, when a new mark is set, the old one should go on the stack. This is why most applications should use `push-mark', not `set-mark'. Novice Emacs Lisp programmers often try to use the mark for the wrong diff -NarU 10 emacs-exs/src/intervals.c emacs/src/intervals.c --- emacs-exs/src/intervals.c 2008-02-01 22:41:39.000000000 +0000 +++ emacs/src/intervals.c 2008-02-01 23:16:00.000000000 +0000 @@ -2050,20 +2050,23 @@ if (charpos > BUF_ZV (buffer) || charpos < BUF_BEGV (buffer)) abort (); have_overlays = (buffer->overlays_before || buffer->overlays_after); /* If we have no text properties and overlays, then we can do it quickly. */ if (NULL_INTERVAL_P (BUF_INTERVALS (buffer)) && ! have_overlays) { temp_set_point_both (buffer, charpos, bytepos); + if (NILP (Vinhibit_point_motion_hooks) && + FUNCTIONP (intern ("post-point-motion"))) + call0 (intern ("post-point-motion")); return; } /* Set TO to the interval containing the char after CHARPOS, and TOPREV to the interval containing the char before CHARPOS. Either one may be null. They may be equal. */ to = find_interval (BUF_INTERVALS (buffer), charpos); if (charpos == BUF_BEGV (buffer)) toprev = 0; else if (to && to->position == charpos) @@ -2087,20 +2090,23 @@ else if (buffer_point != BUF_PT (buffer)) fromprev = from, from = 0; else fromprev = from; /* Moving within an interval. */ if (to == from && toprev == fromprev && INTERVAL_VISIBLE_P (to) && ! have_overlays) { temp_set_point_both (buffer, charpos, bytepos); + if (NILP (Vinhibit_point_motion_hooks) && + FUNCTIONP (intern ("post-point-motion"))) + call0 (intern ("post-point-motion")); return; } original_position = charpos; /* If the new position is between two intangible characters with the same intangible property value, move forward or backward until a change in that property. */ if (NILP (Vinhibit_point_motion_hooks) && ((! NULL_INTERVAL_P (to) && ! NULL_INTERVAL_P (toprev)) @@ -2236,20 +2242,25 @@ call2 (leave_after, make_number (old_position), make_number (charpos)); if (! EQ (enter_before, leave_before) && !NILP (enter_before)) call2 (enter_before, make_number (old_position), make_number (charpos)); if (! EQ (enter_after, leave_after) && !NILP (enter_after)) call2 (enter_after, make_number (old_position), make_number (charpos)); } + + if (NILP (Vinhibit_point_motion_hooks) && + FUNCTIONP (intern ("post-point-motion"))) + call0 (intern ("post-point-motion")); + } /* Move point to POSITION, unless POSITION is inside an intangible segment that reaches all the way to point. */ void move_if_not_intangible (position) int position; { Lisp_Object pos;