From: Dmitry Antipov Date: Tue, 13 Aug 2013 14:45:58 +0000 (+0400) Subject: * window.h (struct window): Convert left_margin_cols and X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1686^2~279 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=eeaf9bf3377b6d4b9083159726da8bb67b36cb56;p=emacs.git * window.h (struct window): Convert left_margin_cols and right_margin_cols from Lisp_Objects to integers. Adjust comment. (WINDOW_LEFT_MARGIN_COLS, WINDOW_RIGHT_MARGIN_COLS) (WINDOW_LEFT_MARGIN_WIDTH, WINDOW_RIGHT_MARGIN_WIDTH): Adjust users. * dispnew.c (margin_glyphs_to_reserve): Convert 3rd arg to int. Adjust comment. (showing_window_margins_p, update_window_line, update_frame_1): * fringe.c (draw_fringe_bitmap_1): * xdisp.c (window_box_width): Adjust users. * window.c (wset_left_margin_cols, wset_right_margin_cols): Remove. (adjust_window_margins, set_window_buffer, Fsplit_window_internal): Use direct assignment. (Fset_window_configuration, save_window_save, Fwindow_margins): Convert Lisp_Object to integer and back where appropriate. (Fset_window_margins): Adjust user. Return t if any margin was actually changed, and mention this in docstring. --- diff --git a/src/ChangeLog b/src/ChangeLog index 28e8ab66e37..dabc6241967 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2013-08-13 Dmitry Antipov + + * window.h (struct window): Convert left_margin_cols and + right_margin_cols from Lisp_Objects to integers. Adjust comment. + (WINDOW_LEFT_MARGIN_COLS, WINDOW_RIGHT_MARGIN_COLS) + (WINDOW_LEFT_MARGIN_WIDTH, WINDOW_RIGHT_MARGIN_WIDTH): + Adjust users. + * dispnew.c (margin_glyphs_to_reserve): Convert 3rd arg to int. + Adjust comment. + (showing_window_margins_p, update_window_line, update_frame_1): + * fringe.c (draw_fringe_bitmap_1): + * xdisp.c (window_box_width): Adjust users. + * window.c (wset_left_margin_cols, wset_right_margin_cols): Remove. + (adjust_window_margins, set_window_buffer, Fsplit_window_internal): + Use direct assignment. + (Fset_window_configuration, save_window_save, Fwindow_margins): + Convert Lisp_Object to integer and back where appropriate. + (Fset_window_margins): Adjust user. Return t if any margin + was actually changed, and mention this in docstring. + 2013-08-13 Xue Fuqiao * syntax.c (forward_word): diff --git a/src/dispnew.c b/src/dispnew.c index 519659a104c..9b93a31e0b1 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -359,25 +359,19 @@ free_glyph_matrix (struct glyph_matrix *matrix) /* Return the number of glyphs to reserve for a marginal area of window W. TOTAL_GLYPHS is the number of glyphs in a complete display line of window W. MARGIN gives the width of the marginal - area in canonical character units. MARGIN should be an integer - or a float. */ + area in canonical character units. */ static int -margin_glyphs_to_reserve (struct window *w, int total_glyphs, Lisp_Object margin) +margin_glyphs_to_reserve (struct window *w, int total_glyphs, int margin) { - int n; - - if (NUMBERP (margin)) + if (margin > 0) { int width = w->total_cols; - double d = max (0, XFLOATINT (margin)); + double d = max (0, margin); d = min (width / 2 - 1, d); - n = (int) ((double) total_glyphs / width * d); + return (int) ((double) total_glyphs / width * d); } - else - n = 0; - - return n; + return 0; } /* Return true if ROW's hash value is correct. @@ -1867,7 +1861,7 @@ showing_window_margins_p (struct window *w) if (showing_window_margins_p (XWINDOW (w->contents))) return 1; } - else if (!NILP (w->left_margin_cols) || !NILP (w->right_margin_cols)) + else if (w->left_margin_cols > 0 || w->right_margin_cols > 0) return 1; w = NILP (w->next) ? 0 : XWINDOW (w->next); @@ -3807,8 +3801,7 @@ update_window_line (struct window *w, int vpos, bool *mouse_face_overwritten_p) eassert (desired_row->enabled_p); /* Update display of the left margin area, if there is one. */ - if (!desired_row->full_width_p - && !NILP (w->left_margin_cols)) + if (!desired_row->full_width_p && w->left_margin_cols > 0) { changed_p = 1; update_marginal_area (w, LEFT_MARGIN_AREA, vpos); @@ -3828,8 +3821,7 @@ update_window_line (struct window *w, int vpos, bool *mouse_face_overwritten_p) } /* Update display of the right margin area, if there is one. */ - if (!desired_row->full_width_p - && !NILP (w->right_margin_cols)) + if (!desired_row->full_width_p && w->right_margin_cols > 0) { changed_p = 1; update_marginal_area (w, RIGHT_MARGIN_AREA, vpos); @@ -4606,10 +4598,7 @@ update_frame_1 (struct frame *f, bool force_p, bool inhibit_id_p) int x = WINDOW_TO_FRAME_HPOS (w, w->cursor.hpos); int y = WINDOW_TO_FRAME_VPOS (w, w->cursor.vpos); - if (INTEGERP (w->left_margin_cols)) - x += XFASTINT (w->left_margin_cols); - - /* x = max (min (x, FRAME_TOTAL_COLS (f) - 1), 0); */ + x += max (0, w->left_margin_cols); cursor_to (f, y, x); } } diff --git a/src/fringe.c b/src/fringe.c index 1d05244e64e..492eddae8d4 100644 --- a/src/fringe.c +++ b/src/fringe.c @@ -666,7 +666,7 @@ draw_fringe_bitmap_1 (struct window *w, struct glyph_row *row, int left_p, int o and OTOH leaving out that one pixel leaves behind traces of the cursor, if it was in column zero before drawing non-empty margin area. */ - && NILP (w->left_margin_cols)) + && w->left_margin_cols == 0) ? 1 : 0); p.bx = x - wd; p.nx = wd; diff --git a/src/window.c b/src/window.c index 6de93b077ca..b33dc328983 100644 --- a/src/window.c +++ b/src/window.c @@ -151,11 +151,6 @@ wset_display_table (struct window *w, Lisp_Object val) w->display_table = val; } static void -wset_left_margin_cols (struct window *w, Lisp_Object val) -{ - w->left_margin_cols = val; -} -static void wset_new_normal (struct window *w, Lisp_Object val) { w->new_normal = val; @@ -186,11 +181,6 @@ wset_pointm (struct window *w, Lisp_Object val) w->pointm = val; } static void -wset_right_margin_cols (struct window *w, Lisp_Object val) -{ - w->right_margin_cols = val; -} -static void wset_scroll_bar_width (struct window *w, Lisp_Object val) { w->scroll_bar_width = val; @@ -3058,15 +3048,12 @@ adjust_window_margins (struct window *w) if (WINDOW_RIGHT_MARGIN_COLS (w) > 0) { if (WINDOW_LEFT_MARGIN_COLS (w) > 0) - { - wset_left_margin_cols (w, make_number (margin_cols / 2)); - wset_right_margin_cols (w, make_number (margin_cols / 2)); - } + w->left_margin_cols = w->right_margin_cols = margin_cols / 2; else - wset_right_margin_cols (w, make_number (margin_cols)); + w->right_margin_cols = margin_cols; } else - wset_left_margin_cols (w, make_number (margin_cols)); + w->left_margin_cols = margin_cols; return 1; } @@ -3223,11 +3210,11 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, /* This may call adjust_window_margins three times, so temporarily disable window margins. */ - Lisp_Object save_left = w->left_margin_cols; - Lisp_Object save_right = w->right_margin_cols; + int save_left = w->left_margin_cols; + int save_right = w->right_margin_cols; - wset_left_margin_cols (w, Qnil); - wset_right_margin_cols (w, Qnil); + w->left_margin_cols = 0; + w->right_margin_cols = 0; Fset_window_fringes (window, BVAR (b, left_fringe_width), BVAR (b, right_fringe_width), @@ -3237,8 +3224,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, BVAR (b, scroll_bar_width), BVAR (b, vertical_scroll_bar_type), Qnil); - wset_left_margin_cols (w, save_left); - wset_right_margin_cols (w, save_right); + 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)); @@ -3939,8 +3926,8 @@ set correctly. See the code of `split-window' for how this is done. */) memset (&n->last_cursor, 0, sizeof n->last_cursor); /* Get special geometry settings from reference window. */ - wset_left_margin_cols (n, r->left_margin_cols); - wset_right_margin_cols (n, r->right_margin_cols); + n->left_margin_cols = r->left_margin_cols; + n->right_margin_cols = r->right_margin_cols; n->left_fringe_width = r->left_fringe_width; n->right_fringe_width = r->right_fringe_width; n->fringes_outside_margins = r->fringes_outside_margins; @@ -5682,8 +5669,8 @@ the return value is nil. Otherwise the value is t. */) w->hscroll = XFASTINT (p->hscroll); w->min_hscroll = XFASTINT (p->min_hscroll); wset_display_table (w, p->display_table); - wset_left_margin_cols (w, p->left_margin_cols); - wset_right_margin_cols (w, p->right_margin_cols); + w->left_margin_cols = XINT (p->left_margin_cols); + w->right_margin_cols = XINT (p->right_margin_cols); w->left_fringe_width = XINT (p->left_fringe_width); w->right_fringe_width = XINT (p->right_fringe_width); w->fringes_outside_margins = !NILP (p->fringes_outside_margins); @@ -5983,8 +5970,8 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i) XSETFASTINT (p->hscroll, w->hscroll); XSETFASTINT (p->min_hscroll, w->min_hscroll); p->display_table = w->display_table; - p->left_margin_cols = w->left_margin_cols; - p->right_margin_cols = w->right_margin_cols; + p->left_margin_cols = make_number (w->left_margin_cols); + p->right_margin_cols = make_number (w->right_margin_cols); p->left_fringe_width = make_number (w->left_fringe_width); p->right_fringe_width = make_number (w->right_fringe_width); p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil; @@ -6142,38 +6129,31 @@ 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. */) +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) { struct window *w = decode_live_window (window); + int left, right; - /* Translate negative or zero widths to nil. - Margins that are too wide have to be checked elsewhere. */ + /* FIXME: what about margins that are too wide? */ - if (!NILP (left_width)) - { - CHECK_NUMBER (left_width); - if (XINT (left_width) <= 0) - left_width = Qnil; - } - - if (!NILP (right_width)) - { - CHECK_NUMBER (right_width); - if (XINT (right_width) <= 0) - right_width = Qnil; - } + left = (NILP (left_width) ? 0 + : (CHECK_NATNUM (left_width), XINT (left_width))); + right = (NILP (right_width) ? 0 + : (CHECK_NATNUM (right_width), XINT (right_width))); - if (!EQ (w->left_margin_cols, left_width) - || !EQ (w->right_margin_cols, right_width)) + if (w->left_margin_cols != left || w->right_margin_cols != right) { - wset_left_margin_cols (w, left_width); - wset_right_margin_cols (w, right_width); + w->left_margin_cols = left; + w->right_margin_cols = right; adjust_window_margins (w); ++windows_or_buffers_changed; adjust_glyphs (XFRAME (WINDOW_FRAME (w))); + return Qt; } return Qnil; @@ -6191,7 +6171,8 @@ as nil. */) (Lisp_Object window) { struct window *w = decode_live_window (window); - return Fcons (w->left_margin_cols, w->right_margin_cols); + return Fcons (make_number (w->left_margin_cols), + make_number (w->right_margin_cols)); } diff --git a/src/window.h b/src/window.h index ea573fbf3e1..a9afbc7f4a3 100644 --- a/src/window.h +++ b/src/window.h @@ -141,11 +141,6 @@ struct window it yet, or if the frame doesn't have any scroll bars, this is nil. */ Lisp_Object vertical_scroll_bar; - /* Width of left and right marginal areas. A value of nil means - no margin. */ - Lisp_Object left_margin_cols; - Lisp_Object right_margin_cols; - /* Pixel width of scroll bars. A value of nil or t means use frame values. */ Lisp_Object scroll_bar_width; @@ -269,6 +264,11 @@ struct window int left_fringe_width; int right_fringe_width; + /* Width of left and right marginal areas in columns. + A value of 0 means no margin. */ + int left_margin_cols; + int right_margin_cols; + /* Non-zero if this window is a minibuffer window. */ unsigned mini : 1; @@ -600,33 +600,21 @@ wset_next_buffers (struct window *w, Lisp_Object val) /* Width of left margin area in columns. */ -#define WINDOW_LEFT_MARGIN_COLS(W) \ - (NILP (W->left_margin_cols) \ - ? 0 \ - : XINT (W->left_margin_cols)) +#define WINDOW_LEFT_MARGIN_COLS(W) (W->left_margin_cols) /* Width of right marginal area in columns. */ -#define WINDOW_RIGHT_MARGIN_COLS(W) \ - (NILP (W->right_margin_cols) \ - ? 0 \ - : XINT (W->right_margin_cols)) +#define WINDOW_RIGHT_MARGIN_COLS(W) (W->right_margin_cols) /* Width of left margin area in pixels. */ -#define WINDOW_LEFT_MARGIN_WIDTH(W) \ - (NILP (W->left_margin_cols) \ - ? 0 \ - : (XINT (W->left_margin_cols) \ - * WINDOW_FRAME_COLUMN_WIDTH (W))) +#define WINDOW_LEFT_MARGIN_WIDTH(W) \ + (W->left_margin_cols * WINDOW_FRAME_COLUMN_WIDTH (W)) /* Width of right marginal area in pixels. */ -#define WINDOW_RIGHT_MARGIN_WIDTH(W) \ - (NILP (W->right_margin_cols) \ - ? 0 \ - : (XINT (W->right_margin_cols) \ - * WINDOW_FRAME_COLUMN_WIDTH (W))) +#define WINDOW_RIGHT_MARGIN_WIDTH(W) \ + (W->right_margin_cols * WINDOW_FRAME_COLUMN_WIDTH (W)) /* Total width of fringes reserved for drawing truncation bitmaps, continuation bitmaps and alike. The width is in canonical char diff --git a/src/xdisp.c b/src/xdisp.c index 8ef46d5be10..de5fd6ef26a 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -982,22 +982,18 @@ window_box_width (struct window *w, int area) if (area == TEXT_AREA) { - if (INTEGERP (w->left_margin_cols)) - cols -= XFASTINT (w->left_margin_cols); - if (INTEGERP (w->right_margin_cols)) - cols -= XFASTINT (w->right_margin_cols); + cols -= max (0, w->left_margin_cols); + cols -= max (0, w->right_margin_cols); pixels = -WINDOW_TOTAL_FRINGE_WIDTH (w); } else if (area == LEFT_MARGIN_AREA) { - cols = (INTEGERP (w->left_margin_cols) - ? XFASTINT (w->left_margin_cols) : 0); + cols = max (0, w->left_margin_cols); pixels = 0; } else if (area == RIGHT_MARGIN_AREA) { - cols = (INTEGERP (w->right_margin_cols) - ? XFASTINT (w->right_margin_cols) : 0); + cols = max (0, w->right_margin_cols); pixels = 0; } }