Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid `ement-room-list-auto-update' repeatedly rebuilding the buffer if it is not being disaplayed #261

Closed
phil-s opened this issue Feb 4, 2024 · 2 comments

Comments

@phil-s
Copy link

phil-s commented Feb 4, 2024

I've just written the following, which I think could be adapted to standard behaviour.

What do you think of the idea of just not updating unless/until the buffer is visible?

(define-advice ement-room-list-auto-update (:around (orig-fun &rest args) my-ignore-hidden)
  "Do nothing at all if *Ement Room List* is not currently displayed.

This is :around advice for `ement-room-list-auto-update'.  Remove with:
\(advice-remove \\='ement-room-list-auto-update
               \\='ement-room-list-auto-update@my-ignore-hidden)"
  (when-let ((buf (get-buffer "*Ement Room List*")))
    (if (get-buffer-window buf 'visible)
        (apply orig-fun args)
      ;; The next time that a window-configuration change results in the buffer
      ;; being displayed in a window, call the specified function (with the
      ;; window selected and the buffer set as current).  Because the function
      ;; removes itself from the buffer-local hook value, it only triggers once.
      (with-current-buffer buf
        (add-hook 'window-configuration-change-hook
                  #'my-ement-room-list-auto-update-now nil :local)))))

(defun my-ement-room-list-auto-update-now ()
  "Called via `window-configuration-change-hook'.
See `ement-room-list-auto-update@my-ignore-hidden'."
  (remove-hook 'window-configuration-change-hook
               #'my-ement-room-list-auto-update-now :local)
  (ement-room-list-auto-update nil))  
@alphapapa
Copy link
Owner

Well, obviously I would prefer to avoid hacks like this if possible. AFAIK the intention is still to debounce the room-list updating, i.e. #197. Do we (or do some users) need both? Or is this an alternative to that?

@phil-s
Copy link
Author

phil-s commented Feb 6, 2024

Oh, yeah -- I was forgetting about that tbh. Your comment cross-references the two, so I guess I'll just close this.

@phil-s phil-s closed this as completed Feb 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants