bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#22404: 25.1.50; Forcing `window-scroll-functions` to run.


From: Keith David Bershatsky
Subject: bug#22404: 25.1.50; Forcing `window-scroll-functions` to run.
Date: Wed, 20 Jan 2016 18:32:40 -0800

`set-window-start` (without the third option) would indeed trigger the WSF 
because it contains a key ingredient:  `w->force_start = true`.

Because the second argument (i.e., POS) cannot be known from the PCH when point 
has moved beyond the visible window, `set-window-start` is not a viable 
substitute for this feature request.

The attached patch is an example of an implementation of this feature request.  
I created a new function called `force-wsf`, whose sole purpose is to trigger 
the WSF to run during redisplay -- after the PCH has already finished.  As 
noted in a previous e-mail, `run-window-scroll-functions` doesn't accomplish 
what `force-wsf` can achieve because the former runs the function attached to 
the WSF immediately -- instead of waiting until later on during redisplay when 
the correct values of `window-start` and `window-end` are ascertainable.

This is my first attempt at writing something like this, and I'm not sure 
exactly if everything is correct.  It does, however, appear to achieve the 
desired affect -- i.e., run the WSF at least once every command loop (even if 
no scrolling occurs) so we can always know the correct values for 
`window-start` and `window-end`.  It is no longer necessary to guess with 
`elisp` from the PCH regarding whether WSF will run.

I would, however, still like to come up with a test at the C-source code level 
that tells me whether the WSF will run more than one time -- because I only 
care about the last call on the WSF when the final values for `window-start` 
and `window-end` become available.

The usage for the new function `force-wsf` is as follows:

    (defun pch-fn ()
      (force-wsf (selected-window)))
    
    (add-hook 'post-command-hook 'pch-fn nil 'local)
    
    (defun wsf-fn (win start)
      (message "point: %s | win: %s | start: %s | end: %s" 
        ;; A better test at the C-source code level appears to be needed to 
ascertain whether
        ;; the WSF will run more than one time -- because we want the value for 
`window-start`
        ;; and `window-end win t` based on the LAST time WSF runs during the 
command loop.
        (if (pos-visible-in-window-p nil nil nil)
          "visible"
          "NOT visible")
        win start (window-end win t)))
    
    (add-hook 'window-scroll-functions 'wsf-fn nil 'local)

The new function in window.c looks like this:

    DEFUN ("force-wsf", Fforce_wsf, Sforce_wsf, 0, 1, 0,
           doc: /* Set force_start so that redisplay_window will run the
    window-scroll-functions.  */)
      (Lisp_Object window)
    {
      register struct window *w = decode_live_window (window);
        w->optional_new_start = true;
        return;
    }

And, the there is one additional line that may also be required further on down 
in window.d:

  defsubr (&Sforce_wsf);

Thanks,

Keith

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

At Wed, 20 Jan 2016 15:34:41 +0200,
Eli Zaretskii wrote:
> 
> > . . . you need to call set-window-start with its 3rd
> argument omitted or nil.  Does that solve your problem?

Attachment: patch.diff
Description: application/diff


reply via email to

[Prev in Thread] Current Thread [Next in Thread]