19

I'm writing an extension that talks to an outside process, so it is a given to lower the amount of 'hey whats up' requests when my buffer isn't focused.

So, what is the best way to recognize:

  1. When my buffer is visible and focused
  2. When my buffer is visible but not focused
  3. When my buffer is neither visible nor focused
2
  • Clarifying question: do you mean "how does the outside process recognize" these characteristics?
    – Dan
    Commented Nov 1, 2014 at 13:55
  • @Dan I think he has a function being run as an idle timer, and needs to know from this function.
    – Malabarba
    Commented Nov 1, 2014 at 14:53

1 Answer 1

28
  • window-buffer returns the buffer currently displayed by a given window.

  • get-buffer-window, on the contrary, returns a window currently displaying the given buffer (or nil if there is no such window; play with the optional 2nd argument to tell it how to behave in cases where you have multiple frames).

With these two ingredients, you should be able to discriminate all your cases:

;; my-buffer is supposed to be the buffer you are looking for
(cond ((eq my-buffer (window-buffer (selected-window)))
       (message "Visible and focused"))
      ((get-buffer-window my-buffer)
       (message "Visible and unfocused")) 
      (t
       (message "Not visible")))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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