]> git.eshelyaron.com Git - emacs.git/commitdiff
Make tab-mode a minor mode.
authorJan Djärv <jan.h.d@swipnet.se>
Sat, 10 Apr 2010 12:37:06 +0000 (14:37 +0200)
committerJan Djärv <jan.h.d@swipnet.se>
Sat, 10 Apr 2010 12:37:06 +0000 (14:37 +0200)
tab-show-always is new, to be a customize later on.

README.TABS
lisp/menu-bar.el
lisp/native-tabs.el
src/gtkutil.c
src/gtkutil.h
src/xfns.c

index c08887a5186844ad1a93e3487e3273338064ec6f..f490dfaf30e6df112fc2fc426b5fbe99be7ed0d5 100644 (file)
@@ -2,24 +2,15 @@ You can drag tabs to reorder them, drop them on another frame to move it there
 and drop on the root window to create a new frame.
 
 Frames created with frame parameter disable-tabs set to t will not have tabs.
-This parameter can't be toggeled at runtime, it must be set when creating
-the frame.
+This parameter can be toggeled at runtime.
 
-Lisp code is in native-tabs.el.  Keybindings are:
+The lisp interface is in xfns.c and native-tabs.el
 
-      (global-set-key "\C-x7\C-f" 'find-file-new-tab)
-      (global-set-key "\C-x70" 'tab-delete)
-      (global-set-key "\C-x71" 'tab-delete-other)
-      (global-set-key "\C-x72" 'tab-new)
-      (global-set-key "\C-x73" 'switch-to-buffer-tab)
-      (global-set-key "\C-x7b" 'switch-to-buffer-other-tab)
-      (global-set-key "\C-x7f" 'find-file-new-tab)
-      (global-set-key "\C-x7o" 'tab-next)
-      (global-set-key "\C-x7n" 'tab<-next)
-      (global-set-key "\C-x7p" 'tab-previous)))
+To turn tabs off (default is on), use the menu Options => Show/Hide or
+customise tab-mode.
+C-h f tab-mode to see keybindings.
 
-
-The lisp interface is mostly in xfns.c:
+Some functions:
 
 (find-file-new-tab FILENAME &optional WILDCARDS)
 (tab-new &optional LABEL FRAME)
@@ -31,6 +22,8 @@ The lisp interface is mostly in xfns.c:
 (tab-nr-of-tabs &optional FRAME)
 (tab-configuration &optional FRAME)
 (tab-current &optional FRAME)
-(tab-show KEY FRAME)
+(tab-show KEY &optional FRAME)
+(tab-enable ENABLE &optional FRAME)
+(tab-show-always SHOW)
 (switch-to-buffer-tab BUFFER-OR-NAME &optional FRAME)
 (switch-to-buffer-other-tab BUFFER-OR-NAME &optional NORECORD)
index d831744f31139d2aa7fd9a1a634a91723fef7255..f87eb5bcdcdbfe0662bb10cb10c4addd6066c58f 100644 (file)
@@ -970,6 +970,12 @@ mail status in mode line"))
              :visible (and (display-graphic-p) (fboundp 'x-show-tip))
              :button (:toggle . tooltip-mode)))
 
+(define-key menu-bar-showhide-menu [showhide-tabs]
+  `(menu-item ,(purecopy "Tabs") tab-mode
+             :help ,(purecopy "Turn tab on/off")
+             :visible (and (display-graphic-p) (featurep 'tabs))
+             :button (:toggle . tab-mode)))
+
 (define-key menu-bar-showhide-menu [menu-bar-mode]
   `(menu-item ,(purecopy "Menu-bar") toggle-menu-bar-mode-from-frame
              :help ,(purecopy "Turn menu-bar on/off")
index 2471d873ee55695149112b327ee5b2ed828c9d45..afd46a9124b939435c39a7792c31f27dfa4411ac 100644 (file)
 
 ;;; Code:
 
-;;; Customizable variables
+(defvar tab-mode-map
+  (let ((map (make-sparse-keymap)))
+    (define-key map "\C-x7\C-f" 'find-file-new-tab)
+    (define-key map "\C-x70" 'tab-delete)
+    (define-key map "\C-x71" 'tab-delete-other)
+    (define-key map "\C-x72" 'tab-new)
+    (define-key map "\C-x73" 'switch-to-buffer-tab)
+    (define-key map "\C-x7b" 'switch-to-buffer-other-tab)
+    (define-key map "\C-x7f" 'find-file-new-tab)
+    (define-key map "\C-x7o" 'tab-next)
+    (define-key map "\C-x7n" 'tab-next)
+    (define-key map "\C-x7p" 'tab-previous)
+    map)
+  "Keymap for `tab-mode´")
+
+;;;###autoload
+(define-minor-mode tab-mode
+  "Toggle use of tabs.
+This command applies to all frames that exist and frames to be
+created in the future.
+With numeric ARG, use tabs if and only if ARG is positive.
+
+Keyboard commands for tabs are:
+\\{tab-mode-map}."
+  :init-value t
+  :global t
+  :group 'mouse
+  :group 'frames
+  :keymap tab-mode-map
+  (modify-all-frames-parameters (list (cons 'disable-tabs (not tab-mode)))))
 
 (declare-function tab-new "xfns.c" ())
 (declare-function tab-delete "xfns.c" ())
@@ -38,6 +67,7 @@
 (declare-function tab-configuration "xfns.c" ())
 (declare-function tab-current "xfns.c" ())
 (declare-function tab-show "xfns.c" ())
+(declare-function tab-enable "xfns.c" ())
 
 (defun find-file-new-tab (filename &optional wildcards)
   "Edit file FILENAME, in a new tab.
@@ -131,7 +161,7 @@ BUFFER-OR-NAME."
         (frame (car n1))
         (x (car (cdr n1)))
         (y (cdr (cdr n1))))
-    (if (eq type 2) 
+    (if (eq type 2) ;; // A tab is dropped from another frame.
        (let ((top y)
              (left x)
              (width (frame-pixel-width frame))
@@ -148,18 +178,6 @@ BUFFER-OR-NAME."
                 (cons 'top top)
                 (cons 'left left)))))))
 
-(if (featurep 'tabs)
-    (progn
-      (define-key special-event-map [tab-event]
-       'handle-tab-event)
-      (global-set-key "\C-x7\C-f" 'find-file-new-tab)
-      (global-set-key "\C-x70" 'tab-delete)
-      (global-set-key "\C-x71" 'tab-delete-other)
-      (global-set-key "\C-x72" 'tab-new)
-      (global-set-key "\C-x73" 'switch-to-buffer-tab)
-      (global-set-key "\C-x7b" 'switch-to-buffer-other-tab)
-      (global-set-key "\C-x7f" 'find-file-new-tab)
-      (global-set-key "\C-x7o" 'tab-next)
-      (global-set-key "\C-x7n" 'tab-next)
-      (global-set-key "\C-x7p" 'tab-previous)))
+(define-key special-event-map [tab-event] 'handle-tab-event)
+
 
index 87e0883fe3458a153d384a0d71edab3d263d8aed..491b1a1c01417909db32e671d8d7378c54088125 100644 (file)
@@ -763,7 +763,10 @@ static int xg_tab_nr;
 static xg_list_node tabs_gc_list;
 static GtkNotebook* notebook_on_hold;
 
-typedef struct tabs_gc_data_
+/* If 1, show tabs even if there is only one tab.  */
+static int xg_always_show_tabs;
+
+typedef struct
 {
   xg_list_node  ptrs;
   Lisp_Object object;
@@ -791,13 +794,14 @@ xg_check_show_tabs (FRAME_PTR f,
 {
   gboolean shown = gtk_notebook_get_show_tabs (wnote);
   int pages = gtk_notebook_get_n_pages (wnote);
-
-  if ((shown && pages == 1) || (!shown && pages > 1)) 
+  int should_show = pages > 1 || xg_always_show_tabs;
+  
+  if ((shown && !should_show) || (!shown && should_show)) 
     {
       GtkRequisition req;
       int oldheight, row_add = 0;
 
-      gtk_notebook_set_show_tabs (wnote, pages > 1);
+      gtk_notebook_set_show_tabs (wnote, should_show);
       oldheight = FRAME_TABS_HEIGHT (f);
 
       gtk_widget_size_request (f->output_data.x->notebook_widget, &req);
@@ -814,15 +818,14 @@ xg_check_show_tabs (FRAME_PTR f,
       if (oldheight > 0 && FRAME_LINE_HEIGHT (f) > 0)
         {
           row_add = oldheight/FRAME_LINE_HEIGHT (f);
-          if (row_add * FRAME_LINE_HEIGHT (f) != oldheight)
-            --row_add;
         }
       else if (FRAME_TABS_HEIGHT (f) > 0 && FRAME_LINE_HEIGHT (f) > 0)
         {
           row_add = -(FRAME_TABS_HEIGHT (f)/FRAME_LINE_HEIGHT (f));
         }
 
-      xg_frame_set_char_size (f, FRAME_COLS (f), FRAME_LINES (f) + row_add);
+      if (row_add != 0)
+        xg_frame_set_char_size (f, FRAME_COLS (f), FRAME_LINES (f) + row_add);
     }
 }
 
@@ -1334,6 +1337,18 @@ xg_tab_get_win_config (FRAME_PTR f, int nr)
   return conf ? conf->object : Qnil;
 }
 
+void
+xg_tabs_always_show (FRAME_PTR f, int show)
+{
+  if (f == 0)
+    xg_always_show_tabs = show;
+  else
+    {
+      GtkNotebook *wnote = GTK_NOTEBOOK (f->output_data.x->notebook_widget);
+      if (wnote) xg_check_show_tabs (f, wnote);
+    }
+}
+
 static void
 xg_setup_notebook (FRAME_PTR f, GtkWidget *wvbox, GtkWidget *wnote)
 {
@@ -1355,7 +1370,7 @@ xg_setup_notebook (FRAME_PTR f, GtkWidget *wvbox, GtkWidget *wnote)
 #else
   gtk_notebook_set_group_id (GTK_NOTEBOOK (wnote), 1);
 #endif
-  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (wnote), FALSE);
+  gtk_notebook_set_show_tabs (GTK_NOTEBOOK (wnote), xg_always_show_tabs);
 
   style = gtk_widget_get_modifier_style (wnote);
   style->xthickness = style->ythickness = 0;
@@ -4925,6 +4940,7 @@ xg_initialize ()
   id_to_widget.widgets = 0;
   xg_tab_nr = 1;
   tabs_gc_list.prev = tabs_gc_list.next = 0;
+  xg_always_show_tabs = 0;
 
   /* Remove F10 as a menu accelerator, it does not mix well with Emacs key
      bindings.  It doesn't seem to be any way to remove properties,
index 07a886e8e90125bd0538980df7e35a8c20e63c71..b005498e84310b639a6e558c8a6e21cfe943755f 100644 (file)
@@ -148,6 +148,8 @@ extern void xg_set_current_tab P_ ((FRAME_PTR f, const char *key));
 extern void xg_enable_tabs P_ ((FRAME_PTR f, int enable));
 
 extern Lisp_Object xg_tab_get_win_config P_ ((FRAME_PTR f, int nr));
+extern void xg_tabs_always_show P_ ((FRAME_PTR f, int show));
+
 
 extern GtkWidget *xg_create_widget P_ ((char *type,
                                         char *name,
index c08fad851d43a810f28073ba27951555278ac829..b427b28d81c14b3b06596f234d5ed43eca6d866f 100644 (file)
@@ -746,15 +746,12 @@ x_set_notabs (f, new_value, old_value)
      struct frame *f;
      Lisp_Object new_value, old_value;
 {
-  if (! EQ (new_value, old_value))
-    {
-      f->no_tabs = !NILP (new_value);
+  f->no_tabs = !NILP (new_value);
 #ifdef USE_GTK
-      BLOCK_INPUT;
-      xg_enable_tabs (f, NILP (new_value));
-      UNBLOCK_INPUT;
+  BLOCK_INPUT;
+  xg_enable_tabs (f, NILP (new_value));
+  UNBLOCK_INPUT;
 #endif
-    }
 }
 
 #ifdef USE_GTK
@@ -6100,7 +6097,7 @@ DEFUN ("tab-enable", Ftab_enable,
        Stab_enable, 1, 2, 0,
        doc: /* Enable or disable tabs on FRAME.
 FRAME nil means use the selected frame.
-If enable is non-nil, enable tabs.  If it is nil, disable tabs.  */)
+If ENABLE is non-nil, enable tabs.  If it is nil, disable tabs.  */)
      (enable, frame)
      Lisp_Object enable, frame;
 {
@@ -6109,6 +6106,26 @@ If enable is non-nil, enable tabs.  If it is nil, disable tabs.  */)
   return Qnil;
 }
 
+DEFUN ("tab-show-always", Ftab_show_always,
+       Stab_show_always, 1, 1, 0,
+       doc: /* Set if tabs always should be visible on frames.
+If SHOW is non-nil, always show tabs.  If it is nil, show tabs if there are
+more than one.  */)
+     (show)
+     Lisp_Object show;
+{
+  xg_tabs_always_show (0, NILP (show));
+  Lisp_Object rest, frame;
+  FOR_EACH_FRAME (rest, frame)
+    {
+      struct frame *f = XFRAME (frame);
+      xg_tabs_always_show (f, !NILP (show));
+    }
+
+  return Qnil;
+}
+
+
 #endif
 
 void
@@ -6281,7 +6298,7 @@ the tool bar buttons.  */);
   defsubr (&Stab_current);
   defsubr (&Stab_show);
   defsubr (&Stab_enable);
-
+  defsubr (&Stab_show_always);
 #endif /* USE_GTK */
 
   /* X window properties.  */