Skip to content

Conversation

@bcc32
Copy link

@bcc32 bcc32 commented Nov 26, 2025

Hook onto window-state-change-functions instead of buffer-list-update-hook, since the latter does not guarantee that a just-created buffer is actually current. So, a command like the following would create, display, and select a buffer wherein the ensure-override-mode-func is never executed:

(defun display-results ()
  (interactive)
  (let ((buffer (get-buffer-create "*results*")))
    (with-current-buffer buffer
      (insert "I ran a command, and here are the results..."))
    (display-buffer buffer '(display-buffer-same-window))))

This change also has the nice side benefit of skipping the hook if a buffer is never displayed, or the window displaying it is never selected.

Hook onto window-state-change-functions instead of
buffer-list-update-hook, since the latter does not guarantee that a
just-created buffer is actually current.  So, a command like the
following would create, display, and select a buffer wherein the
ensure-override-mode-func is never executed:

    (defun display-results ()
      (interactive)
      (let ((buffer (get-buffer-create "*results*")))
        (with-current-buffer buffer
          (insert "I ran a command, and here are the results..."))
        (display-buffer buffer '(display-buffer-same-window))))

This change also has the nice side benefit of skipping the hook if a
buffer is never displayed, or the window displaying it is never
selected.
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

Successfully merging this pull request may close these issues.

1 participant