emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] feature/tabs 2a016475: Don't use hook pre-redisplay-functi


From: Juri Linkov
Subject: [Emacs-diffs] feature/tabs 2a016475: Don't use hook pre-redisplay-functions. Set buffer-local tab-line-format.
Date: Thu, 5 Sep 2019 15:31:13 -0400 (EDT)

branch: feature/tabs
commit 2a0164753456d0f788aa026bdd903ac76519d6ab
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>

    Don't use hook pre-redisplay-functions.  Set buffer-local tab-line-format.
    
    * lisp/tab-line.el (tab-line-format): Move to C.
    (tab-line-update-window-parameter): Remove function.
    (global-tab-line-mode): Set the default value of tab-line-format.
    
    * src/buffer.c (syms_of_buffer): Define buffer-local variable
    tab-line-format.
    
    * src/buffer.h (struct buffer): Add tab_line_format_.
    
    * src/window.c (window_wants_tab_line):
    * src/xdisp.c (pos_visible_p, display_mode_lines):
    Check for buffer-local tab_line_format.
---
 lisp/tab-line.el | 22 ++--------------------
 src/buffer.c     | 14 ++++++++++++++
 src/buffer.h     |  4 ++++
 src/window.c     |  3 ++-
 src/xdisp.c      | 10 ++++++++--
 5 files changed, 30 insertions(+), 23 deletions(-)

diff --git a/lisp/tab-line.el b/lisp/tab-line.el
index c678ce5..92802b6 100644
--- a/lisp/tab-line.el
+++ b/lisp/tab-line.el
@@ -251,8 +251,6 @@ using the `previous-buffer' command."
       (force-mode-line-update))))
 
 
-(defvar tab-line-format '(:eval (tab-line-format)))
-
 ;;;###autoload
 (define-minor-mode global-tab-line-mode
   "Display window-local tab line."
@@ -260,24 +258,8 @@ using the `previous-buffer' command."
   :type 'boolean
   :global t
   :init-value nil
