Is there a way for the code inside of an :eval
form in the modeline format spec to determine whether the modeline will be drawn with the active or inactive face? I'd like part of the modeline to display differently based on whether its active or inactive. I speciafically don't want to use advice, since the code will end up being used in a package.
(eq (get-buffer-window) (selected-window))
always returns true from the code run in mode-line-format
, so that doesn't seem to do the trick. I also tried adding a hook to buffer-list-change-hook
as suggested by the manual, but that doesn't do; somehow some updates are missed.
Is there a way to check from the :eval
portion of a modeline format spec whether the window is selected?`
(Based on the following code I'll bet no, but I'd love to be proven wrong:)
Lisp_Object old_selected_window = selected_window;
Lisp_Object old_selected_frame = selected_frame;
Lisp_Object new_frame = w->frame;
Lisp_Object old_frame_selected_window = XFRAME (new_frame)->selected_window;
int n = 0;
selected_frame = new_frame;
/* FIXME: If we were to allow the mode-line's computation changing the buffer
or window's point, then we'd need select_window_1 here as well. */
XSETWINDOW (selected_window, w);
XFRAME (new_frame)->selected_window = selected_window;
/* These will be set while the mode line specs are processed. */
line_number_displayed = false;
w->column_number_displayed = -1;
if (WINDOW_WANTS_MODELINE_P (w))
{
struct window *sel_w = XWINDOW (old_selected_window);
/* Select mode line face based on the real selected window. */
display_mode_line (w, CURRENT_MODE_LINE_FACE_ID_3 (sel_w, sel_w, w),
BVAR (current_buffer, mode_line_format));
++n;
}