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

Get wrong window size when hydra is active #409

Open
twlz0ne opened this issue Mar 4, 2022 · 1 comment
Open

Get wrong window size when hydra is active #409

twlz0ne opened this issue Mar 4, 2022 · 1 comment

Comments

@twlz0ne
Copy link

twlz0ne commented Mar 4, 2022

That makes scroll-{up,down} unable to reach the top and bottom of the buffer.

emacs-hydra-window-size-issue

Reproduction script:

(setq user-emacs-directory (make-temp-file "temp-emacs-dir--" 'tmpdir "/"))
(setq package-user-dir (concat user-emacs-directory "elpa/"))

;; Add hydra source code
(add-to-list 'load-path "~/repos/emacs-hydra")

;; ---------------------------------------------------------------------------

(require 'hydra)

(defvar hydra-active-p nil)

(define-advice scroll-up (:before (&optional arg) debug)
  (message "==> [scroll up] buffer: %s, window height: %s, hydra-active-p: %s"
           (current-buffer) (window-height) hydra-active-p))

(define-advice scroll-down (:before (&optional arg) debug)
  (message "==> [scroll down] buffer: %s, window height: %s, hydra-active-p: %s"
           (current-buffer) (window-height) hydra-active-p))

(defhydra hydra-scroll (:hint nil)
    "
  1
  2
  3
  4
  5               _C-v_: Scroll up
  6               _M-v_: Scrool down
  7
  8
  9
 10
"
    ("C-v" (let ((hydra-active-p t)) (scroll-up)))
    ("M-v" (let ((hydra-active-p t)) (scroll-down))))

(global-set-key (kbd "C-c h") #'hydra-scroll/body)

(add-hook 'emacs-startup-hook
          (lambda ()
            (display-line-numbers-mode 1)
            (view-echo-area-messages)
            (save-excursion
              (insert "\
Steps to reproduce:

1. Press C-v to scroll window
2. Check the window height printed in *Messages* buffer.
3. Press C-c h to active hydra
4. Press C-v to scroll window
5. Check the window height printed in *Messages* buffer.

The window height of the two prints should be different."))))
  • macOS 10.13.6
  • Emacs 29.0.50
  • lv & hydra 9e9e00c (2022-01-02)
@twlz0ne
Copy link
Author

twlz0ne commented Mar 4, 2022

The correct window size can be get in the timer:

-   ("C-v" (let ((hydra-active-p t)) (scroll-up)))
+   ("C-v" (run-with-timer 0 nil (lambda ()
+                                  (let ((hydra-active-p t))
+                                    (scroll-up)))))

emacs-hydra-window-size-issue-2

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

1 participant