3

I want to display a few lines at the top of a specific buffer, no matter how much the user has scrolled down (basically, a multi-line version of a header line). Moreover, I want these lines to be visible if and only if that buffer is visible (e.g. if I switch to a different buffer, the lines should disappear. When I switch back, they should be visible again).

(The specific use case I have is a weekly calendar view. The user can scroll to see different hours of the day, but I want the days of the week, all-day events, navigation buttons, etc. to always be visible at the top.)

So far the closest I've got is using a posframe (which uses child frames). This can successfully display such a "multi line header", but the problem I ran into is when killing/changing buffers the posframe does not disappear. The posframe appears to be associated with the whole frame, rather than a specific buffer. I have not found a way to have a posframe appear if and only if a specific buffer is visible.

I would appreciate help on either making the posframes work, or an alternative method for a multi-line sticky header. Thanks!

1 Answer 1

1

I think a good way to 'fake' this is to use an atomic window and set the window parameters mode-line-format to none and no-other-window to t as follows:

(let* ((buf "*multi-line-header")
       (win (display-buffer-in-atom-window
            (get-buffer-create buf)
            '((side . above) (window-height . 3)))))
  (set-window-parameter win 'no-other-window t)
  (set-window-parameter win 'mode-line-format 'none)
  (with-current-buffer buf
    (insert (propertize "This is a fake\nmulti-line\nheader" 'face "warning"))))

I have simply modified the example for using display-buffer-in-atom-window. However, its docstring mentions that it should only be called by display-buffer or a similar function. So you might want to read about that (I guess it would be cleaner, but that it is not essential).

Also, you would have to find a way to automatically show the header-window, when switching to your 'base' buffer (I guess you could find some hook to use for that), and delete it when you switch buffer in your 'base' window. But I hope this anwer gets you on the way...

(As you still have to create and delete the window when switching buffers, I am not sure if it has to be an atomic window at all, it just 'feels' right. So you should still think about if this is really necessary)

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.