I've started splitting my emacs frame into two side-by-side windows, but often I'm unable to tell at a glance which window the cursor is currently in. I've bound the other-window command to a special key, so it's easy to hit that -- would there be a way to flash the cursor maybe three times right after switching to the other window? Or maybe there are better solutions people have thought of?
I was looking for an old Emacs package named
e-other-window and found this question while searching on the net. Finally, I had to dig in my previous computer and found it again, so I just uploaded it on Github to share it to everyone (that's the best backup I can make of it).
e-other-window.el --- flash windows when you change to them
This is a small usefull Emacs package from Kevin A. Burton that flashes the current window when switching from a window to another using a keybinding.
Combined with hl-line-mode, I find it very easy to find where is the cursor in a 2, 3 or 4 windows frame.
I find it helps to have emacs highlight the current line.
The minor mode hl-line-mode does that. You can enable it in your current buffer with M-x
hl-line-mode, or globally from your emacs config:
Take a look at the Emacswiki: HighlightCurrentLine. It also mentions other minor-modes that might be more in your interest.
While looking through the wiki myself I found the crosshairs-mode. I think I'll try it out myself:
(crosshairs-mode 1) (setq col-highlight-vline-face-flag t col-highlight-face hl-line-face)
I like the horizontal line, but I find the constant vertical line distracting. Luckily
crosshairs also provides a flash function
flash-crosshairs and an idle mode
To display the crosshair on idle I have this in my config:
(require 'crosshairs) (toggle-crosshairs-when-idle 1) (setq col-highlight-vline-face-flag t col-highlight-face hl-line-face)
But this won't flash on buffer/window switches, unfortunately there are no hooks for that. But at least emacs lisp gives us advising functions, which allow us to extend existing functions. Though that can be quite tricky.
This will flash the crosshair after buffer switches:
(defadvice switch-to-buffer (after switch-to-buffer-flash-crosshairs activate) "Call `flash-crosshairs' after `switch-to-buffer'" (flash-crosshairs))
This should work in most cases (when the switch is done without
The window switch is more difficult, since minibuffers (open file etc.) cause some issues. So only flash when we switch to another buffer:
(defadvice select-window (around select-window-flash-crosshairs activate) "Call `flash-crosshairs' after `select-window', if switching to another buffer. The check is necessary to prevent issues with mini-buffer switching." (let (cons (cur-buffer-name (buffer-name (current-buffer))) ad-arg-bindings) ad-do-it (unless (string= (buffer-name (window-buffer window)) cur-buffer-name) (flash-crosshairs))))
ad-arg-bindings are the arguments to the advised function and
ad-do-it executes the original.
To deactivate the advices use:
(ad-remove-advice 'select-window 'around 'select-window-flash-crosshairs) (ad-remove-advice 'switch-to-buffer 'after 'switch-to-buffer-flash-crosshairs)
I think that covers most cases, though like I said advising is tricky ...