emacs-devel
[Top][All Lists]
Advanced

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

Re: 27.0.50: How can I test a buffer-local window-configuration-change-h


From: Phil Sainty
Subject: Re: 27.0.50: How can I test a buffer-local window-configuration-change-hook in batch mode?
Date: Fri, 25 Oct 2019 23:54:19 +1300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

Hi Martin,

On 25/10/19 9:51 PM, martin rudalics wrote:
> Could you please provide a more realistic example for the function you
> want to put on that hook than the
> 
>     (add-hook 'window-configuration-change-hook 'emacs-lisp-mode nil t)
> 
> from your initial example?  Then we might be able to come up with
> something more practical than invoking a hook explicitly.

The example is actually pretty close to the real use-case.  If so-long
sees a file with very long lines being visited, it (now) only triggers
its mitigations if and when that buffer is first displayed.  So if the
buffer is never displayed then nothing is done.

Here's the key part of the (non-test) library code:

https://git.savannah.nongnu.org/cgit/so-long.git/tree/so-long.el?h=1572000262&id=80ed099#n1591

(defun so-long-deferred ()
  "Arrange to call `so-long' if the current buffer is displayed
in a window."
  ;; The first time that a window-configuration change results in the
  ;; buffer being displayed in a window, `so-long' will be called
  ;; (with the window selected and the buffer set as current).
  ;; Because `so-long' removes this buffer-local hook value, it
  ;; triggers once at most.
  (add-hook 'window-configuration-change-hook #'so-long nil :local))


Where `so-long' itself (by default) is invoking a major mode.

(It *does* do more besides, but as I say -- not miles away from the
example I'd used.)


And the relevant part of the related test is:

  ;; Invisible buffer.
  (with-temp-buffer
    (insert "#!emacs\n")
    (normal-mode)
    (so-long-tests-remember)
    (insert (make-string (1+ so-long-threshold) ?x))
    (normal-mode)
    (should (eq major-mode 'emacs-lisp-mode))
    (should (eq nil (get-buffer-window)))
    ;; Displaying the buffer should invoke `so-long'.
    (display-buffer (current-buffer))
    (should (window-live-p (get-buffer-window)))
    (unless (version< emacs-version "27")
      ;; From Emacs 27 the `display-buffer' call is insufficient.
      ;; The various 'window change functions' are now invoked by the
      ;; redisplay, and redisplay does nothing at all in batch mode,
      ;; so we cannot test under this revised behaviour.  Refer to:
      ;;
https://lists.gnu.org/archive/html/emacs-devel/2019-10/msg00971.html
      ;; For interactive (non-batch) test runs, calling `redisplay'
      ;; does do the trick; so do that first.
      (redisplay)
      ;; In batch mode we need to cheat, and just pretend that
      ;; `redisplay' triggered `window-configuration-change-hook'.
      ;; Test `so-long--active' though, in case a future version of
      ;; Emacs adds the framework necessary to make this work.
      (when noninteractive
        (unless (eq so-long--active t)
          (run-window-configuration-change-hook))))
    (so-long-tests-assert-and-revert 'so-long-mode))


Without `run-window-configuration-change-hook' I'd have to replicate
some of that functionality myself, and the test would be getting even
further away from the real processes, and therefore becoming less and
less useful as a test.  I'd like to have to fake as little as possible.


-Phil



reply via email to

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