(defhydra windows (global-map "C-c w" :post flash-active-buffer)
  "window moving"
  ("o" other-window "other"))

(make-face 'flash-active-buffer-face)
(set-face-attribute 'flash-active-buffer-face nil
                    :background "red"
                    :foreground "black")
(defun flash-active-buffer ()
  (run-at-time "250 millisec" nil
               (lambda (remap-cookie)
                 (face-remap-remove-relative remap-cookie))
               (face-remap-add-relative 'default 'flash-active-buffer-face)))

The above works as you'd expect: when the hydra exits, the final window flashes. What I'd like is to flash the window as the focus moves about the frame. However, instead of flashing the window, it will leave all other windows with the flash-color (in this case, completely red).

How can I get each window to flash as expected when using :pre?


To highlight after each switch, even when the hydra hasn't exited yet, you can use this:

(defhydra windows (global-map "C-c w"
                   :after-exit flash-active-buffer)
  "window moving"
  ("o" other-window "other"))

Another approach, which I think is actually better, since it's more straight forward:

(defhydra windows (global-map "C-c w")
  "window moving"
     (other-window 1)
     (flash-active-buffer)) "other"))

A lot of similar info is summarized on the internals wiki page, :after-exit is there as well.

  • Nice! I guess I just misunderstood the docs :) Note: in order for this application of hydra to work well, you should shorten the flash. I have it set now for 50ms Jul 7 '15 at 14:34
  • I'd recommend to rewrite flash-active-buffer with overlays, since you can specify the window in which the overlay is visible. Your current approach works badly if there are many windows with the same buffer.
    – abo-abo
    Jul 7 '15 at 14:41
  • It does indeed work badly -- but it's honestly a function I stole from someone else. Emacs' display architecture is not something I've invested time in understanding yet. Jul 7 '15 at 14:48
  • See avy--make-backgrounds - you can use it almost without change.
    – abo-abo
    Jul 7 '15 at 14:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.