diff options
| author | Eli Zaretskii | 2002-02-16 12:40:51 +0000 |
|---|---|---|
| committer | Eli Zaretskii | 2002-02-16 12:40:51 +0000 |
| commit | 1df7e8f069e2e7a3b9b321ff8c42e59b314021d2 (patch) | |
| tree | bfb9952bd2d1512ae845ee41463ef086d3a874aa /src | |
| parent | 3996d07ad063cf83e5636ccac12008f2b8a5a72d (diff) | |
| download | emacs-1df7e8f069e2e7a3b9b321ff8c42e59b314021d2.tar.gz emacs-1df7e8f069e2e7a3b9b321ff8c42e59b314021d2.zip | |
(automatic_hscroll_margin, Vautomatic_hscroll_step): New variables.
(syms_of_xdisp): DEVFAR them.
(hscroll_window_tree): Use automatic_hscroll_margin and
Vautomatic_hscroll_step to compute the amount of window scrolling.
Diffstat (limited to 'src')
| -rw-r--r-- | src/xdisp.c | 98 |
1 files changed, 87 insertions, 11 deletions
diff --git a/src/xdisp.c b/src/xdisp.c index aec0e9e0f06..3766f0b5219 100644 --- a/src/xdisp.c +++ b/src/xdisp.c | |||
| @@ -582,6 +582,13 @@ int trace_move; | |||
| 582 | 582 | ||
| 583 | int automatic_hscrolling_p; | 583 | int automatic_hscrolling_p; |
| 584 | 584 | ||
| 585 | /* How close to the margin can point get before the window is scrolled | ||
| 586 | horizontally. */ | ||
| 587 | int automatic_hscroll_margin; | ||
| 588 | |||
| 589 | /* How much to scroll horizontally when point is inside the above margin. */ | ||
| 590 | Lisp_Object Vautomatic_hscroll_step; | ||
| 591 | |||
| 585 | /* A list of symbols, one for each supported image type. */ | 592 | /* A list of symbols, one for each supported image type. */ |
| 586 | 593 | ||
| 587 | Lisp_Object Vimage_types; | 594 | Lisp_Object Vimage_types; |
| @@ -8017,11 +8024,32 @@ hscroll_window_tree (window) | |||
| 8017 | Lisp_Object window; | 8024 | Lisp_Object window; |
| 8018 | { | 8025 | { |
| 8019 | int hscrolled_p = 0; | 8026 | int hscrolled_p = 0; |
| 8020 | 8027 | int hscroll_relative_p = FLOATP (Vautomatic_hscroll_step); | |
| 8028 | int hscroll_step_abs = 0; | ||
| 8029 | double hscroll_step_rel = 0; | ||
| 8030 | |||
| 8031 | if (hscroll_relative_p) | ||
| 8032 | { | ||
| 8033 | hscroll_step_rel = XFLOAT_DATA (Vautomatic_hscroll_step); | ||
| 8034 | if (hscroll_step_rel < 0) | ||
| 8035 | { | ||
| 8036 | hscroll_relative_p = 0; | ||
| 8037 | hscroll_step_abs = 0; | ||
| 8038 | } | ||
| 8039 | } | ||
| 8040 | else if (INTEGERP (Vautomatic_hscroll_step)) | ||
| 8041 | { | ||
| 8042 | hscroll_step_abs = XINT (Vautomatic_hscroll_step); | ||
| 8043 | if (hscroll_step_abs < 0) | ||
| 8044 | hscroll_step_abs = 0; | ||
| 8045 | } | ||
| 8046 | else | ||
| 8047 | hscroll_step_abs = 0; | ||
| 8048 | |||
| 8021 | while (WINDOWP (window)) | 8049 | while (WINDOWP (window)) |
| 8022 | { | 8050 | { |
| 8023 | struct window *w = XWINDOW (window); | 8051 | struct window *w = XWINDOW (window); |
| 8024 | 8052 | ||
| 8025 | if (WINDOWP (w->hchild)) | 8053 | if (WINDOWP (w->hchild)) |
| 8026 | hscrolled_p |= hscroll_window_tree (w->hchild); | 8054 | hscrolled_p |= hscroll_window_tree (w->hchild); |
| 8027 | else if (WINDOWP (w->vchild)) | 8055 | else if (WINDOWP (w->vchild)) |
| @@ -8043,24 +8071,25 @@ hscroll_window_tree (window) | |||
| 8043 | &text_area_width, &text_area_height); | 8071 | &text_area_width, &text_area_height); |
| 8044 | 8072 | ||
| 8045 | /* Scroll when cursor is inside this scroll margin. */ | 8073 | /* Scroll when cursor is inside this scroll margin. */ |
| 8046 | /* Shouldn't we export this `5' for customization ? -stef */ | 8074 | hscroll_margin |
| 8047 | hscroll_margin = 5 * CANON_X_UNIT (XFRAME (w->frame)); | 8075 | = automatic_hscroll_margin * CANON_X_UNIT (XFRAME (w->frame)); |
| 8048 | 8076 | ||
| 8049 | if ((XFASTINT (w->hscroll) | 8077 | if ((XFASTINT (w->hscroll) |
| 8050 | && w->cursor.x < hscroll_margin) | 8078 | && w->cursor.x <= hscroll_margin) |
| 8051 | || (cursor_row->enabled_p | 8079 | || (cursor_row->enabled_p |
| 8052 | && cursor_row->truncated_on_right_p | 8080 | && cursor_row->truncated_on_right_p |
| 8053 | && (w->cursor.x > text_area_width - hscroll_margin))) | 8081 | && (w->cursor.x >= text_area_width - hscroll_margin))) |
| 8054 | { | 8082 | { |
| 8055 | struct it it; | 8083 | struct it it; |
| 8056 | int hscroll; | 8084 | int hscroll; |
| 8057 | struct buffer *saved_current_buffer; | 8085 | struct buffer *saved_current_buffer; |
| 8058 | int pt; | 8086 | int pt; |
| 8087 | int wanted_x; | ||
| 8059 | 8088 | ||
| 8060 | /* Find point in a display of infinite width. */ | 8089 | /* Find point in a display of infinite width. */ |
| 8061 | saved_current_buffer = current_buffer; | 8090 | saved_current_buffer = current_buffer; |
| 8062 | current_buffer = XBUFFER (w->buffer); | 8091 | current_buffer = XBUFFER (w->buffer); |
| 8063 | 8092 | ||
| 8064 | if (w == XWINDOW (selected_window)) | 8093 | if (w == XWINDOW (selected_window)) |
| 8065 | pt = BUF_PT (current_buffer); | 8094 | pt = BUF_PT (current_buffer); |
| 8066 | else | 8095 | else |
| @@ -8077,9 +8106,33 @@ hscroll_window_tree (window) | |||
| 8077 | move_it_in_display_line_to (&it, pt, -1, MOVE_TO_POS); | 8106 | move_it_in_display_line_to (&it, pt, -1, MOVE_TO_POS); |
| 8078 | current_buffer = saved_current_buffer; | 8107 | current_buffer = saved_current_buffer; |
| 8079 | 8108 | ||
| 8080 | /* Center cursor in window. */ | 8109 | /* Position cursor in window. */ |
| 8081 | hscroll = (max (0, it.current_x - text_area_width / 2) | 8110 | if (!hscroll_relative_p && hscroll_step_abs == 0) |
| 8082 | / CANON_X_UNIT (it.f)); | 8111 | hscroll = max (0, it.current_x - text_area_width / 2) |
| 8112 | / CANON_X_UNIT (it.f); | ||
| 8113 | else if (w->cursor.x >= text_area_width - hscroll_margin) | ||
| 8114 | { | ||
| 8115 | if (hscroll_relative_p) | ||
| 8116 | wanted_x = text_area_width * (1 - hscroll_step_rel) | ||
| 8117 | - hscroll_margin; | ||
| 8118 | else | ||
| 8119 | wanted_x = text_area_width | ||
| 8120 | - hscroll_step_abs * CANON_X_UNIT (it.f) | ||
| 8121 | - hscroll_margin; | ||
| 8122 | hscroll | ||
| 8123 | = max (0, it.current_x - wanted_x) / CANON_X_UNIT (it.f); | ||
| 8124 | } | ||
| 8125 | else | ||
| 8126 | { | ||
| 8127 | if (hscroll_relative_p) | ||
| 8128 | wanted_x = text_area_width * hscroll_step_rel | ||
| 8129 | + hscroll_margin; | ||
| 8130 | else | ||
| 8131 | wanted_x = hscroll_step_abs * CANON_X_UNIT (it.f) | ||
| 8132 | + hscroll_margin; | ||
| 8133 | hscroll | ||
| 8134 | = max (0, it.current_x - wanted_x) / CANON_X_UNIT (it.f); | ||
| 8135 | } | ||
| 8083 | hscroll = max (hscroll, XFASTINT (w->min_hscroll)); | 8136 | hscroll = max (hscroll, XFASTINT (w->min_hscroll)); |
| 8084 | 8137 | ||
| 8085 | /* Don't call Fset_window_hscroll if value hasn't | 8138 | /* Don't call Fset_window_hscroll if value hasn't |
| @@ -15010,6 +15063,29 @@ nil means don't display a cursor there. */); | |||
| 15010 | DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p, | 15063 | DEFVAR_BOOL ("automatic-hscrolling", &automatic_hscrolling_p, |
| 15011 | doc: /* *Non-nil means scroll the display automatically to make point visible. */); | 15064 | doc: /* *Non-nil means scroll the display automatically to make point visible. */); |
| 15012 | automatic_hscrolling_p = 1; | 15065 | automatic_hscrolling_p = 1; |
| 15066 | |||
| 15067 | DEFVAR_INT ("automatic-hscroll-margin", &automatic_hscroll_margin, | ||
| 15068 | doc: /* *How many columns away from the window edge point is allowed to get | ||
| 15069 | before automatic hscrolling will horizontally scroll the window. */); | ||
| 15070 | automatic_hscroll_margin = 5; | ||
| 15071 | |||
| 15072 | DEFVAR_LISP ("automatic-hscroll-step", &Vautomatic_hscroll_step, | ||
| 15073 | doc: /* *How many columns to scroll the window when point gets too close to the edge. | ||
| 15074 | When point is less than `automatic-hscroll-margin' columns from the window | ||
| 15075 | edge, automatic hscrolling will scroll the window by the amount of columns | ||
| 15076 | determined by this variable. If its value is a positive integer, scroll that | ||
| 15077 | many columns. If it's a positive floating-point number, it specifies the | ||
| 15078 | fraction of the window's width to scroll. If it's nil or zero, point will be | ||
| 15079 | centered horizontally after the scroll. Any other value, including negative | ||
| 15080 | numbers, are treated as if the value were zero. | ||
| 15081 | |||
| 15082 | Automatic hscrolling always moves point outside the scroll margin, so if | ||
| 15083 | point was more than scroll step columns inside the margin, the window will | ||
| 15084 | scroll more than the value given by the scroll step. | ||
| 15085 | |||
| 15086 | Note that the lower bound for automatic hscrolling specified by `scroll-left' | ||
| 15087 | and `scroll-right' overrides this variable's effect. */); | ||
| 15088 | Vautomatic_hscroll_step = make_number (0); | ||
| 15013 | 15089 | ||
| 15014 | DEFVAR_LISP ("image-types", &Vimage_types, | 15090 | DEFVAR_LISP ("image-types", &Vimage_types, |
| 15015 | doc: /* List of supported image types. | 15091 | doc: /* List of supported image types. |