From: Dmitry Antipov Date: Wed, 14 Aug 2013 04:09:37 +0000 (+0400) Subject: Cleanup window fringes, margins and scroll bars adjustments. X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1686^2~261 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=25554267037ced56fdaed17e3a09d8926b70f978;p=emacs.git Cleanup window fringes, margins and scroll bars adjustments. * window.c (set_window_fringes, set_window_margins) (set_window_scroll_bars, apply_window_adjustment): New functions. (set_window_buffer, Fset_window_margins, Fset_window_fringes) (Fset_window_scroll_bars): Use them. --- diff --git a/src/ChangeLog b/src/ChangeLog index 7081236ec65..af088340e3b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,11 @@ +2013-08-14 Dmitry Antipov + + Cleanup window fringes, margins and scroll bars adjustments. + * window.c (set_window_fringes, set_window_margins) + (set_window_scroll_bars, apply_window_adjustment): New functions. + (set_window_buffer, Fset_window_margins, Fset_window_fringes) + (Fset_window_scroll_bars): Use them. + 2013-08-14 Dmitry Antipov * window.h (struct window): Convert scroll_bar_width diff --git a/src/window.c b/src/window.c index 7b2e9b08881..d07eed86a1c 100644 --- a/src/window.c +++ b/src/window.c @@ -87,6 +87,14 @@ static void window_resize_apply (struct window *, bool); static Lisp_Object select_window (Lisp_Object, Lisp_Object, int); static void select_window_1 (Lisp_Object, bool); +static struct window *set_window_fringes (struct window *, Lisp_Object, + Lisp_Object, Lisp_Object); +static struct window *set_window_margins (struct window *, Lisp_Object, + Lisp_Object); +static struct window *set_window_scroll_bars (struct window *, Lisp_Object, + Lisp_Object, Lisp_Object); +static void apply_window_adjustment (struct window *); + /* This is the window in which the terminal's cursor should be left when nothing is being done with it. This must always be a leaf window, and its buffer is selected by @@ -3202,28 +3210,14 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, if (!keep_margins_p) { /* Set left and right marginal area width etc. from buffer. */ - - /* This may call adjust_window_margins three times, so - temporarily disable window margins. */ - int save_left = w->left_margin_cols; - int save_right = w->right_margin_cols; - - w->left_margin_cols = 0; - w->right_margin_cols = 0; - - Fset_window_fringes (window, - BVAR (b, left_fringe_width), BVAR (b, right_fringe_width), - BVAR (b, fringes_outside_margins)); - - Fset_window_scroll_bars (window, - BVAR (b, scroll_bar_width), - BVAR (b, vertical_scroll_bar_type), Qnil); - - w->left_margin_cols = save_left; - w->right_margin_cols = save_right; - - Fset_window_margins (window, - BVAR (b, left_margin_cols), BVAR (b, right_margin_cols)); + set_window_fringes (w, BVAR (b, left_fringe_width), + BVAR (b, right_fringe_width), + BVAR (b, fringes_outside_margins)); + set_window_scroll_bars (w, BVAR (b, scroll_bar_width), + BVAR (b, vertical_scroll_bar_type), Qnil); + set_window_margins (w, BVAR (b, left_margin_cols), + BVAR (b, right_margin_cols)); + apply_window_adjustment (w); } if (run_hooks_p) @@ -6112,29 +6106,32 @@ saved by this function. */) XSETWINDOW_CONFIGURATION (tem, data); return (tem); } + +/* Called after W's margins, fringes or scroll bars was adjusted. */ + +static void +apply_window_adjustment (struct window *w) +{ + eassert (w); + adjust_window_margins (w); + clear_glyph_matrix (w->current_matrix); + w->window_end_valid = 0; + windows_or_buffers_changed++; + adjust_glyphs (XFRAME (WINDOW_FRAME (w))); +} + /*********************************************************************** Marginal Areas ***********************************************************************/ -DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, - 2, 3, 0, - doc: /* Set width of marginal areas of window WINDOW. -WINDOW must be a live window and defaults to the selected one. - -Second arg LEFT-WIDTH specifies the number of character cells to -reserve for the left marginal area. Optional third arg RIGHT-WIDTH -does the same for the right marginal area. A nil width parameter -means no margin. - -Return t if any margin was actually changed and nil otherwise. */) - (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width) +static struct window * +set_window_margins (struct window *w, Lisp_Object left_width, + Lisp_Object right_width) { - struct window *w = decode_live_window (window); int left, right; /* FIXME: what about margins that are too wide? */ - left = (NILP (left_width) ? 0 : (CHECK_NATNUM (left_width), XINT (left_width))); right = (NILP (right_width) ? 0 @@ -6144,15 +6141,27 @@ Return t if any margin was actually changed and nil otherwise. */) { w->left_margin_cols = left; w->right_margin_cols = right; + return w; + } + return NULL; +} - adjust_window_margins (w); +DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, + 2, 3, 0, + doc: /* Set width of marginal areas of window WINDOW. +WINDOW must be a live window and defaults to the selected one. - ++windows_or_buffers_changed; - adjust_glyphs (XFRAME (WINDOW_FRAME (w))); - return Qt; - } +Second arg LEFT-WIDTH specifies the number of character cells to +reserve for the left marginal area. Optional third arg RIGHT-WIDTH +does the same for the right marginal area. A nil width parameter +means no margin. - return Qnil; +Return t if any margin was actually changed and nil otherwise. */) + (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width) +{ + struct window *w = set_window_margins (decode_live_window (window), + left_width, right_width); + return w ? (apply_window_adjustment (w), Qt) : Qnil; } @@ -6177,25 +6186,10 @@ as nil. */) Fringes ***********************************************************************/ -DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes, - 2, 4, 0, - doc: /* Set the fringe widths of window WINDOW. -WINDOW must be a live window and defaults to the selected one. - -Second arg LEFT-WIDTH specifies the number of pixels to reserve for -the left fringe. Optional third arg RIGHT-WIDTH specifies the right -fringe width. If a fringe width arg is nil, that means to use the -frame's default fringe width. Default fringe widths can be set with -the command `set-fringe-style'. -If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes -outside of the display margins. By default, fringes are drawn between -display marginal areas and the text area. - -Return t if any fringe was actually changed and nil otherwise. */) - (Lisp_Object window, Lisp_Object left_width, - Lisp_Object right_width, Lisp_Object outside_margins) +static struct window * +set_window_fringes (struct window *w, Lisp_Object left_width, + Lisp_Object right_width, Lisp_Object outside_margins) { - struct window *w = decode_live_window (window); int left, right, outside = !NILP (outside_margins); left = (NILP (left_width) ? -1 @@ -6212,18 +6206,33 @@ Return t if any fringe was actually changed and nil otherwise. */) w->left_fringe_width = left; w->right_fringe_width = right; w->fringes_outside_margins = outside; + return w; + } + return NULL; +} - adjust_window_margins (w); - - clear_glyph_matrix (w->current_matrix); - w->window_end_valid = 0; +DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes, + 2, 4, 0, + doc: /* Set the fringe widths of window WINDOW. +WINDOW must be a live window and defaults to the selected one. - ++windows_or_buffers_changed; - adjust_glyphs (XFRAME (WINDOW_FRAME (w))); - return Qt; - } +Second arg LEFT-WIDTH specifies the number of pixels to reserve for +the left fringe. Optional third arg RIGHT-WIDTH specifies the right +fringe width. If a fringe width arg is nil, that means to use the +frame's default fringe width. Default fringe widths can be set with +the command `set-fringe-style'. +If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes +outside of the display margins. By default, fringes are drawn between +display marginal areas and the text area. - return Qnil; +Return t if any fringe was actually changed and nil otherwise. */) + (Lisp_Object window, Lisp_Object left_width, + Lisp_Object right_width, Lisp_Object outside_margins) +{ + struct window *w + = set_window_fringes (decode_live_window (window), + left_width, right_width, outside_margins); + return w ? (apply_window_adjustment (w), Qt) : Qnil; } @@ -6248,24 +6257,10 @@ Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */) Scroll bars ***********************************************************************/ -DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, - Sset_window_scroll_bars, 2, 4, 0, - doc: /* Set width and type of scroll bars of window WINDOW. -WINDOW must be a live window and defaults to the selected one. - -Second parameter WIDTH specifies the pixel width for the scroll bar; -this is automatically adjusted to a multiple of the frame column width. -Third parameter VERTICAL-TYPE specifies the type of the vertical scroll -bar: left, right, or nil. -If WIDTH is nil, use the frame's scroll-bar width. -If VERTICAL-TYPE is t, use the frame's scroll-bar type. -Fourth parameter HORIZONTAL-TYPE is currently unused. - -Return t if scroll bars was actually changed and nil otherwise. */) - (Lisp_Object window, Lisp_Object width, - Lisp_Object vertical_type, Lisp_Object horizontal_type) +static struct window * +set_window_scroll_bars (struct window *w, Lisp_Object width, + Lisp_Object vertical_type, Lisp_Object horizontal_type) { - struct window *w = decode_live_window (window); int iwidth = (NILP (width) ? -1 : (CHECK_NATNUM (width), XINT (width))); if (iwidth == 0) @@ -6282,18 +6277,32 @@ Return t if scroll bars was actually changed and nil otherwise. */) { w->scroll_bar_width = iwidth; wset_vertical_scroll_bar_type (w, vertical_type); + return w; + } + return NULL; +} - adjust_window_margins (w); - - clear_glyph_matrix (w->current_matrix); - w->window_end_valid = 0; +DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, + Sset_window_scroll_bars, 2, 4, 0, + doc: /* Set width and type of scroll bars of window WINDOW. +WINDOW must be a live window and defaults to the selected one. - ++windows_or_buffers_changed; - adjust_glyphs (XFRAME (WINDOW_FRAME (w))); - return Qt; - } +Second parameter WIDTH specifies the pixel width for the scroll bar; +this is automatically adjusted to a multiple of the frame column width. +Third parameter VERTICAL-TYPE specifies the type of the vertical scroll +bar: left, right, or nil. +If WIDTH is nil, use the frame's scroll-bar width. +If VERTICAL-TYPE is t, use the frame's scroll-bar type. +Fourth parameter HORIZONTAL-TYPE is currently unused. - return Qnil; +Return t if scroll bars was actually changed and nil otherwise. */) + (Lisp_Object window, Lisp_Object width, + Lisp_Object vertical_type, Lisp_Object horizontal_type) +{ + struct window *w + = set_window_scroll_bars (decode_live_window (window), + width, vertical_type, horizontal_type); + return w ? (apply_window_adjustment (w), Qt) : Qnil; }