aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
authorTom Tromey2013-08-19 21:53:07 -0600
committerTom Tromey2013-08-19 21:53:07 -0600
commit6d75555c5cc3d2a629646cee7629e67530fa7a36 (patch)
tree3852804dd234ad613ea8691332e10b92c027e87d /src/window.c
parentcc231cbe45d27a1906d268fb72d3b4105a2e9c65 (diff)
parent8c2f38aaab7a7a2f0605416fc2ee38701e41ab61 (diff)
downloademacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.tar.gz
emacs-6d75555c5cc3d2a629646cee7629e67530fa7a36.zip
merge from trunk
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c437
1 files changed, 184 insertions, 253 deletions
diff --git a/src/window.c b/src/window.c
index bf4ce1dbe39..a1a069e0e7d 100644
--- a/src/window.c
+++ b/src/window.c
@@ -66,14 +66,11 @@ static Lisp_Object Qsafe, Qabove, Qbelow, Qwindow_size, Qclone_of;
66static int displayed_window_lines (struct window *); 66static int displayed_window_lines (struct window *);
67static int count_windows (struct window *); 67static int count_windows (struct window *);
68static int get_leaf_windows (struct window *, struct window **, int); 68static int get_leaf_windows (struct window *, struct window **, int);
69static void window_scroll (Lisp_Object, EMACS_INT, int, int); 69static void window_scroll (Lisp_Object, EMACS_INT, bool, int);
70static void window_scroll_pixel_based (Lisp_Object, int, int, int); 70static void window_scroll_pixel_based (Lisp_Object, int, bool, int);
71static void window_scroll_line_based (Lisp_Object, int, int, int); 71static void window_scroll_line_based (Lisp_Object, int, bool, int);
72static int freeze_window_start (struct window *, void *);
73static Lisp_Object window_list (void); 72static Lisp_Object window_list (void);
74static int add_window_to_list (struct window *, void *); 73static int add_window_to_list (struct window *, void *);
75static int candidate_window_p (Lisp_Object, Lisp_Object, Lisp_Object,
76 Lisp_Object);
77static Lisp_Object next_window (Lisp_Object, Lisp_Object, 74static Lisp_Object next_window (Lisp_Object, Lisp_Object,
78 Lisp_Object, int); 75 Lisp_Object, int);
79static void decode_next_window_args (Lisp_Object *, Lisp_Object *, 76static void decode_next_window_args (Lisp_Object *, Lisp_Object *,
@@ -90,6 +87,14 @@ static void window_resize_apply (struct window *, bool);
90static Lisp_Object select_window (Lisp_Object, Lisp_Object, int); 87static Lisp_Object select_window (Lisp_Object, Lisp_Object, int);
91static void select_window_1 (Lisp_Object, bool); 88static void select_window_1 (Lisp_Object, bool);
92 89
90static struct window *set_window_fringes (struct window *, Lisp_Object,
91 Lisp_Object, Lisp_Object);
92static struct window *set_window_margins (struct window *, Lisp_Object,
93 Lisp_Object);
94static struct window *set_window_scroll_bars (struct window *, Lisp_Object,
95 Lisp_Object, Lisp_Object);
96static void apply_window_adjustment (struct window *);
97
93/* This is the window in which the terminal's cursor should 98/* This is the window in which the terminal's cursor should
94 be left when nothing is being done with it. This must 99 be left when nothing is being done with it. This must
95 always be a leaf window, and its buffer is selected by 100 always be a leaf window, and its buffer is selected by
@@ -154,16 +159,6 @@ wset_display_table (struct window *w, Lisp_Object val)
154 w->display_table = val; 159 w->display_table = val;
155} 160}
156static void 161static void
157wset_left_fringe_width (struct window *w, Lisp_Object val)
158{
159 w->left_fringe_width = val;
160}
161static void
162wset_left_margin_cols (struct window *w, Lisp_Object val)
163{
164 w->left_margin_cols = val;
165}
166static void
167wset_new_normal (struct window *w, Lisp_Object val) 162wset_new_normal (struct window *w, Lisp_Object val)
168{ 163{
169 w->new_normal = val; 164 w->new_normal = val;
@@ -194,21 +189,6 @@ wset_pointm (struct window *w, Lisp_Object val)
194 w->pointm = val; 189 w->pointm = val;
195} 190}
196static void 191static void
197wset_right_fringe_width (struct window *w, Lisp_Object val)
198{
199 w->right_fringe_width = val;
200}
201static void
202wset_right_margin_cols (struct window *w, Lisp_Object val)
203{
204 w->right_margin_cols = val;
205}
206static void
207wset_scroll_bar_width (struct window *w, Lisp_Object val)
208{
209 w->scroll_bar_width = val;
210}
211static void
212wset_start (struct window *w, Lisp_Object val) 192wset_start (struct window *w, Lisp_Object val)
213{ 193{
214 w->start = val; 194 w->start = val;
@@ -241,6 +221,17 @@ wset_combination (struct window *w, bool horflag, Lisp_Object val)
241 w->horizontal = horflag; 221 w->horizontal = horflag;
242} 222}
243 223
224/* Nonzero if leaf window W doesn't reflect the actual state
225 of displayed buffer due to its text or overlays change. */
226
227bool
228window_outdated (struct window *w)
229{
230 struct buffer *b = XBUFFER (w->contents);
231 return (w->last_modified < BUF_MODIFF (b)
232 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b));
233}
234
244struct window * 235struct window *
245decode_live_window (register Lisp_Object window) 236decode_live_window (register Lisp_Object window)
246{ 237{
@@ -490,7 +481,6 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
490 CHECK_LIVE_WINDOW (window); 481 CHECK_LIVE_WINDOW (window);
491 482
492 w = XWINDOW (window); 483 w = XWINDOW (window);
493 w->frozen_window_start_p = 0;
494 484
495 /* Make the selected window's buffer current. */ 485 /* Make the selected window's buffer current. */
496 Fset_buffer (w->contents); 486 Fset_buffer (w->contents);
@@ -1355,7 +1345,7 @@ struct check_window_data
1355static int 1345static int
1356check_window_containing (struct window *w, void *user_data) 1346check_window_containing (struct window *w, void *user_data)
1357{ 1347{
1358 struct check_window_data *cw = (struct check_window_data *) user_data; 1348 struct check_window_data *cw = user_data;
1359 enum window_part found; 1349 enum window_part found;
1360 int continue_p = 1; 1350 int continue_p = 1;
1361 1351
@@ -1508,8 +1498,7 @@ if it isn't already recorded. */)
1508 || !w->window_end_valid 1498 || !w->window_end_valid
1509 || b->clip_changed 1499 || b->clip_changed
1510 || b->prevent_redisplay_optimizations_p 1500 || b->prevent_redisplay_optimizations_p
1511 || w->last_modified < BUF_MODIFF (b) 1501 || window_outdated (w))
1512 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b))
1513 && !noninteractive) 1502 && !noninteractive)
1514 { 1503 {
1515 struct text_pos startp; 1504 struct text_pos startp;
@@ -1550,7 +1539,7 @@ if it isn't already recorded. */)
1550 set_buffer_internal (old_buffer); 1539 set_buffer_internal (old_buffer);
1551 } 1540 }
1552 else 1541 else
1553 XSETINT (value, BUF_Z (b) - XFASTINT (w->window_end_pos)); 1542 XSETINT (value, BUF_Z (b) - w->window_end_pos);
1554 1543
1555 return value; 1544 return value;
1556} 1545}
@@ -1606,9 +1595,8 @@ overriding motion of point in order to display at this exact start. */)
1606 if (NILP (noforce)) 1595 if (NILP (noforce))
1607 w->force_start = 1; 1596 w->force_start = 1;
1608 w->update_mode_line = 1; 1597 w->update_mode_line = 1;
1609 w->last_modified = 0; 1598 if (w != XWINDOW (selected_window))
1610 w->last_overlay_modified = 0; 1599 /* Enforce full redisplay. FIXME: make it more selective. */
1611 if (!EQ (window, selected_window))
1612 windows_or_buffers_changed++; 1600 windows_or_buffers_changed++;
1613 1601
1614 return pos; 1602 return pos;
@@ -1722,8 +1710,7 @@ Return nil if window display is not up-to-date. In that case, use
1722 || windows_or_buffers_changed 1710 || windows_or_buffers_changed
1723 || b->clip_changed 1711 || b->clip_changed
1724 || b->prevent_redisplay_optimizations_p 1712 || b->prevent_redisplay_optimizations_p
1725 || w->last_modified < BUF_MODIFF (b) 1713 || window_outdated (w))
1726 || w->last_overlay_modified < BUF_OVERLAY_MODIFF (b))
1727 return Qnil; 1714 return Qnil;
1728 1715
1729 if (NILP (line)) 1716 if (NILP (line))
@@ -2046,10 +2033,9 @@ replace_window (Lisp_Object old, Lisp_Object new, int setflag)
2046 n->phys_cursor_width = -1; 2033 n->phys_cursor_width = -1;
2047 n->must_be_updated_p = 0; 2034 n->must_be_updated_p = 0;
2048 n->pseudo_window_p = 0; 2035 n->pseudo_window_p = 0;
2049 wset_window_end_vpos (n, make_number (0)); 2036 n->window_end_vpos = 0;
2050 wset_window_end_pos (n, make_number (0)); 2037 n->window_end_pos = 0;
2051 n->window_end_valid = 0; 2038 n->window_end_valid = 0;
2052 n->frozen_window_start_p = 0;
2053 } 2039 }
2054 2040
2055 tem = o->next; 2041 tem = o->next;
@@ -2158,7 +2144,7 @@ delete_deletable_window (Lisp_Object window)
2158static int 2144static int
2159add_window_to_list (struct window *w, void *user_data) 2145add_window_to_list (struct window *w, void *user_data)
2160{ 2146{
2161 Lisp_Object *list = (Lisp_Object *) user_data; 2147 Lisp_Object *list = user_data;
2162 Lisp_Object window; 2148 Lisp_Object window;
2163 XSETWINDOW (window, w); 2149 XSETWINDOW (window, w);
2164 *list = Fcons (window, *list); 2150 *list = Fcons (window, *list);
@@ -2213,12 +2199,13 @@ window_list (void)
2213 a window means search the frame that window belongs to, 2199 a window means search the frame that window belongs to,
2214 a frame means consider windows on that frame, only. */ 2200 a frame means consider windows on that frame, only. */
2215 2201
2216static int 2202static bool
2217candidate_window_p (Lisp_Object window, Lisp_Object owindow, Lisp_Object minibuf, Lisp_Object all_frames) 2203candidate_window_p (Lisp_Object window, Lisp_Object owindow,
2204 Lisp_Object minibuf, Lisp_Object all_frames)
2218{ 2205{
2219 struct window *w = XWINDOW (window); 2206 struct window *w = XWINDOW (window);
2220 struct frame *f = XFRAME (w->frame); 2207 struct frame *f = XFRAME (w->frame);
2221 int candidate_p = 1; 2208 bool candidate_p = 1;
2222 2209
2223 if (!BUFFERP (w->contents)) 2210 if (!BUFFERP (w->contents))
2224 candidate_p = 0; 2211 candidate_p = 0;
@@ -3020,7 +3007,7 @@ replace_buffer_in_windows_safely (Lisp_Object buffer)
3020 minimum allowable size. */ 3007 minimum allowable size. */
3021 3008
3022void 3009void
3023check_frame_size (FRAME_PTR frame, int *rows, int *cols) 3010check_frame_size (struct frame *frame, int *rows, int *cols)
3024{ 3011{
3025 /* For height, we have to see: 3012 /* For height, we have to see:
3026 how many windows the frame has at minimum (one or two), 3013 how many windows the frame has at minimum (one or two),
@@ -3064,15 +3051,12 @@ adjust_window_margins (struct window *w)
3064 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0) 3051 if (WINDOW_RIGHT_MARGIN_COLS (w) > 0)
3065 { 3052 {
3066 if (WINDOW_LEFT_MARGIN_COLS (w) > 0) 3053 if (WINDOW_LEFT_MARGIN_COLS (w) > 0)
3067 { 3054 w->left_margin_cols = w->right_margin_cols = margin_cols / 2;
3068 wset_left_margin_cols (w, make_number (margin_cols / 2));
3069 wset_right_margin_cols (w, make_number (margin_cols / 2));
3070 }
3071 else 3055 else
3072 wset_right_margin_cols (w, make_number (margin_cols)); 3056 w->right_margin_cols = margin_cols;
3073 } 3057 }
3074 else 3058 else
3075 wset_left_margin_cols (w, make_number (margin_cols)); 3059 w->left_margin_cols = margin_cols;
3076 return 1; 3060 return 1;
3077} 3061}
3078 3062
@@ -3120,7 +3104,7 @@ run_window_configuration_change_hook (struct frame *f)
3120 3104
3121 if (SELECTED_FRAME () != f) 3105 if (SELECTED_FRAME () != f)
3122 { 3106 {
3123 record_unwind_protect (select_frame_norecord, Fselected_frame ()); 3107 record_unwind_protect (select_frame_norecord, selected_frame);
3124 select_frame_norecord (frame); 3108 select_frame_norecord (frame);
3125 } 3109 }
3126 3110
@@ -3135,7 +3119,7 @@ run_window_configuration_change_hook (struct frame *f)
3135 buffer))) 3119 buffer)))
3136 { 3120 {
3137 ptrdiff_t inner_count = SPECPDL_INDEX (); 3121 ptrdiff_t inner_count = SPECPDL_INDEX ();
3138 record_unwind_protect (select_window_norecord, Fselected_window ()); 3122 record_unwind_protect (select_window_norecord, selected_window);
3139 select_window_norecord (window); 3123 select_window_norecord (window);
3140 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook, 3124 run_funs (Fbuffer_local_value (Qwindow_configuration_change_hook,
3141 buffer)); 3125 buffer));
@@ -3186,8 +3170,8 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3186 bset_display_count (b, make_number (XINT (BVAR (b, display_count)) + 1)); 3170 bset_display_count (b, make_number (XINT (BVAR (b, display_count)) + 1));
3187 bset_display_time (b, Fcurrent_time ()); 3171 bset_display_time (b, Fcurrent_time ());
3188 3172
3189 wset_window_end_pos (w, make_number (0)); 3173 w->window_end_pos = 0;
3190 wset_window_end_vpos (w, make_number (0)); 3174 w->window_end_vpos = 0;
3191 memset (&w->last_cursor, 0, sizeof w->last_cursor); 3175 memset (&w->last_cursor, 0, sizeof w->last_cursor);
3192 3176
3193 if (!(keep_margins_p && samebuf)) 3177 if (!(keep_margins_p && samebuf))
@@ -3207,8 +3191,6 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3207 buffer); 3191 buffer);
3208 w->start_at_line_beg = 0; 3192 w->start_at_line_beg = 0;
3209 w->force_start = 0; 3193 w->force_start = 0;
3210 w->last_modified = 0;
3211 w->last_overlay_modified = 0;
3212 } 3194 }
3213 /* Maybe we could move this into the `if' but it's not obviously safe and 3195 /* Maybe we could move this into the `if' but it's not obviously safe and
3214 I doubt it's worth the trouble. */ 3196 I doubt it's worth the trouble. */
@@ -3228,28 +3210,14 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer,
3228 if (!keep_margins_p) 3210 if (!keep_margins_p)
3229 { 3211 {
3230 /* Set left and right marginal area width etc. from buffer. */ 3212 /* Set left and right marginal area width etc. from buffer. */
3231 3213 set_window_fringes (w, BVAR (b, left_fringe_width),
3232 /* This may call adjust_window_margins three times, so 3214 BVAR (b, right_fringe_width),
3233 temporarily disable window margins. */ 3215 BVAR (b, fringes_outside_margins));
3234 Lisp_Object save_left = w->left_margin_cols; 3216 set_window_scroll_bars (w, BVAR (b, scroll_bar_width),
3235 Lisp_Object save_right = w->right_margin_cols; 3217 BVAR (b, vertical_scroll_bar_type), Qnil);
3236 3218 set_window_margins (w, BVAR (b, left_margin_cols),
3237 wset_left_margin_cols (w, Qnil); 3219 BVAR (b, right_margin_cols));
3238 wset_right_margin_cols (w, Qnil); 3220 apply_window_adjustment (w);
3239
3240 Fset_window_fringes (window,
3241 BVAR (b, left_fringe_width), BVAR (b, right_fringe_width),
3242 BVAR (b, fringes_outside_margins));
3243
3244 Fset_window_scroll_bars (window,
3245 BVAR (b, scroll_bar_width),
3246 BVAR (b, vertical_scroll_bar_type), Qnil);
3247
3248 wset_left_margin_cols (w, save_left);
3249 wset_right_margin_cols (w, save_right);
3250
3251 Fset_window_margins (window,
3252 BVAR (b, left_margin_cols), BVAR (b, right_margin_cols));
3253 } 3221 }
3254 3222
3255 if (run_hooks_p) 3223 if (run_hooks_p)
@@ -3469,8 +3437,6 @@ make_window (void)
3469 wset_start (w, Fmake_marker ()); 3437 wset_start (w, Fmake_marker ());
3470 wset_pointm (w, Fmake_marker ()); 3438 wset_pointm (w, Fmake_marker ());
3471 wset_vertical_scroll_bar_type (w, Qt); 3439 wset_vertical_scroll_bar_type (w, Qt);
3472 wset_window_end_pos (w, make_number (0));
3473 wset_window_end_vpos (w, make_number (0));
3474 /* These Lisp fields are marked specially so they're not set to nil by 3440 /* These Lisp fields are marked specially so they're not set to nil by
3475 allocate_window. */ 3441 allocate_window. */
3476 wset_prev_buffers (w, Qnil); 3442 wset_prev_buffers (w, Qnil);
@@ -3479,8 +3445,10 @@ make_window (void)
3479 /* Initialize non-Lisp data. Note that allocate_window zeroes out all 3445 /* Initialize non-Lisp data. Note that allocate_window zeroes out all
3480 non-Lisp data, so do it only for slots which should not be zero. */ 3446 non-Lisp data, so do it only for slots which should not be zero. */
3481 w->nrows_scale_factor = w->ncols_scale_factor = 1; 3447 w->nrows_scale_factor = w->ncols_scale_factor = 1;
3448 w->left_fringe_width = w->right_fringe_width = -1;
3482 w->phys_cursor_type = -1; 3449 w->phys_cursor_type = -1;
3483 w->phys_cursor_width = -1; 3450 w->phys_cursor_width = -1;
3451 w->scroll_bar_width = -1;
3484 w->column_number_displayed = -1; 3452 w->column_number_displayed = -1;
3485 3453
3486 /* Reset window_list. */ 3454 /* Reset window_list. */
@@ -3669,10 +3637,6 @@ window_resize_apply (struct window *w, bool horflag)
3669 c = NILP (c->next) ? 0 : XWINDOW (c->next); 3637 c = NILP (c->next) ? 0 : XWINDOW (c->next);
3670 } 3638 }
3671 } 3639 }
3672
3673 /* Clear out some redisplay caches. */
3674 w->last_modified = 0;
3675 w->last_overlay_modified = 0;
3676} 3640}
3677 3641
3678 3642
@@ -3950,12 +3914,12 @@ set correctly. See the code of `split-window' for how this is done. */)
3950 memset (&n->last_cursor, 0, sizeof n->last_cursor); 3914 memset (&n->last_cursor, 0, sizeof n->last_cursor);
3951 3915
3952 /* Get special geometry settings from reference window. */ 3916 /* Get special geometry settings from reference window. */
3953 wset_left_margin_cols (n, r->left_margin_cols); 3917 n->left_margin_cols = r->left_margin_cols;
3954 wset_right_margin_cols (n, r->right_margin_cols); 3918 n->right_margin_cols = r->right_margin_cols;
3955 wset_left_fringe_width (n, r->left_fringe_width); 3919 n->left_fringe_width = r->left_fringe_width;
3956 wset_right_fringe_width (n, r->right_fringe_width); 3920 n->right_fringe_width = r->right_fringe_width;
3957 n->fringes_outside_margins = r->fringes_outside_margins; 3921 n->fringes_outside_margins = r->fringes_outside_margins;
3958 wset_scroll_bar_width (n, r->scroll_bar_width); 3922 n->scroll_bar_width = r->scroll_bar_width;
3959 wset_vertical_scroll_bar_type (n, r->vertical_scroll_bar_type); 3923 wset_vertical_scroll_bar_type (n, r->vertical_scroll_bar_type);
3960 3924
3961 /* Directly assign orthogonal coordinates and sizes. */ 3925 /* Directly assign orthogonal coordinates and sizes. */
@@ -4191,9 +4155,7 @@ grow_mini_window (struct window *w, int delta)
4191 /* Grow the mini-window. */ 4155 /* Grow the mini-window. */
4192 w->top_line = r->top_line + r->total_lines; 4156 w->top_line = r->top_line + r->total_lines;
4193 w->total_lines -= XINT (value); 4157 w->total_lines -= XINT (value);
4194 w->last_modified = 0; 4158 /* Enforce full redisplay. FIXME: make it more selective. */
4195 w->last_overlay_modified = 0;
4196
4197 windows_or_buffers_changed++; 4159 windows_or_buffers_changed++;
4198 adjust_glyphs (f); 4160 adjust_glyphs (f);
4199 unblock_input (); 4161 unblock_input ();
@@ -4227,10 +4189,7 @@ shrink_mini_window (struct window *w)
4227 /* Shrink the mini-window. */ 4189 /* Shrink the mini-window. */
4228 w->top_line = r->top_line + r->total_lines; 4190 w->top_line = r->top_line + r->total_lines;
4229 w->total_lines = 1; 4191 w->total_lines = 1;
4230 4192 /* Enforce full redisplay. FIXME: make it more selective. */
4231 w->last_modified = 0;
4232 w->last_overlay_modified = 0;
4233
4234 windows_or_buffers_changed++; 4193 windows_or_buffers_changed++;
4235 adjust_glyphs (f); 4194 adjust_glyphs (f);
4236 unblock_input (); 4195 unblock_input ();
@@ -4337,7 +4296,7 @@ window_internal_height (struct window *w)
4337 respectively. */ 4296 respectively. */
4338 4297
4339static void 4298static void
4340window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror) 4299window_scroll (Lisp_Object window, EMACS_INT n, bool whole, int noerror)
4341{ 4300{
4342 immediate_quit = 1; 4301 immediate_quit = 1;
4343 n = clip_to_bounds (INT_MIN, n, INT_MAX); 4302 n = clip_to_bounds (INT_MIN, n, INT_MAX);
@@ -4358,7 +4317,7 @@ window_scroll (Lisp_Object window, EMACS_INT n, int whole, int noerror)
4358 descriptions. */ 4317 descriptions. */
4359 4318
4360static void 4319static void
4361window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror) 4320window_scroll_pixel_based (Lisp_Object window, int n, bool whole, int noerror)
4362{ 4321{
4363 struct it it; 4322 struct it it;
4364 struct window *w = XWINDOW (window); 4323 struct window *w = XWINDOW (window);
@@ -4456,8 +4415,6 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4456 w->contents); 4415 w->contents);
4457 w->start_at_line_beg = 1; 4416 w->start_at_line_beg = 1;
4458 w->update_mode_line = 1; 4417 w->update_mode_line = 1;
4459 w->last_modified = 0;
4460 w->last_overlay_modified = 0;
4461 /* Set force_start so that redisplay_window will run the 4418 /* Set force_start so that redisplay_window will run the
4462 window-scroll-functions. */ 4419 window-scroll-functions. */
4463 w->force_start = 1; 4420 w->force_start = 1;
@@ -4602,8 +4559,6 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4602 bytepos = marker_byte_position (w->start); 4559 bytepos = marker_byte_position (w->start);
4603 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n'); 4560 w->start_at_line_beg = (pos == BEGV || FETCH_BYTE (bytepos - 1) == '\n');
4604 w->update_mode_line = 1; 4561 w->update_mode_line = 1;
4605 w->last_modified = 0;
4606 w->last_overlay_modified = 0;
4607 /* Set force_start so that redisplay_window will run the 4562 /* Set force_start so that redisplay_window will run the
4608 window-scroll-functions. */ 4563 window-scroll-functions. */
4609 w->force_start = 1; 4564 w->force_start = 1;
@@ -4726,7 +4681,7 @@ window_scroll_pixel_based (Lisp_Object window, int n, int whole, int noerror)
4726 See the comment of window_scroll for parameter descriptions. */ 4681 See the comment of window_scroll for parameter descriptions. */
4727 4682
4728static void 4683static void
4729window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror) 4684window_scroll_line_based (Lisp_Object window, int n, bool whole, int noerror)
4730{ 4685{
4731 register struct window *w = XWINDOW (window); 4686 register struct window *w = XWINDOW (window);
4732 /* Fvertical_motion enters redisplay, which can trigger 4687 /* Fvertical_motion enters redisplay, which can trigger
@@ -4738,7 +4693,7 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4738 register ptrdiff_t pos, pos_byte; 4693 register ptrdiff_t pos, pos_byte;
4739 register int ht = window_internal_height (w); 4694 register int ht = window_internal_height (w);
4740 register Lisp_Object tem; 4695 register Lisp_Object tem;
4741 int lose; 4696 bool lose;
4742 Lisp_Object bolp; 4697 Lisp_Object bolp;
4743 ptrdiff_t startpos = marker_position (w->start); 4698 ptrdiff_t startpos = marker_position (w->start);
4744 ptrdiff_t startbyte = marker_byte_position (w->start); 4699 ptrdiff_t startbyte = marker_byte_position (w->start);
@@ -4802,8 +4757,6 @@ window_scroll_line_based (Lisp_Object window, int n, int whole, int noerror)
4802 set_marker_restricted_both (w->start, w->contents, pos, pos_byte); 4757 set_marker_restricted_both (w->start, w->contents, pos, pos_byte);
4803 w->start_at_line_beg = !NILP (bolp); 4758 w->start_at_line_beg = !NILP (bolp);
4804 w->update_mode_line = 1; 4759 w->update_mode_line = 1;
4805 w->last_modified = 0;
4806 w->last_overlay_modified = 0;
4807 /* Set force_start so that redisplay_window will run 4760 /* Set force_start so that redisplay_window will run
4808 the window-scroll-functions. */ 4761 the window-scroll-functions. */
4809 w->force_start = 1; 4762 w->force_start = 1;
@@ -5172,7 +5125,7 @@ and redisplay normally--don't erase and redraw the frame. */)
5172 struct window *w = XWINDOW (selected_window); 5125 struct window *w = XWINDOW (selected_window);
5173 struct buffer *buf = XBUFFER (w->contents); 5126 struct buffer *buf = XBUFFER (w->contents);
5174 struct buffer *obuf = current_buffer; 5127 struct buffer *obuf = current_buffer;
5175 int center_p = 0; 5128 bool center_p = 0;
5176 ptrdiff_t charpos, bytepos; 5129 ptrdiff_t charpos, bytepos;
5177 EMACS_INT iarg IF_LINT (= 0); 5130 EMACS_INT iarg IF_LINT (= 0);
5178 int this_scroll_margin; 5131 int this_scroll_margin;
@@ -5517,7 +5470,7 @@ the return value is nil. Otherwise the value is t. */)
5517 struct Lisp_Vector *saved_windows; 5470 struct Lisp_Vector *saved_windows;
5518 Lisp_Object new_current_buffer; 5471 Lisp_Object new_current_buffer;
5519 Lisp_Object frame; 5472 Lisp_Object frame;
5520 FRAME_PTR f; 5473 struct frame *f;
5521 ptrdiff_t old_point = -1; 5474 ptrdiff_t old_point = -1;
5522 5475
5523 CHECK_WINDOW_CONFIGURATION (configuration); 5476 CHECK_WINDOW_CONFIGURATION (configuration);
@@ -5704,12 +5657,12 @@ the return value is nil. Otherwise the value is t. */)
5704 w->hscroll = XFASTINT (p->hscroll); 5657 w->hscroll = XFASTINT (p->hscroll);
5705 w->min_hscroll = XFASTINT (p->min_hscroll); 5658 w->min_hscroll = XFASTINT (p->min_hscroll);
5706 wset_display_table (w, p->display_table); 5659 wset_display_table (w, p->display_table);
5707 wset_left_margin_cols (w, p->left_margin_cols); 5660 w->left_margin_cols = XINT (p->left_margin_cols);
5708 wset_right_margin_cols (w, p->right_margin_cols); 5661 w->right_margin_cols = XINT (p->right_margin_cols);
5709 wset_left_fringe_width (w, p->left_fringe_width); 5662 w->left_fringe_width = XINT (p->left_fringe_width);
5710 wset_right_fringe_width (w, p->right_fringe_width); 5663 w->right_fringe_width = XINT (p->right_fringe_width);
5711 w->fringes_outside_margins = !NILP (p->fringes_outside_margins); 5664 w->fringes_outside_margins = !NILP (p->fringes_outside_margins);
5712 wset_scroll_bar_width (w, p->scroll_bar_width); 5665 w->scroll_bar_width = XINT (p->scroll_bar_width);
5713 wset_vertical_scroll_bar_type (w, p->vertical_scroll_bar_type); 5666 wset_vertical_scroll_bar_type (w, p->vertical_scroll_bar_type);
5714 wset_dedicated (w, p->dedicated); 5667 wset_dedicated (w, p->dedicated);
5715 wset_combination_limit (w, p->combination_limit); 5668 wset_combination_limit (w, p->combination_limit);
@@ -5735,9 +5688,6 @@ the return value is nil. Otherwise the value is t. */)
5735 } 5688 }
5736 } 5689 }
5737 5690
5738 w->last_modified = 0;
5739 w->last_overlay_modified = 0;
5740
5741 if (BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer))) 5691 if (BUFFERP (p->buffer) && BUFFER_LIVE_P (XBUFFER (p->buffer)))
5742 /* If saved buffer is alive, install it. */ 5692 /* If saved buffer is alive, install it. */
5743 { 5693 {
@@ -6008,12 +5958,12 @@ save_window_save (Lisp_Object window, struct Lisp_Vector *vector, int i)
6008 XSETFASTINT (p->hscroll, w->hscroll); 5958 XSETFASTINT (p->hscroll, w->hscroll);
6009 XSETFASTINT (p->min_hscroll, w->min_hscroll); 5959 XSETFASTINT (p->min_hscroll, w->min_hscroll);
6010 p->display_table = w->display_table; 5960 p->display_table = w->display_table;
6011 p->left_margin_cols = w->left_margin_cols; 5961 p->left_margin_cols = make_number (w->left_margin_cols);
6012 p->right_margin_cols = w->right_margin_cols; 5962 p->right_margin_cols = make_number (w->right_margin_cols);
6013 p->left_fringe_width = w->left_fringe_width; 5963 p->left_fringe_width = make_number (w->left_fringe_width);
6014 p->right_fringe_width = w->right_fringe_width; 5964 p->right_fringe_width = make_number (w->right_fringe_width);
6015 p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil; 5965 p->fringes_outside_margins = w->fringes_outside_margins ? Qt : Qnil;
6016 p->scroll_bar_width = w->scroll_bar_width; 5966 p->scroll_bar_width = make_number (w->scroll_bar_width);
6017 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type; 5967 p->vertical_scroll_bar_type = w->vertical_scroll_bar_type;
6018 p->dedicated = w->dedicated; 5968 p->dedicated = w->dedicated;
6019 p->combination_limit = w->combination_limit; 5969 p->combination_limit = w->combination_limit;
@@ -6154,11 +6104,46 @@ saved by this function. */)
6154 XSETWINDOW_CONFIGURATION (tem, data); 6104 XSETWINDOW_CONFIGURATION (tem, data);
6155 return (tem); 6105 return (tem);
6156} 6106}
6107
6108/* Called after W's margins, fringes or scroll bars was adjusted. */
6109
6110static void
6111apply_window_adjustment (struct window *w)
6112{
6113 eassert (w);
6114 adjust_window_margins (w);
6115 clear_glyph_matrix (w->current_matrix);
6116 w->window_end_valid = 0;
6117 windows_or_buffers_changed++;
6118 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6119}
6120
6157 6121
6158/*********************************************************************** 6122/***********************************************************************
6159 Marginal Areas 6123 Marginal Areas
6160 ***********************************************************************/ 6124 ***********************************************************************/
6161 6125
6126static struct window *
6127set_window_margins (struct window *w, Lisp_Object left_width,
6128 Lisp_Object right_width)
6129{
6130 int left, right;
6131
6132 /* FIXME: what about margins that are too wide? */
6133 left = (NILP (left_width) ? 0
6134 : (CHECK_NATNUM (left_width), XINT (left_width)));
6135 right = (NILP (right_width) ? 0
6136 : (CHECK_NATNUM (right_width), XINT (right_width)));
6137
6138 if (w->left_margin_cols != left || w->right_margin_cols != right)
6139 {
6140 w->left_margin_cols = left;
6141 w->right_margin_cols = right;
6142 return w;
6143 }
6144 return NULL;
6145}
6146
6162DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins, 6147DEFUN ("set-window-margins", Fset_window_margins, Sset_window_margins,
6163 2, 3, 0, 6148 2, 3, 0,
6164 doc: /* Set width of marginal areas of window WINDOW. 6149 doc: /* Set width of marginal areas of window WINDOW.
@@ -6167,41 +6152,14 @@ WINDOW must be a live window and defaults to the selected one.
6167Second arg LEFT-WIDTH specifies the number of character cells to 6152Second arg LEFT-WIDTH specifies the number of character cells to
6168reserve for the left marginal area. Optional third arg RIGHT-WIDTH 6153reserve for the left marginal area. Optional third arg RIGHT-WIDTH
6169does the same for the right marginal area. A nil width parameter 6154does the same for the right marginal area. A nil width parameter
6170means no margin. */) 6155means no margin.
6156
6157Return t if any margin was actually changed and nil otherwise. */)
6171 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width) 6158 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width)
6172{ 6159{
6173 struct window *w = decode_live_window (window); 6160 struct window *w = set_window_margins (decode_live_window (window),
6174 6161 left_width, right_width);
6175 /* Translate negative or zero widths to nil. 6162 return w ? (apply_window_adjustment (w), Qt) : Qnil;
6176 Margins that are too wide have to be checked elsewhere. */
6177
6178 if (!NILP (left_width))
6179 {
6180 CHECK_NUMBER (left_width);
6181 if (XINT (left_width) <= 0)
6182 left_width = Qnil;
6183 }
6184
6185 if (!NILP (right_width))
6186 {
6187 CHECK_NUMBER (right_width);
6188 if (XINT (right_width) <= 0)
6189 right_width = Qnil;
6190 }
6191
6192 if (!EQ (w->left_margin_cols, left_width)
6193 || !EQ (w->right_margin_cols, right_width))
6194 {
6195 wset_left_margin_cols (w, left_width);
6196 wset_right_margin_cols (w, right_width);
6197
6198 adjust_window_margins (w);
6199
6200 ++windows_or_buffers_changed;
6201 adjust_glyphs (XFRAME (WINDOW_FRAME (w)));
6202 }
6203
6204 return Qnil;
6205} 6163}
6206 6164
6207 6165
@@ -6216,7 +6174,8 @@ as nil. */)
6216 (Lisp_Object window) 6174 (Lisp_Object window)
6217{ 6175{
6218 struct window *w = decode_live_window (window); 6176 struct window *w = decode_live_window (window);
6219 return Fcons (w->left_margin_cols, w->right_margin_cols); 6177 return Fcons (w->left_margin_cols ? make_number (w->left_margin_cols) : Qnil,
6178 w->right_margin_cols ? make_number (w->right_margin_cols) : Qnil);
6220} 6179}
6221 6180
6222 6181
@@ -6225,6 +6184,31 @@ as nil. */)
6225 Fringes 6184 Fringes
6226 ***********************************************************************/ 6185 ***********************************************************************/
6227 6186
6187static struct window *
6188set_window_fringes (struct window *w, Lisp_Object left_width,
6189 Lisp_Object right_width, Lisp_Object outside_margins)
6190{
6191 int left, right, outside = !NILP (outside_margins);
6192
6193 left = (NILP (left_width) ? -1
6194 : (CHECK_NATNUM (left_width), XINT (left_width)));
6195 right = (NILP (right_width) ? -1
6196 : (CHECK_NATNUM (right_width), XINT (right_width)));
6197
6198 /* Do nothing on a tty or if nothing to actually change. */
6199 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6200 && (w->left_fringe_width != left
6201 || w->right_fringe_width != right
6202 || w->fringes_outside_margins != outside))
6203 {
6204 w->left_fringe_width = left;
6205 w->right_fringe_width = right;
6206 w->fringes_outside_margins = outside;
6207 return w;
6208 }
6209 return NULL;
6210}
6211
6228DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes, 6212DEFUN ("set-window-fringes", Fset_window_fringes, Sset_window_fringes,
6229 2, 4, 0, 6213 2, 4, 0,
6230 doc: /* Set the fringe widths of window WINDOW. 6214 doc: /* Set the fringe widths of window WINDOW.
@@ -6237,37 +6221,16 @@ frame's default fringe width. Default fringe widths can be set with
6237the command `set-fringe-style'. 6221the command `set-fringe-style'.
6238If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes 6222If optional fourth arg OUTSIDE-MARGINS is non-nil, draw the fringes
6239outside of the display margins. By default, fringes are drawn between 6223outside of the display margins. By default, fringes are drawn between
6240display marginal areas and the text area. */) 6224display marginal areas and the text area.
6241 (Lisp_Object window, Lisp_Object left_width, Lisp_Object right_width, Lisp_Object outside_margins)
6242{
6243 struct window *w = decode_live_window (window);
6244 int outside = !NILP (outside_margins);
6245
6246 if (!NILP (left_width))
6247 CHECK_NATNUM (left_width);
6248 if (!NILP (right_width))
6249 CHECK_NATNUM (right_width);
6250
6251 /* Do nothing on a tty. */
6252 if (FRAME_WINDOW_P (WINDOW_XFRAME (w))
6253 && (!EQ (w->left_fringe_width, left_width)
6254 || !EQ (w->right_fringe_width, right_width)
6255 || w->fringes_outside_margins != outside))
6256 {
6257 wset_left_fringe_width (w, left_width);
6258 wset_right_fringe_width (w, right_width);
6259 w->fringes_outside_margins = outside;
6260
6261 adjust_window_margins (w);
6262
6263 clear_glyph_matrix (w->current_matrix);
6264 w->window_end_valid = 0;
6265 6225
6266 ++windows_or_buffers_changed; 6226Return t if any fringe was actually changed and nil otherwise. */)
6267 adjust_glyphs (XFRAME (WINDOW_FRAME (w))); 6227 (Lisp_Object window, Lisp_Object left_width,
6268 } 6228 Lisp_Object right_width, Lisp_Object outside_margins)
6269 6229{
6270 return Qnil; 6230 struct window *w
6231 = set_window_fringes (decode_live_window (window),
6232 left_width, right_width, outside_margins);
6233 return w ? (apply_window_adjustment (w), Qt) : Qnil;
6271} 6234}
6272 6235
6273 6236
@@ -6292,29 +6255,14 @@ Value is a list of the form (LEFT-WIDTH RIGHT-WIDTH OUTSIDE-MARGINS). */)
6292 Scroll bars 6255 Scroll bars
6293 ***********************************************************************/ 6256 ***********************************************************************/
6294 6257
6295DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars, 6258static struct window *
6296 Sset_window_scroll_bars, 2, 4, 0, 6259set_window_scroll_bars (struct window *w, Lisp_Object width,
6297 doc: /* Set width and type of scroll bars of window WINDOW. 6260 Lisp_Object vertical_type, Lisp_Object horizontal_type)
6298WINDOW must be a live window and defaults to the selected one.
6299
6300Second parameter WIDTH specifies the pixel width for the scroll bar;
6301this is automatically adjusted to a multiple of the frame column width.
6302Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6303bar: left, right, or nil.
6304If WIDTH is nil, use the frame's scroll-bar width.
6305If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6306Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6307 (Lisp_Object window, Lisp_Object width, Lisp_Object vertical_type, Lisp_Object horizontal_type)
6308{ 6261{
6309 struct window *w = decode_live_window (window); 6262 int iwidth = (NILP (width) ? -1 : (CHECK_NATNUM (width), XINT (width)));
6310 6263
6311 if (!NILP (width)) 6264 if (iwidth == 0)
6312 { 6265 vertical_type = Qnil;
6313 CHECK_RANGED_INTEGER (width, 0, INT_MAX);
6314
6315 if (XINT (width) == 0)
6316 vertical_type = Qnil;
6317 }
6318 6266
6319 if (!(NILP (vertical_type) 6267 if (!(NILP (vertical_type)
6320 || EQ (vertical_type, Qleft) 6268 || EQ (vertical_type, Qleft)
@@ -6322,22 +6270,37 @@ Fourth parameter HORIZONTAL-TYPE is currently unused. */)
6322 || EQ (vertical_type, Qt))) 6270 || EQ (vertical_type, Qt)))
6323 error ("Invalid type of vertical scroll bar"); 6271 error ("Invalid type of vertical scroll bar");
6324 6272
6325 if (!EQ (w->scroll_bar_width, width) 6273 if (w->scroll_bar_width != iwidth
6326 || !EQ (w->vertical_scroll_bar_type, vertical_type)) 6274 || !EQ (w->vertical_scroll_bar_type, vertical_type))
6327 { 6275 {
6328 wset_scroll_bar_width (w, width); 6276 w->scroll_bar_width = iwidth;
6329 wset_vertical_scroll_bar_type (w, vertical_type); 6277 wset_vertical_scroll_bar_type (w, vertical_type);
6278 return w;
6279 }
6280 return NULL;
6281}
6330 6282
6331 adjust_window_margins (w); 6283DEFUN ("set-window-scroll-bars", Fset_window_scroll_bars,
6332 6284 Sset_window_scroll_bars, 2, 4, 0,
6333 clear_glyph_matrix (w->current_matrix); 6285 doc: /* Set width and type of scroll bars of window WINDOW.
6334 w->window_end_valid = 0; 6286WINDOW must be a live window and defaults to the selected one.
6335 6287
6336 ++windows_or_buffers_changed; 6288Second parameter WIDTH specifies the pixel width for the scroll bar;
6337 adjust_glyphs (XFRAME (WINDOW_FRAME (w))); 6289this is automatically adjusted to a multiple of the frame column width.
6338 } 6290Third parameter VERTICAL-TYPE specifies the type of the vertical scroll
6291bar: left, right, or nil.
6292If WIDTH is nil, use the frame's scroll-bar width.
6293If VERTICAL-TYPE is t, use the frame's scroll-bar type.
6294Fourth parameter HORIZONTAL-TYPE is currently unused.
6339 6295
6340 return Qnil; 6296Return t if scroll bars was actually changed and nil otherwise. */)
6297 (Lisp_Object window, Lisp_Object width,
6298 Lisp_Object vertical_type, Lisp_Object horizontal_type)
6299{
6300 struct window *w
6301 = set_window_scroll_bars (decode_live_window (window),
6302 width, vertical_type, horizontal_type);
6303 return w ? (apply_window_adjustment (w), Qt) : Qnil;
6341} 6304}
6342 6305
6343 6306
@@ -6466,38 +6429,6 @@ foreach_window_1 (struct window *w, int (*fn) (struct window *, void *), void *u
6466 return cont; 6429 return cont;
6467} 6430}
6468 6431
6469
6470/* Freeze or unfreeze the window start of W unless it is a
6471 mini-window or the selected window. FREEZE_P non-null means freeze
6472 the window start. */
6473
6474static int
6475freeze_window_start (struct window *w, void *freeze_p)
6476{
6477 if (MINI_WINDOW_P (w)
6478 || (WINDOWP (selected_window) /* Can be nil in corner cases. */
6479 && (w == XWINDOW (selected_window)
6480 || (MINI_WINDOW_P (XWINDOW (selected_window))
6481 && ! NILP (Vminibuf_scroll_window)
6482 && w == XWINDOW (Vminibuf_scroll_window)))))
6483 freeze_p = NULL;
6484
6485 w->frozen_window_start_p = freeze_p != NULL;
6486 return 1;
6487}
6488
6489
6490/* Freeze or unfreeze the window starts of all leaf windows on frame
6491 F, except the selected window and a mini-window. FREEZE_P non-zero
6492 means freeze the window start. */
6493
6494void
6495freeze_window_starts (struct frame *f, bool freeze_p)
6496{
6497 foreach_window (f, freeze_window_start, (void *) (freeze_p ? f : 0));
6498}
6499
6500
6501/*********************************************************************** 6432/***********************************************************************
6502 Initialization 6433 Initialization
6503 ***********************************************************************/ 6434 ***********************************************************************/