unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Nathaniel Flath <flat0103@gmail.com>
To: Miles Bader <miles@gnu.org>
Cc: Stefan Monnier <monnier@iro.umontreal.ca>, emacs-devel@gnu.org
Subject: Re: Overalays and point-entered
Date: Wed, 9 Dec 2009 22:37:35 -0500	[thread overview]
Message-ID: <5e3a506e0912091937v4a6ab81egee0529bb9603dfc8@mail.gmail.com> (raw)
In-Reply-To: <5e3a506e0912091541v71f7c4ebq6daf0bcac2ddccd2@mail.gmail.com>


[-- Attachment #1.1: Type: text/plain, Size: 3388 bytes --]

The patch is attached - please let me know if you have any comments.

Thanks,
Nathaniel Flath

On Wed, Dec 9, 2009 at 6:41 PM, Nathaniel Flath <flat0103@gmail.com> wrote:

> So after having my motherboard fried and having to finish projects, I
> finally had enough time to look at this again.  I've bene paying attention
> to this list, so I realize that the feature freeze is in effect, but if it's
> possible to discuss this now so that the next time trunk is unfrozen it can
> be put in I'd like to do that.
>
> The current  solution I have for the problem we were discussing is to have
> both buffers and windows have a list of overlays that had text properties
> with 'point-motion at the last point position.  The value of 'point-motion
> is a function that takes prev-pt-position, current-pt-position,  the
> overlay/text property the function belongs to, the buffer that was active
> last time run_point_motion_hooks was called, the previous window, and
> whether the hook 'belongs' to a buffer or a window.  This is getting a bit
> cumbersome, but also lets the writer of the hook specify exactly the
> behavior they want.  The hooks for the current buffer, previous buffer,
> current window, and previous window are all run.  I'm working on the patch
> for this - I'll send it on when I'm finished, which will probably be later
> today.  Does this sound like a good approach, or do you have some other
> suggestion?
>
> Thanks,
> Nathaniel Flath
>
>
> On Fri, Nov 6, 2009 at 9:54 AM, Nathaniel Flath <flat0103@gmail.com>wrote:
>
>> I started working on this - attached is a patch that will run hooks in
>> point-motion only when movement occurs inside the same buffer and window.
>> I'll work on buffer-change-motion-hook a bit later.  Let me know if there's
>> any issues.
>>
>> Thanks,
>> Nathaniel Flath
>>
>>
>> On Sat, Oct 31, 2009 at 12:03 PM, Nathaniel Flath <flat0103@gmail.com>wrote:
>>
>>> This may be a good solution.  What are your thoughts, Stefan?
>>>
>>> Nathaniel
>>>
>>>
>>> On Tue, Oct 27, 2009 at 8:44 PM, Miles Bader <miles@gnu.org> wrote:
>>>
>>>> Stefan Monnier <monnier@iro.umontreal.ca> writes:
>>>> > Now, what the behavior should be upon C-x o or C-x b is again somewhat
>>>> > unclear: for C-x b, actually I think it's pretty clear that it should
>>>> > run the hook (which is a vote in favor of per-window data), but for
>>>> "C-x
>>>> > o" it's less clear: running the hook would often be a good idea, but
>>>> > would mean that it's somewhere between difficult and impossible to let
>>>> > the user go to the *Completions* buffer to select an entry with
>>>> > choose-completion.
>>>>
>>>> It seems like it would be easier to handle the subtle variations among a
>>>> variety of cases if there were simply hooks for each type of movement --
>>>> one which is per-buffer, and only cares about point position, one which
>>>> runs when a window becomes selected/deselected (C-x o case), and one
>>>> which runs when a buffer is attached/detached from a window (C-x b
>>>> case).
>>>>
>>>> Then the programmer could add hooks to handle which things he cared
>>>> about, without having them be inadvertently triggered in cases he
>>>> doesn't care about.
>>>>
>>>> -miles
>>>>
>>>> --
>>>> "Though they may have different meanings, the cries of 'Yeeeee-haw!' and
>>>>  'Allahu akbar!' are, in spirit, not actually all that different."
>>>>
>>>
>>>
>>
>

[-- Attachment #1.2: Type: text/html, Size: 4838 bytes --]

[-- Attachment #2: pointmotion.patch --]
[-- Type: text/x-patch, Size: 11593 bytes --]

Index: buffer.c
===================================================================
RCS file: /sources/emacs/emacs/src/buffer.c,v
retrieving revision 1.591
diff -r1.591 buffer.c
399c399,401
< 
---
>   b->noverlays_prev = 0;
>   b->prev_text_prop = Qnil;
>   b->overlay_prev_vec = 0;
2208c2210
<     error ("Cannot swap a dead buffer's text");    
---
>     error ("Cannot swap a dead buffer's text");
4355c4357
<     last_overlay_modification_hooks = larger_vector 
---
>     last_overlay_modification_hooks = larger_vector
Index: buffer.h
===================================================================
RCS file: /sources/emacs/emacs/src/buffer.h,v
retrieving revision 1.130
diff -r1.130 buffer.h
560a561,567
>   /* Vector of overlays that were on this window the last time
>      run_point_motion_hooks was run and this window was current */
>   Lisp_Object* overlay_prev_vec;
> 
>   /* Number of overlays in overlay_prev_vec */
>   unsigned int noverlays_prev;
> 
798a806,809
> 
>   /* Text property containing point-motion */
>   Lisp_Object prev_text_prop;
> 
Index: editfns.c
===================================================================
RCS file: /sources/emacs/emacs/src/editfns.c,v
retrieving revision 1.476
diff -r1.476 editfns.c
502a503,544
> /* Returns an array of overlays that are active at the indication position and buffer.
>    The lenght of the array will be stored in num_overlays. */
> 
> Lisp_Object*
> get_overlays_at_pos (position, buffer, num_overlays )
>      Lisp_Object position, buffer;
>      int* num_overlays;
> {
>   CHECK_NUMBER_COERCE_MARKER (position);
> 
>   if (NILP (buffer))
>     XSETBUFFER (buffer, current_buffer);
> 
>   int posn = XINT (position);
>   int i, noverlays;
>   Lisp_Object* overlay_vec;
>   struct buffer *obuf = current_buffer;
>   set_buffer_temp (XBUFFER (buffer));
> 
>   noverlays = overlays_around (posn, overlay_vec, 0);
>   overlay_vec = xmalloc (sizeof(Lisp_Object) * noverlays);
>   noverlays = overlays_around (posn, overlay_vec, noverlays);
>   noverlays = sort_overlays (overlay_vec, noverlays, NULL);
> 
>   set_buffer_temp (obuf);
>   for (i = 0; i < noverlays; i++)
>     {
>       Lisp_Object ol = overlay_vec[i];
>       Lisp_Object start = OVERLAY_START (ol), finish = OVERLAY_END (ol);
>       if ((OVERLAY_POSITION (start) == posn
>            && XMARKER (start)->insertion_type == 1)
>           || (OVERLAY_POSITION (finish) == posn
>               && XMARKER (finish)->insertion_type == 0))
>         {
>           overlay_vec[i] = overlay_vec[noverlays];
>           noverlays--; i--;
>         }
>     }
>   *num_overlays = noverlays;
>   return overlay_vec;
> }
> 
Index: keyboard.c
===================================================================
RCS file: /sources/emacs/emacs/src/keyboard.c,v
retrieving revision 1.1024
diff -r1.1024 keyboard.c
1982a1983,1985
>       if (NILP (Vinhibit_point_motion_hooks))
>         run_point_motion_hooks (prev_buffer);
> 
1994a1998,2203
> /* Checks if it should run a 'point-motion hook for the given overlay or text property.  The
>  * property will be run if it exists, if the window property isn't set to disable it, and if
>  * the overlay is not in overlay_vec.
>  */
> void check_run_point_motion_hook (overlay,
>                                   prev_buffer,
>                                   prev_window,
>                                   is_buffer,
>                                   overlay_vec,
>                                   noverlay_vec)
>      Lisp_Object overlay, prev_buffer, prev_window, is_buffer;
>      Lisp_Object* overlay_vec;
>      int noverlay_vec;
> {
>   extern Lisp_Object Qpoint_motion, Qwindow;
>   Lisp_Object point_motion, overlay_window;
>   int j;
>   point_motion = Foverlay_get (overlay, Qpoint_motion);
>   overlay_window = Foverlay_get (overlay, Qwindow);
>   if (!NILP (point_motion) &&
>       (NILP (overlay_window)
>        || !NILP (Feq (overlay_window, Fselected_window()))))
>     {
>       for (j = 0; j < noverlay_vec; j++)
>         {
>           if (!NILP (Feq (overlay, overlay_vec[j] ) ) )
>             return;
>         }
> 
>       call6 (point_motion,
>              make_number (last_point_position),
>              make_number (current_buffer->pt),
>              overlay,
>              prev_buffer,
>              prev_window,
>              is_buffer
>              );
>     }
> }
> 
> /*  Runs 'point-motion hooks on text properties and overlays. */
> void
> run_point_motion_hooks (prev_c_buffer)
>      struct buffer* prev_c_buffer;
> {
>   extern Lisp_Object Qpoint_motion, Qwindow;
> 
>   static Lisp_Object* prev_window;
>   static Lisp_Object* prev_buffer;
>   static struct window* prev_c_window;
> 
>   int i, j, noverlays_cur;
>   Lisp_Object *overlay_cur_vec;
>   Lisp_Object point_motion, overlay_window;
>   struct window* current_window = XWINDOW (Fselected_window());
> 
>   /* Retrieves vector of overlays in current location and runs 'point-motion */
>      overlay_cur_vec = get_overlays_at_pos (make_number (current_buffer->pt),
>                                          current_buffer,
>                                          &noverlays_cur);
>   for (i = 0; i < noverlays_cur; i++)
>     {
>       check_run_point_motion_hook (overlay_cur_vec[i],
>                                    prev_buffer,
>                                    prev_window,
>                                    Qt,
>                                    0,
>                                    0);
>     }
> 
>   /* Runs 'point-motion for overlays being moved out of */
>   for (i = 0; i < current_buffer->noverlays_prev; i++)
>     {
>       check_run_point_motion_hook( current_buffer->overlay_prev_vec[i],
>                                    prev_buffer,
>                                    prev_window,
>                                    Qt,
>                                    overlay_cur_vec,
>                                    noverlays_cur );
>     }
> 
>   for (i = 0; i < current_window->noverlays_prev; i++)
>     {
>       check_run_point_motion_hook( current_window->overlay_prev_vec[i],
>                                    prev_buffer,
>                                    prev_window,
>                                    Qnil,
>                                    overlay_cur_vec,
>                                    noverlays_cur );
>     }
> 
>   /* Rest of commands handle changing windows/buffers */
>   if( current_buffer != prev_c_buffer ) {
>     for (i = 0; i < prev_c_buffer->noverlays_prev; i++ ) {
>       check_run_point_motion_hook( prev_c_buffer->overlay_prev_vec[i],
>                                    prev_buffer,
>                                    prev_window,
>                                    Qt,
>                                    overlay_cur_vec,
>                                    noverlays_cur );
>     }
>   }
> 
>   if( prev_c_window != 0 && current_window != prev_c_window ) {
>     for (i = 0; i < prev_c_window->noverlays_prev; i++)
>       {
>         check_run_point_motion_hook( prev_c_window->overlay_prev_vec[i],
>                                      prev_buffer,
>                                      prev_window,
>                                      Qnil,
>                                      overlay_cur_vec,
>                                      noverlays_cur );
>       }
>   }
> 
>   /* Runs hook for current text property */
>   point_motion = Fget_text_property (make_number (current_buffer->pt),
>                                      Qpoint_motion,
>                                      Qnil);
>   if (!NILP (point_motion))
>     {
>       call6 (point_motion,
>              make_number (last_point_position),
>              make_number (current_buffer->pt),
>              point_motion,
>              prev_buffer,
>              prev_window,
>              Qt );
>     }
> 
> 
> 
>   /* Runs 'point-motion for text property being moved out of */
>   if (current_buffer->prev_text_prop != 0
>       && !NILP (current_buffer->prev_text_prop)) {
>     call6 (current_buffer->prev_text_prop,
>            make_number (last_point_position),
>            make_number (current_buffer->pt),
>            current_buffer->prev_text_prop,
>            prev_buffer,
>            prev_window,
>            Qt );
>   }
> 
>   if (current_window->prev_text_prop != 0
>       && !NILP (current_window->prev_text_prop)) {
>     call6 (current_window->prev_text_prop,
>            make_number (last_point_position),
>            make_number (current_buffer->pt),
>            current_window->prev_text_prop,
>            prev_buffer,
>            prev_window,
>            Qt );
>   }
> 
>   /* These blocks handle changing buffer and window */
>   if (prev_c_buffer != current_buffer &&
>       prev_c_buffer->prev_text_prop != 0
>       && !NILP (prev_c_buffer->prev_text_prop)) {
>     call6 (prev_c_buffer->prev_text_prop,
>            make_number (last_point_position),
>            make_number (current_buffer->pt),
>            prev_c_buffer->prev_text_prop,
>            prev_buffer,
>            prev_window,
>            Qt );
>   }
> 
>   if (prev_c_window != 0 &&
>       prev_c_window != XWINDOW (Fselected_window()) &&
>       prev_c_window->prev_text_prop != 0
>       && !NILP (prev_c_window->prev_text_prop)) {
>     call6 (prev_c_window->prev_text_prop,
>            make_number (last_point_position),
>            make_number (current_buffer->pt),
>            prev_c_window->prev_text_prop,
>            prev_buffer,
>            prev_window,
>            Qnil );
>   }
> 
> 
>   /* Frees previous overlays and sets them to the current list */
>   if (current_window->overlay_prev_vec)
>     free (current_window->overlay_prev_vec);
>   if (current_buffer->overlay_prev_vec)
>     free (current_buffer->overlay_prev_vec);
> 
>   current_buffer->overlay_prev_vec = overlay_cur_vec;
>   current_buffer->noverlays_prev = noverlays_cur;
> 
>   current_window->overlay_prev_vec =
>     xmalloc( sizeof (overlay_cur_vec) );
>   memcpy (current_window->overlay_prev_vec,
>           overlay_cur_vec,
>           sizeof (overlay_cur_vec));
>   current_window->noverlays_prev = noverlays_cur;
> 
>   current_buffer->prev_text_prop = point_motion;
>   current_window->prev_text_prop = point_motion;
>   prev_window = Fselected_window();
>   prev_c_window = XWINDOW( Fselected_window() );
> 
>   prev_buffer = Fcurrent_buffer();
> }
> 
4734c4943
<   do 
---
>   do
Index: textprop.c
===================================================================
RCS file: /sources/emacs/emacs/src/textprop.c,v
retrieving revision 1.167
diff -r1.167 textprop.c
56a57
> Lisp_Object Qpoint_motion;
2351a2353,2354
>   staticpro (&Qpoint_motion);
>   Qpoint_motion = intern_c_string("point-motion");
Index: window.c
===================================================================
RCS file: /sources/emacs/emacs/src/window.c,v
retrieving revision 1.644
diff -r1.644 window.c
270c270,272
< 
---
>   p->prev_text_prop = 0;
>   p->overlay_prev_vec = 0;
>   p->noverlays_prev = 0;
Index: window.h
===================================================================
RCS file: /sources/emacs/emacs/src/window.h,v
retrieving revision 1.81
diff -r1.81 window.h
294a295,304
> 
>     /* Vector of overlays that were on this window the last time
>        run_point_motion_hooks was run and this window was current */
>     Lisp_Object* overlay_prev_vec;
> 
>     /* Number of overlays in overlay_prev_vec */
>     unsigned int noverlays_prev;
> 
>     /* Text property containing point-motion */
>     Lisp_Object* prev_text_prop;

  reply	other threads:[~2009-12-10  3:37 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-11  0:09 Overalays and point-entered Nathaniel Flath
2009-09-11  1:57 ` Stefan Monnier
     [not found]   ` <5e3a506e0909101902h72747299u2e306830ce63b11d@mail.gmail.com>
     [not found]     ` <jwvmy52p4re.fsf-monnier+emacs@gnu.org>
2009-09-11  4:08       ` Nathaniel Flath
2009-09-13 16:47         ` Nathaniel Flath
2009-09-14  1:16           ` Stefan Monnier
     [not found]             ` <5e3a506e0909140810r38a83a84l387fb6bafeb962c1@mail.gmail.com>
     [not found]               ` <jwvzl8x49un.fsf-monnier+emacs@gnu.org>
2009-09-16 20:46                 ` Nathaniel Flath
2009-09-17  1:05                   ` Stefan Monnier
2009-09-23 15:41                     ` Nathaniel Flath
2009-09-23 20:55                       ` Stefan Monnier
2009-09-24  1:07                         ` Stephen J. Turnbull
2009-09-24 14:31                           ` Overlays " Stefan Monnier
2009-09-24 13:47                         ` Overalays " Nathaniel Flath
2009-09-24 14:04                           ` Nathaniel Flath
2009-09-24 14:26                             ` Stefan Monnier
2009-10-06 18:33                               ` Nathaniel Flath
2009-10-17 17:00                                 ` Nathaniel Flath
2009-10-18  1:09                                   ` Stefan Monnier
2009-10-22  3:35                                     ` Nathaniel Flath
2009-10-22 15:37                                       ` Stefan Monnier
2009-10-23 15:43                                         ` Nathaniel Flath
2009-10-25  2:30                                           ` Stefan Monnier
2009-10-27  8:42                                             ` Nathaniel Flath
2009-10-27 13:28                                               ` Stefan Monnier
2009-10-28  0:44                                                 ` Miles Bader
2009-10-31 17:03                                                   ` Nathaniel Flath
2009-11-06 14:54                                                     ` Nathaniel Flath
2009-12-09 23:41                                                       ` Nathaniel Flath
2009-12-10  3:37                                                         ` Nathaniel Flath [this message]
2009-12-10  8:32                                                           ` Stefan Monnier
2009-12-20 23:39                                                             ` Nathaniel Flath
2010-01-02  3:34                                                               ` Nathaniel Flath
2010-01-08  7:19                                                                 ` Nathaniel Flath
2010-01-15  2:38                                                                   ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5e3a506e0912091937v4a6ab81egee0529bb9603dfc8@mail.gmail.com \
    --to=flat0103@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).