3

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?

  • Maybe set up your window manager to (better) highlight the currently active window? This is already the default behavior in most window managers I have tried, but some have a default color scheme in which the highlight is barely noticeable. – tripleee Jul 16 '13 at 7:13
  • 2
    He is talking of 'emacs windows', they are not the same as the windows we usually mean. A WM window is an 'emacs frame'. And emacs frames can be split into 'emacs windows' (vertical/horizontal splits). – ahilsend Jul 16 '13 at 7:19
3

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).

https://github.com/N-Mi/e-other-window

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.

2

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:

(global-hl-line-mode 1)

Take a look at the Emacswiki: HighlightCurrentLine. It also mentions other minor-modes that might be more in your interest.


Edit:

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)

Edit2:

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 toggle-crosshairs-when-idle.

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 switch-to-buffer)

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 ...

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.