From: Jan Djärv Date: Sat, 10 Apr 2010 12:37:06 +0000 (+0200) Subject: Make tab-mode a minor mode. X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=87691e6b61fb87f6602dcdeb6a4fb8bd8f6fee14;p=emacs.git Make tab-mode a minor mode. tab-show-always is new, to be a customize later on. --- diff --git a/README.TABS b/README.TABS index c08887a5186..f490dfaf30e 100644 --- a/README.TABS +++ b/README.TABS @@ -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) diff --git a/lisp/menu-bar.el b/lisp/menu-bar.el index d831744f311..f87eb5bcdcd 100644 --- a/lisp/menu-bar.el +++ b/lisp/menu-bar.el @@ -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") diff --git a/lisp/native-tabs.el b/lisp/native-tabs.el index 2471d873ee5..afd46a9124b 100644 --- a/lisp/native-tabs.el +++ b/lisp/native-tabs.el @@ -27,7 +27,36 @@ ;;; 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) + diff --git a/src/gtkutil.c b/src/gtkutil.c index 87e0883fe34..491b1a1c014 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -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, diff --git a/src/gtkutil.h b/src/gtkutil.h index 07a886e8e90..b005498e843 100644 --- a/src/gtkutil.h +++ b/src/gtkutil.h @@ -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, diff --git a/src/xfns.c b/src/xfns.c index c08fad851d4..b427b28d81c 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -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. */