aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBasil L. Contovounesios2018-05-01 13:48:30 +0100
committerNoam Postavsky2018-05-10 19:04:11 -0400
commiteabb6f6c3ee75dac1a7510e80bdd3c2fcfbbbcb5 (patch)
tree01437a50671e79777b46d11f2638ffa63790ef0b
parentae92f52c75383cf8f332db184d91f10fa8fb67cb (diff)
downloademacs-eabb6f6c3ee75dac1a7510e80bdd3c2fcfbbbcb5.tar.gz
emacs-eabb6f6c3ee75dac1a7510e80bdd3c2fcfbbbcb5.zip
Rewrite scroll-other-window-down in C (bug#30207)
* lisp/window.el (scroll-other-window-down): Move to src/window.c as Fscroll_other_window_down. * src/window.c (scroll_command): Generalise for arbitrary windows. (Fscroll_up, Fscroll_down): Use scroll_command with selected_window. (Fscroll_other_window, Fscroll_other_window_down): Rewrite in terms of scroll_command. (syms_of_window): Add Sscroll_other_window_down.
-rw-r--r--lisp/window.el11
-rw-r--r--src/window.c85
2 files changed, 45 insertions, 51 deletions
diff --git a/lisp/window.el b/lisp/window.el
index bc2008e1d9c..085e51646f8 100644
--- a/lisp/window.el
+++ b/lisp/window.el
@@ -8923,17 +8923,6 @@ This is different from `scroll-down-command' that scrolls a full screen."
8923(put 'scroll-down-line 'scroll-command t) 8923(put 'scroll-down-line 'scroll-command t)
8924 8924
8925 8925
8926(defun scroll-other-window-down (&optional lines)
8927 "Scroll the \"other window\" down.
8928For more details, see the documentation for `scroll-other-window'."
8929 (interactive "P")
8930 (scroll-other-window
8931 ;; Just invert the argument's meaning.
8932 ;; We can do that without knowing which window it will be.
8933 (if (eq lines '-) nil
8934 (if (null lines) '-
8935 (- (prefix-numeric-value lines))))))
8936
8937(defun beginning-of-buffer-other-window (arg) 8926(defun beginning-of-buffer-other-window (arg)
8938 "Move point to the beginning of the buffer in the other window. 8927 "Move point to the beginning of the buffer in the other window.
8939Leave mark at previous position. 8928Leave mark at previous position.
diff --git a/src/window.c b/src/window.c
index af317674bb6..f654d87e14a 100644
--- a/src/window.c
+++ b/src/window.c
@@ -5634,35 +5634,54 @@ window_scroll_line_based (Lisp_Object window, int n, bool whole, bool noerror)
5634} 5634}
5635 5635
5636 5636
5637/* Scroll selected_window up or down. If N is nil, scroll a 5637/* Scroll WINDOW up or down. If N is nil, scroll upward by a
5638 screen-full which is defined as the height of the window minus 5638 screen-full which is defined as the height of the window minus
5639 next_screen_context_lines. If N is the symbol `-', scroll. 5639 next_screen_context_lines. If N is the symbol `-', scroll downward
5640 DIRECTION may be 1 meaning to scroll down, or -1 meaning to scroll 5640 by a screen-full. DIRECTION may be 1 meaning to scroll down, or -1
5641 up. This is the guts of Fscroll_up and Fscroll_down. */ 5641 meaning to scroll up. */
5642 5642
5643static void 5643static void
5644scroll_command (Lisp_Object n, int direction) 5644scroll_command (Lisp_Object window, Lisp_Object n, int direction)
5645{ 5645{
5646 struct window *w;
5647 bool other_window;
5646 ptrdiff_t count = SPECPDL_INDEX (); 5648 ptrdiff_t count = SPECPDL_INDEX ();
5647 5649
5648 eassert (eabs (direction) == 1); 5650 eassert (eabs (direction) == 1);
5649 5651
5650 /* If selected window's buffer isn't current, make it current for 5652 w = XWINDOW (window);
5653 other_window = ! EQ (window, selected_window);
5654
5655 /* If given window's buffer isn't current, make it current for
5651 the moment. But don't screw up if window_scroll gets an error. */ 5656 the moment. But don't screw up if window_scroll gets an error. */
5652 if (XBUFFER (XWINDOW (selected_window)->contents) != current_buffer) 5657 if (XBUFFER (w->contents) != current_buffer)
5653 { 5658 {
5654 record_unwind_protect (save_excursion_restore, save_excursion_save ()); 5659 record_unwind_protect (save_excursion_restore, save_excursion_save ());
5655 Fset_buffer (XWINDOW (selected_window)->contents); 5660 Fset_buffer (w->contents);
5661 }
5662
5663 if (other_window)
5664 {
5665 SET_PT_BOTH (marker_position (w->pointm),
5666 marker_byte_position (w->pointm));
5667 SET_PT_BOTH (marker_position (w->old_pointm),
5668 marker_byte_position (w->old_pointm));
5656 } 5669 }
5657 5670
5658 if (NILP (n)) 5671 if (NILP (n))
5659 window_scroll (selected_window, direction, true, false); 5672 window_scroll (window, direction, true, false);
5660 else if (EQ (n, Qminus)) 5673 else if (EQ (n, Qminus))
5661 window_scroll (selected_window, -direction, true, false); 5674 window_scroll (window, -direction, true, false);
5662 else 5675 else
5663 { 5676 {
5664 n = Fprefix_numeric_value (n); 5677 n = Fprefix_numeric_value (n);
5665 window_scroll (selected_window, XINT (n) * direction, false, false); 5678 window_scroll (window, XINT (n) * direction, false, false);
5679 }
5680
5681 if (other_window)
5682 {
5683 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
5684 set_marker_both (w->old_pointm, Qnil, PT, PT_BYTE);
5666 } 5685 }
5667 5686
5668 unbind_to (count, Qnil); 5687 unbind_to (count, Qnil);
@@ -5677,7 +5696,7 @@ If ARG is the atom `-', scroll downward by nearly full screen.
5677When calling from a program, supply as argument a number, nil, or `-'. */) 5696When calling from a program, supply as argument a number, nil, or `-'. */)
5678 (Lisp_Object arg) 5697 (Lisp_Object arg)
5679{ 5698{
5680 scroll_command (arg, 1); 5699 scroll_command (selected_window, arg, 1);
5681 return Qnil; 5700 return Qnil;
5682} 5701}
5683 5702
@@ -5690,7 +5709,7 @@ If ARG is the atom `-', scroll upward by nearly full screen.
5690When calling from a program, supply as argument a number, nil, or `-'. */) 5709When calling from a program, supply as argument a number, nil, or `-'. */)
5691 (Lisp_Object arg) 5710 (Lisp_Object arg)
5692{ 5711{
5693 scroll_command (arg, -1); 5712 scroll_command (selected_window, arg, -1);
5694 return Qnil; 5713 return Qnil;
5695} 5714}
5696 5715
@@ -5750,36 +5769,21 @@ It is determined by the function `other-window-for-scrolling',
5750which see. */) 5769which see. */)
5751 (Lisp_Object arg) 5770 (Lisp_Object arg)
5752{ 5771{
5753 Lisp_Object window;
5754 struct window *w;
5755 ptrdiff_t count = SPECPDL_INDEX (); 5772 ptrdiff_t count = SPECPDL_INDEX ();
5756 5773 scroll_command (Fother_window_for_scrolling (), arg, 1);
5757 window = Fother_window_for_scrolling ();
5758 w = XWINDOW (window);
5759
5760 /* Don't screw up if window_scroll gets an error. */
5761 record_unwind_protect (save_excursion_restore, save_excursion_save ());
5762
5763 Fset_buffer (w->contents);
5764 SET_PT_BOTH (marker_position (w->pointm), marker_byte_position (w->pointm));
5765 SET_PT_BOTH (marker_position (w->old_pointm), marker_byte_position (w->old_pointm));
5766
5767 if (NILP (arg))
5768 window_scroll (window, 1, true, true);
5769 else if (EQ (arg, Qminus))
5770 window_scroll (window, -1, true, true);
5771 else
5772 {
5773 if (CONSP (arg))
5774 arg = XCAR (arg);
5775 CHECK_NUMBER (arg);
5776 window_scroll (window, XINT (arg), false, true);
5777 }
5778
5779 set_marker_both (w->pointm, Qnil, PT, PT_BYTE);
5780 set_marker_both (w->old_pointm, Qnil, PT, PT_BYTE);
5781 unbind_to (count, Qnil); 5774 unbind_to (count, Qnil);
5775 return Qnil;
5776}
5782 5777
5778DEFUN ("scroll-other-window-down", Fscroll_other_window_down,
5779 Sscroll_other_window_down, 0, 1, "P",
5780 doc: /* Scroll next window downward ARG lines; or near full screen if no ARG.
5781For more details, see the documentation for `scroll-other-window'. */)
5782 (Lisp_Object arg)
5783{
5784 ptrdiff_t count = SPECPDL_INDEX ();
5785 scroll_command (Fother_window_for_scrolling (), arg, -1);
5786 unbind_to (count, Qnil);
5783 return Qnil; 5787 return Qnil;
5784} 5788}
5785 5789
@@ -7831,6 +7835,7 @@ displayed after a scrolling operation to be somewhat inaccurate. */);
7831 defsubr (&Sscroll_right); 7835 defsubr (&Sscroll_right);
7832 defsubr (&Sother_window_for_scrolling); 7836 defsubr (&Sother_window_for_scrolling);
7833 defsubr (&Sscroll_other_window); 7837 defsubr (&Sscroll_other_window);
7838 defsubr (&Sscroll_other_window_down);
7834 defsubr (&Sminibuffer_selected_window); 7839 defsubr (&Sminibuffer_selected_window);
7835 defsubr (&Srecenter); 7840 defsubr (&Srecenter);
7836 defsubr (&Swindow_text_width); 7841 defsubr (&Swindow_text_width);