-  :initialize (lambda (sym val)
-                (custom-initialize-default sym val)
-                (when global-tab-line-mode
-                  (add-hook 'pre-redisplay-functions 
#'tab-line-update-window-parameter)))
-  (if global-tab-line-mode
-      (progn
-        (add-hook 'pre-redisplay-functions #'tab-line-update-window-parameter)
-        (force-mode-line-update))
-    (remove-hook 'pre-redisplay-functions #'tab-line-update-window-parameter)
-    (walk-windows (lambda (w) (tab-line-update-window-parameter w)) t)))
-
-(defun tab-line-update-window-parameter (window)
-  (let* ((name 'tab-line-format)
-         (value (window-parameter window name))
-         (active global-tab-line-mode))
-    (when (xor value active)
-      (set-window-parameter
-       window name (unless value tab-line-format)))))
+  (setq-default tab-line-format (when global-tab-line-mode
+                                  '(:eval (tab-line-format)))))
 
 
 (provide 'tab-line)
diff --git a/src/buffer.c b/src/buffer.c
index ad9feee..233a95c 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -249,6 +249,11 @@ bset_header_line_format (struct buffer *b, Lisp_Object val)
   b->header_line_format_ = val;
 }
 static void
+bset_tab_line_format (struct buffer *b, Lisp_Object val)
+{
+  b->tab_line_format_ = val;
+}
+static void
 bset_indicate_buffer_boundaries (struct buffer *b, Lisp_Object val)
 {
   b->indicate_buffer_boundaries_ = val;
@@ -5188,6 +5193,7 @@ init_buffer_once (void)
   XSETFASTINT (BVAR (&buffer_local_flags, scroll_up_aggressively), idx); ++idx;
   XSETFASTINT (BVAR (&buffer_local_flags, scroll_down_aggressively), idx); 
++idx;
   XSETFASTINT (BVAR (&buffer_local_flags, header_line_format), idx); ++idx;
+  XSETFASTINT (BVAR (&buffer_local_flags, tab_line_format), idx); ++idx;
   XSETFASTINT (BVAR (&buffer_local_flags, cursor_type), idx); ++idx;
   XSETFASTINT (BVAR (&buffer_local_flags, extra_line_spacing), idx); ++idx;
   XSETFASTINT (BVAR (&buffer_local_flags, cursor_in_non_selected_windows), 
idx); ++idx;
@@ -5233,6 +5239,7 @@ init_buffer_once (void)
   /* real setup is done in bindings.el */
   bset_mode_line_format (&buffer_defaults, build_pure_c_string ("%-"));
   bset_header_line_format (&buffer_defaults, Qnil);
+  bset_tab_line_format (&buffer_defaults, Qnil);
   bset_abbrev_mode (&buffer_defaults, Qnil);
   bset_overwrite_mode (&buffer_defaults, Qnil);
   bset_case_fold_search (&buffer_defaults, Qt);
@@ -5504,6 +5511,13 @@ syms_of_buffer (void)
   Fput (Qprotected_field, Qerror_message,
        build_pure_c_string ("Attempt to modify a protected field"));
 
+  DEFVAR_PER_BUFFER ("tab-line-format",
+                    &BVAR (current_buffer, tab_line_format),
+                    Qnil,
+                    doc: /* Analogous to `mode-line-format', but controls the 
tab line.
+The tab line appears, optionally, at the top of a window;
+the mode line appears at the bottom.  */);
+
   DEFVAR_PER_BUFFER ("header-line-format",
                     &BVAR (current_buffer, header_line_format),
                     Qnil,
diff --git a/src/buffer.h b/src/buffer.h
index 2080a6f..e411ab5 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -539,6 +539,10 @@ struct buffer
      of windows.  Nil means don't display that line.  */
   Lisp_Object header_line_format_;
 
+  /* Analogous to mode_line_format for the line displayed at the top
+     of windows.  Nil means don't display that line.  */
+  Lisp_Object tab_line_format_;
+
   /* Keys that are bound local to this buffer.  */
   Lisp_Object keymap_;
 
diff --git a/src/window.c b/src/window.c
index 30b53d1..6749ffd 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5419,7 +5419,8 @@ window_wants_tab_line (struct window *w)
           && !MINI_WINDOW_P (w)
           && !WINDOW_PSEUDO_P (w)
           && !EQ (window_tab_line_format, Qnone)
-          && !NILP (window_tab_line_format)
+          && (!NILP (window_tab_line_format)
+              || !NILP (BVAR (XBUFFER (WINDOW_BUFFER (w)), tab_line_format)))
           && (WINDOW_PIXEL_HEIGHT (w)
               > (((window_wants_mode_line (w) ? 1 : 0)
                    + (window_wants_header_line (w) ? 1 : 0)
diff --git a/src/xdisp.c b/src/xdisp.c
index eca47d2..9f999c7 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -1478,7 +1478,10 @@ pos_visible_p (struct window *w, ptrdiff_t charpos, int 
*x, int *y,
        = window_parameter (w, Qtab_line_format);
 
       w->tab_line_height
-       = display_mode_line (w, TAB_LINE_FACE_ID, window_tab_line_format);
+       = display_mode_line (w, TAB_LINE_FACE_ID,
+                            NILP (window_tab_line_format)
+                            ? BVAR (current_buffer, tab_line_format)
+                            : window_tab_line_format);
     }
 
   if (window_wants_header_line (w))
@@ -24743,7 +24746,10 @@ display_mode_lines (struct window *w)
       Lisp_Object window_tab_line_format
        = window_parameter (w, Qtab_line_format);
 
-      display_mode_line (w, TAB_LINE_FACE_ID, window_tab_line_format);
+      display_mode_line (w, TAB_LINE_FACE_ID,
+                        NILP (window_tab_line_format)
+                        ? BVAR (current_buffer, tab_line_format)
+                        : window_tab_line_format);
       ++n;
     }
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]