aboutsummaryrefslogtreecommitdiffstats
path: root/src/window.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/window.c')
-rw-r--r--src/window.c112
1 files changed, 66 insertions, 46 deletions
diff --git a/src/window.c b/src/window.c
index d8e09162228..93fef54c95f 100644
--- a/src/window.c
+++ b/src/window.c
@@ -63,7 +63,7 @@ static Lisp_Object Qreplace_buffer_in_windows, Qget_mru_window;
63static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically; 63static Lisp_Object Qwindow_resize_root_window, Qwindow_resize_root_window_vertically;
64static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command; 64static Lisp_Object Qscroll_up, Qscroll_down, Qscroll_command;
65static Lisp_Object Qsafe, Qabove, Qbelow; 65static Lisp_Object Qsafe, Qabove, Qbelow;
66static Lisp_Object Qauto_buffer_name, Qclone_of; 66static Lisp_Object Qclone_of;
67 67
68static int displayed_window_lines (struct window *); 68static int displayed_window_lines (struct window *);
69static int count_windows (struct window *); 69static int count_windows (struct window *);
@@ -270,7 +270,7 @@ decode_any_window (register Lisp_Object window)
270 return w; 270 return w;
271} 271}
272 272
273struct window * 273static struct window *
274decode_valid_window (register Lisp_Object window) 274decode_valid_window (register Lisp_Object window)
275{ 275{
276 struct window *w; 276 struct window *w;
@@ -479,6 +479,9 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
479 record_buffer (w->buffer); 479 record_buffer (w->buffer);
480 } 480 }
481 481
482 /* Make the selected window's buffer current. */
483 Fset_buffer (w->buffer);
484
482 if (EQ (window, selected_window) && !inhibit_point_swap) 485 if (EQ (window, selected_window) && !inhibit_point_swap)
483 return window; 486 return window;
484 487
@@ -498,9 +501,9 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
498 else 501 else
499 fset_selected_window (sf, window); 502 fset_selected_window (sf, window);
500 503
501 /* Store the current buffer's actual point into the 504 /* Store the old selected window's buffer's point in pointm of the old
502 old selected window. It belongs to that window, 505 selected window. It belongs to that window, and when the window is
503 and when the window is not selected, must be in the window. */ 506 not selected, must be in the window. */
504 if (!inhibit_point_swap) 507 if (!inhibit_point_swap)
505 { 508 {
506 ow = XWINDOW (selected_window); 509 ow = XWINDOW (selected_window);
@@ -511,9 +514,6 @@ select_window (Lisp_Object window, Lisp_Object norecord, int inhibit_point_swap)
511 } 514 }
512 515
513 selected_window = window; 516 selected_window = window;
514
515 Fset_buffer (w->buffer);
516
517 bset_last_selected_window (XBUFFER (w->buffer), window); 517 bset_last_selected_window (XBUFFER (w->buffer), window);
518 518
519 /* Go to the point recorded in the window. 519 /* Go to the point recorded in the window.
@@ -1409,22 +1409,21 @@ DEFUN ("window-point", Fwindow_point, Swindow_point, 0, 1, 0,
1409 doc: /* Return current value of point in WINDOW. 1409 doc: /* Return current value of point in WINDOW.
1410WINDOW must be a live window and defaults to the selected one. 1410WINDOW must be a live window and defaults to the selected one.
1411 1411
1412For a nonselected window, this is the value point would have 1412For a nonselected window, this is the value point would have if that
1413if that window were selected. 1413window were selected.
1414 1414
1415Note that, when WINDOW is the selected window and its buffer 1415Note that, when WINDOW is selected, the value returned is the same as
1416is also currently selected, the value returned is the same as (point). 1416that returned by `point' for WINDOW's buffer. It would be more strictly
1417It would be more strictly correct to return the `top-level' value 1417correct to return the `top-level' value of `point', outside of any
1418of point, outside of any save-excursion forms. 1418`save-excursion' forms. But that is hard to define. */)
1419But that is hard to define. */)
1420 (Lisp_Object window) 1419 (Lisp_Object window)
1421{ 1420{
1422 register struct window *w = decode_live_window (window); 1421 register struct window *w = decode_live_window (window);
1423 1422
1424 if (w == XWINDOW (selected_window) 1423 if (w == XWINDOW (selected_window))
1425 && current_buffer == XBUFFER (w->buffer)) 1424 return make_number (BUF_PT (XBUFFER (w->buffer)));
1426 return Fpoint (); 1425 else
1427 return Fmarker_position (w->pointm); 1426 return Fmarker_position (w->pointm);
1428} 1427}
1429 1428
1430DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0, 1429DEFUN ("window-start", Fwindow_start, Swindow_start, 0, 1, 0,
@@ -1534,16 +1533,27 @@ Return POS. */)
1534 register struct window *w = decode_live_window (window); 1533 register struct window *w = decode_live_window (window);
1535 1534
1536 CHECK_NUMBER_COERCE_MARKER (pos); 1535 CHECK_NUMBER_COERCE_MARKER (pos);
1537 if (w == XWINDOW (selected_window)
1538 && XBUFFER (w->buffer) == current_buffer)
1539 Fgoto_char (pos);
1540 else
1541 set_marker_restricted (w->pointm, pos, w->buffer);
1542 1536
1543 /* We have to make sure that redisplay updates the window to show 1537 if (w == XWINDOW (selected_window))
1544 the new value of point. */ 1538 {
1545 if (!EQ (window, selected_window)) 1539 if (XBUFFER (w->buffer) == current_buffer)
1546 ++windows_or_buffers_changed; 1540 Fgoto_char (pos);
1541 else
1542 {
1543 struct buffer *old_buffer = current_buffer;
1544
1545 set_buffer_internal (XBUFFER (w->buffer));
1546 Fgoto_char (pos);
1547 set_buffer_internal (old_buffer);
1548 }
1549 }
1550 else
1551 {
1552 set_marker_restricted (w->pointm, pos, w->buffer);
1553 /* We have to make sure that redisplay updates the window to show
1554 the new value of point. */
1555 ++windows_or_buffers_changed;
1556 }
1547 1557
1548 return pos; 1558 return pos;
1549} 1559}
@@ -1960,6 +1970,9 @@ unshow_buffer (register struct window *w)
1960 is actually stored in that buffer, and the window's pointm isn't used. 1970 is actually stored in that buffer, and the window's pointm isn't used.
1961 So don't clobber point in that buffer. */ 1971 So don't clobber point in that buffer. */
1962 if (! EQ (buf, XWINDOW (selected_window)->buffer) 1972 if (! EQ (buf, XWINDOW (selected_window)->buffer)
1973 /* Don't clobber point in current buffer either (this could be
1974 useful in connection with bug#12208).
1975 && XBUFFER (buf) != current_buffer */
1963 /* This line helps to fix Horsley's testbug.el bug. */ 1976 /* This line helps to fix Horsley's testbug.el bug. */
1964 && !(WINDOWP (BVAR (b, last_selected_window)) 1977 && !(WINDOWP (BVAR (b, last_selected_window))
1965 && w != XWINDOW (BVAR (b, last_selected_window)) 1978 && w != XWINDOW (BVAR (b, last_selected_window))
@@ -3089,7 +3102,7 @@ run_window_configuration_change_hook (struct frame *f)
3089 /* Use the right buffer. Matters when running the local hooks. */ 3102 /* Use the right buffer. Matters when running the local hooks. */
3090 if (current_buffer != XBUFFER (Fwindow_buffer (Qnil))) 3103 if (current_buffer != XBUFFER (Fwindow_buffer (Qnil)))
3091 { 3104 {
3092 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 3105 record_unwind_current_buffer ();
3093 Fset_buffer (Fwindow_buffer (Qnil)); 3106 Fset_buffer (Fwindow_buffer (Qnil));
3094 } 3107 }
3095 3108
@@ -3126,7 +3139,7 @@ run_window_configuration_change_hook (struct frame *f)
3126DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook, 3139DEFUN ("run-window-configuration-change-hook", Frun_window_configuration_change_hook,
3127 Srun_window_configuration_change_hook, 1, 1, 0, 3140 Srun_window_configuration_change_hook, 1, 1, 0,
3128 doc: /* Run `window-configuration-change-hook' for FRAME. */) 3141 doc: /* Run `window-configuration-change-hook' for FRAME. */)
3129 (Lisp_Object frame) 3142 (Lisp_Object frame)
3130{ 3143{
3131 CHECK_LIVE_FRAME (frame); 3144 CHECK_LIVE_FRAME (frame);
3132 run_window_configuration_change_hook (XFRAME (frame)); 3145 run_window_configuration_change_hook (XFRAME (frame));
@@ -3193,7 +3206,7 @@ set_window_buffer (Lisp_Object window, Lisp_Object buffer, int run_hooks_p, int
3193 because that might itself be a local variable. */ 3206 because that might itself be a local variable. */
3194 if (window_initialized) 3207 if (window_initialized)
3195 { 3208 {
3196 record_unwind_protect (Fset_buffer, Fcurrent_buffer ()); 3209 record_unwind_current_buffer ();
3197 Fset_buffer (buffer); 3210 Fset_buffer (buffer);
3198 } 3211 }
3199 3212
@@ -5531,7 +5544,6 @@ the return value is nil. Otherwise the value is t. */)
5531 struct Lisp_Vector *saved_windows; 5544 struct Lisp_Vector *saved_windows;
5532 Lisp_Object new_current_buffer; 5545 Lisp_Object new_current_buffer;
5533 Lisp_Object frame; 5546 Lisp_Object frame;
5534 Lisp_Object auto_buffer_name;
5535 FRAME_PTR f; 5547 FRAME_PTR f;
5536 ptrdiff_t old_point = -1; 5548 ptrdiff_t old_point = -1;
5537 5549
@@ -5607,6 +5619,21 @@ the return value is nil. Otherwise the value is t. */)
5607 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f); 5619 int previous_frame_menu_bar_lines = FRAME_MENU_BAR_LINES (f);
5608 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f); 5620 int previous_frame_tool_bar_lines = FRAME_TOOL_BAR_LINES (f);
5609 5621
5622 /* Don't do this within the main loop below: This may call Lisp
5623 code and is thus potentially unsafe while input is blocked. */
5624 for (k = 0; k < saved_windows->header.size; k++)
5625 {
5626 p = SAVED_WINDOW_N (saved_windows, k);
5627 window = p->window;
5628 w = XWINDOW (window);
5629 if (!NILP (w->buffer)
5630 && !EQ (w->buffer, p->buffer)
5631 && !NILP (BVAR (XBUFFER (p->buffer), name)))
5632 /* If a window we restore gets another buffer, record the
5633 window's old buffer. */
5634 call1 (Qrecord_window_buffer, window);
5635 }
5636
5610 /* The mouse highlighting code could get screwed up 5637 /* The mouse highlighting code could get screwed up
5611 if it runs during this. */ 5638 if it runs during this. */
5612 BLOCK_INPUT; 5639 BLOCK_INPUT;
@@ -5785,18 +5812,6 @@ the return value is nil. Otherwise the value is t. */)
5785 BUF_PT_BYTE (XBUFFER (w->buffer))); 5812 BUF_PT_BYTE (XBUFFER (w->buffer)));
5786 w->start_at_line_beg = 1; 5813 w->start_at_line_beg = 1;
5787 } 5814 }
5788 else if (STRINGP (auto_buffer_name =
5789 Fwindow_parameter (window, Qauto_buffer_name))
5790 && SCHARS (auto_buffer_name) != 0
5791 && (wset_buffer (w, Fget_buffer_create (auto_buffer_name)),
5792 !NILP (w->buffer)))
5793 {
5794 set_marker_restricted (w->start,
5795 make_number (0), w->buffer);
5796 set_marker_restricted (w->pointm,
5797 make_number (0), w->buffer);
5798 w->start_at_line_beg = 1;
5799 }
5800 else 5815 else
5801 /* Window has no live buffer, get one. */ 5816 /* Window has no live buffer, get one. */
5802 { 5817 {
@@ -5894,7 +5909,13 @@ the return value is nil. Otherwise the value is t. */)
5894 } 5909 }
5895 5910
5896 if (!NILP (new_current_buffer)) 5911 if (!NILP (new_current_buffer))
5897 Fset_buffer (new_current_buffer); 5912 {
5913 Fset_buffer (new_current_buffer);
5914 /* If the new current buffer doesn't appear in the selected
5915 window, go to its old point (see bug#12208). */
5916 if (!EQ (XWINDOW (data->current_window)->buffer, new_current_buffer))
5917 Fgoto_char (make_number (old_point));
5918 }
5898 5919
5899 Vminibuf_scroll_window = data->minibuf_scroll_window; 5920 Vminibuf_scroll_window = data->minibuf_scroll_window;
5900 minibuf_selected_window = data->minibuf_selected_window; 5921 minibuf_selected_window = data->minibuf_selected_window;
@@ -6696,7 +6717,6 @@ syms_of_window (void)
6696 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook"); 6717 DEFSYM (Qtemp_buffer_show_hook, "temp-buffer-show-hook");
6697 DEFSYM (Qabove, "above"); 6718 DEFSYM (Qabove, "above");
6698 DEFSYM (Qbelow, "below"); 6719 DEFSYM (Qbelow, "below");
6699 DEFSYM (Qauto_buffer_name, "auto-buffer-name");
6700 DEFSYM (Qclone_of, "clone-of"); 6720 DEFSYM (Qclone_of, "clone-of");
6701 6721
6702 staticpro (&Vwindow_list); 6722 staticpro (&Vwindow_list);