[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[5612] info cursor movement commands
From: |
Gavin D. Smith |
Subject: |
[5612] info cursor movement commands |
Date: |
Thu, 29 May 2014 01:51:39 +0000 |
Revision: 5612
http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5612
Author: gavin
Date: 2014-05-29 01:51:37 +0000 (Thu, 29 May 2014)
Log Message:
-----------
info cursor movement commands
Modified Paths:
--------------
trunk/ChangeLog
trunk/info/session.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2014-05-27 18:03:29 UTC (rev 5611)
+++ trunk/ChangeLog 2014-05-29 01:51:37 UTC (rev 5612)
@@ -1,3 +1,28 @@
+2014-05-28 Gavin Smith <address@hidden>
+
+ * info/session.c (point_next_line, point_prev_line): Check for
+ whether we should call forward_move_node_structure or
+ backward_move_node_structure added.
+ (point_prev_line): Go to end of previous line instead of start.
+ (info_forward_char, info_backward_char, info_forward_word)
+ (info_backward_word): Rely on checks in point_next_line,
+ point_prev_line.
+
+ (point_next_line, point_prev_line, point_forward_char)
+ (point_backward_char, point_forward_word, point_backward_word):
+ Rely on line map already being calculated for current line.
+
+ (point_skip_ws_forward): Merged into point_forward_word.
+ (point_skip_ws_backward): Merged into point_backward_word.
+
+ (looking_at_alnum): New function.
+ (_looking_at_newline, looking_at_newline): Renamed.
+ (point_forward_word, point_backward_word): Call looking_at_alnum.
+
+ (move_to_new_line): First argument deleted. All callers updated.
+
+ Some definitions moved in file for better organization.
+
2014-05-27 Gavin Smith <address@hidden>
* info/info.c (add_initial_nodes) <--show-options>: Avoid loading
Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c 2014-05-27 18:03:29 UTC (rev 5611)
+++ trunk/info/session.c 2014-05-29 01:51:37 UTC (rev 5612)
@@ -502,74 +502,9 @@
/* */
/* **************************************************************** */
-/* Change the pagetop of WINDOW to DESIRED_TOP, perhaps scrolling the screen
- to do so. */
-void
-set_window_pagetop (WINDOW *window, int desired_top)
-{
- int point_line, old_pagetop;
+/* Controls whether scroll-behavior affects line movement commands */
+int cursor_movement_scrolls_p = 1;
- if (desired_top < 0)
- desired_top = 0;
- else if (desired_top > window->line_count)
- desired_top = window->line_count - 1;
-
- if (window->pagetop == desired_top)
- return;
-
- old_pagetop = window->pagetop;
- window->pagetop = desired_top;
-
- /* Make sure that point appears in this window. */
- point_line = window_line_of_point (window);
- if ((point_line < window->pagetop) ||
- ((point_line - window->pagetop) > window->height - 1))
- window->point =
- window->line_starts[window->pagetop];
-
- window->flags |= W_UpdateWindow;
-
- /* Find out which direction to scroll, and scroll the window in that
- direction. Do this only if there would be a savings in redisplay
- time. This is true if the amount to scroll is less than the height
- of the window, and if the number of lines scrolled would be greater
- than 10 % of the window's height.
-
- To prevent status line blinking when keeping up or down key,
- scrolling is disabled if the amount to scroll is 1. */
- if (old_pagetop < desired_top)
- {
- int start, end, amount;
-
- amount = desired_top - old_pagetop;
-
- if (amount == 1 ||
- (amount >= window->height) ||
- (((window->height - amount) * 10) < window->height))
- return;
-
- start = amount + window->first_row;
- end = window->height + window->first_row;
-
- display_scroll_display (start, end, -amount);
- }
- else
- {
- int start, end, amount;
-
- amount = old_pagetop - desired_top;
-
- if (amount == 1 ||
- (amount >= window->height) ||
- (((window->height - amount) * 10) < window->height))
- return;
-
- start = window->first_row;
- end = (window->first_row + window->height) - amount;
- display_scroll_display (start, end, amount);
- }
-}
-
/* Immediately make WINDOW->point visible on the screen, and move the
terminal cursor there. */
static void
@@ -594,28 +529,22 @@
display_cursor_at_point (window);
}
-/* Move WINDOW->point from OLD line index to NEW line index. */
+/* Move WINDOW->point to NEW line index, trying to place cursor in
+ goal column. */
static void
-move_to_new_line (int old, int new, WINDOW *window)
+move_to_new_line (int new, WINDOW *window)
{
- if (old == -1)
- {
- info_error ("%s", msg_cant_find_point);
- }
- else
- {
- int goal;
+ int goal;
- if (new >= window->line_count || new < 0)
- return;
-
- goal = window_get_goal_column (window);
- window->goal_column = goal;
+ if (new >= window->line_count || new < 0)
+ return;
+
+ goal = window_get_goal_column (window);
+ window->goal_column = goal;
- window->point = window->line_starts[new];
- window->point += window_chars_to_goal (window, goal);
- info_show_point (window);
- }
+ window->point = window->line_starts[new];
+ window->point += window_chars_to_goal (window, goal);
+ info_show_point (window);
}
static int forward_move_node_structure (WINDOW *window, int behaviour);
@@ -647,13 +576,13 @@
if (forward_move_node_structure (window,
info_scroll_behaviour))
break;
- move_to_new_line (0, 0, window);
+ move_to_new_line (0, window);
}
else
break;
}
else
- move_to_new_line (old_line, new_line, window);
+ move_to_new_line (new_line, window);
}
}
@@ -684,250 +613,207 @@
break;
if (window->line_count > window->height)
set_window_pagetop (window, window->line_count - window->height);
- move_to_new_line (window->line_count,
- window->line_count - 1, window);
+ move_to_new_line (window->line_count - 1, window);
}
else
- move_to_new_line (old_line, new_line, window);
+ move_to_new_line (new_line, window);
}
}
/* Return true if POINT sits on a newline character. */
static int
-_looking_at_newline (WINDOW *win, long point)
+looking_at_newline (WINDOW *win, long point)
{
mbi_iterator_t iter;
-
mbi_init (iter, win->node->contents + point,
win->node->nodelen - point);
mbi_avail (iter);
return mbi_cur (iter).wc_valid && mbi_cur (iter).wc == '\n';
}
-/* Advance point of WIN to the beginning of the next logical line.
- Return 1 if there is no next line. */
+/* Return true if WIN->point sits on an alphanumeric character. */
static int
+looking_at_alnum (WINDOW *win)
+{
+ mbi_iterator_t iter;
+ mbi_init (iter, win->node->contents + win->point,
+ win->node->nodelen - win->point);
+ mbi_avail (iter);
+
+ return mbi_cur (iter).wc_valid && iswalnum (mbi_cur (iter).wc);
+}
+
+/* Advance point of WIN to the beginning of the next logical line. Return
+ 0 if we can't go any further. */
+static int
point_next_line (WINDOW *win)
{
int line = window_line_of_point (win);
- if (line + 1 >= win->line_count)
- return 1;
- win->point = win->line_starts[line + 1];
- window_compute_line_map (win);
+ if (line + 1 < win->line_count)
+ {
+ win->point = win->line_starts[line + 1];
+ window_compute_line_map (win);
+ return 1;
+ }
+
+ if (cursor_movement_scrolls_p
+ && forward_move_node_structure (win, info_scroll_behaviour) == 0)
+ {
+ win->point = 0;
+ return 1;
+ }
+
+ win->point = win->node->nodelen - 1;
return 0;
}
-/* Move point of WIN to the beginning of the previous logical
- line.
- Return 1 if there is no previous line. */
+/* Move point of WIN to the end of the previous logical line. Return
+ 0 if we can't go any further. */
static int
point_prev_line (WINDOW *win)
{
int line = window_line_of_point (win);
- if (line == 0)
- return 1;
- win->point = win->line_starts[line - 1];
- window_compute_line_map (win);
+ if (line > 0)
+ {
+ win->point = win->line_starts[line - 1];
+ window_compute_line_map (win);
+ win->point = win->line_map.map[win->line_map.used - 1];
+ return 1;
+ }
+
+ if (cursor_movement_scrolls_p
+ && backward_move_node_structure (win, info_scroll_behaviour) == 0)
+ {
+ win->point = win->node->nodelen - 1;
+ if (win->line_count > win->height)
+ set_window_pagetop (win, win->line_count - win->height);
+ return 1;
+ }
+
+ win->point = 0;
return 0;
}
-/* Advance point to the next multibyte character. Return 1 if this would
- cause pointing past the end of node buffer. */
-static int
+/* Advance point to the next multibyte character. */
+static void
point_forward_char (WINDOW *win)
{
long point = win->point;
int col;
- window_compute_line_map (win);
col = window_point_to_column (win, point, &point) + 1;
- if (col >= win->line_map.used)
- {
- if (point_next_line (win))
- return 1;
- col = 0;
- }
- win->point = win->line_map.map[col];
- return 0;
+ if (col < win->line_map.used)
+ win->point = win->line_map.map[col];
+ else
+ point_next_line (win);
}
-/* Set point to the previous multibyte character.
- Return 1 if already on the beginning of node buffer. */
-static int
+/* Set point to the previous multibyte character. */
+static void
point_backward_char (WINDOW *win)
{
long point = win->point;
int col;
- window_compute_line_map (win);
col = window_point_to_column (win, point, &point);
for (; col >= 0 && win->line_map.map[col] == point; col--)
;
- if (col < 0)
- {
- if (point_prev_line (win))
- return 1;
- col = win->line_map.used - 1;
- }
- win->point = win->line_map.map[col];
- return 0;
+
+ if (col >= 0)
+ win->point = win->line_map.map[col];
+ else
+ point_prev_line (win);
}
-/* Skip forward any white space characters starting from column *PCOL in
- the current line, advancing line if necessary. Return 1 if going past
- the end of node buffer. */
-static int
-point_skip_ws_forward (WINDOW *win, int *pcol)
+/* Advance window point to the beginning of the next word. */
+static void
+point_forward_word (WINDOW *win)
{
- mbi_iterator_t iter;
- int col = *pcol;
+ int col;
+ col = window_point_to_column (win, win->point, &win->point);
+
+ /* Skip white space forwards. */
while (1)
{
- char *buffer = win->node->contents;
- size_t buflen = win->node->nodelen;
-
for (; col < win->line_map.used; col++)
{
- mbi_init (iter, buffer + win->line_map.map[col],
- buflen - win->line_map.map[col]);
- mbi_avail (iter);
- if (!mbi_cur (iter).wc_valid || iswalnum (mbi_cur (iter).wc))
- {
- *pcol = col;
- return 0;
- }
+ win->point = win->line_map.map[col];
+ if (looking_at_alnum (win))
+ goto skipped_whitespace;
}
- if (point_next_line (win))
- return 1;
+ if (!point_next_line (win))
+ return;
col = 0;
}
- return 1;
-}
+ skipped_whitespace:
-/* Skip backward any white space characters starting from column *PCOL in
- the current line, retracting line if necessary. Return 1 if going
- before the beginning of node buffer. */
-static int
-point_skip_ws_backward (WINDOW *win, int *pcol)
-{
- mbi_iterator_t iter;
- int col = *pcol;
-
while (1)
{
- char *buffer = win->node->contents;
- size_t buflen = win->node->nodelen;
-
- for (; col > 0; col--)
+ for (; col < win->line_map.used; col++)
{
- mbi_init (iter, buffer + win->line_map.map[col],
- buflen - win->line_map.map[col]);
- mbi_avail (iter);
- if (!mbi_cur (iter).wc_valid || iswalnum (mbi_cur (iter).wc))
- {
- *pcol = col;
- return 0;
- }
+ win->point = win->line_map.map[col];
+ if (!looking_at_alnum (win))
+ return;
}
- if (point_prev_line (win))
- return 1;
- col = win->line_map.used - 1;
+ if (!point_next_line (win))
+ return;
+ col = 0;
}
- return 1;
}
-/* Advance window point to the beginning of the next word. Return 1
- if there are no more words in the buffer. */
-static int
-point_forward_word (WINDOW *win)
+/* Set window point to the beginning of the previous word. */
+static void
+point_backward_word (WINDOW *win)
{
- mbi_iterator_t iter;
int col;
- window_compute_line_map (win);
+ point_backward_char (win);
col = window_point_to_column (win, win->point, &win->point);
- if (point_skip_ws_forward (win, &col))
- return 1;
-
+ /* Skip white space backwards. */
while (1)
{
- char *buffer = win->node->contents;
- size_t buflen = win->node->nodelen;
-
- for (; col < win->line_map.used; col++)
- {
- mbi_init (iter, buffer + win->line_map.map[col],
- buflen - win->line_map.map[col]);
- mbi_avail (iter);
- if (!(mbi_cur (iter).wc_valid && iswalnum (mbi_cur (iter).wc)))
- {
- if (point_skip_ws_forward (win, &col))
- return 1;
- win->point = win->line_map.map[col];
- return 0;
- }
- }
- if (point_next_line (win))
- return 1;
- col = 0;
+ for (; col >= 0; col--)
+ {
+ win->point = win->line_map.map[col];
+ if (looking_at_alnum (win))
+ goto skipped_whitespace;
+ }
+ if (!point_prev_line (win))
+ return;
+ col = win->line_map.used - 1;
}
- return 1;
-}
+ skipped_whitespace:
-/* Set window point to the beginning of the previous word. Return 1
- if looking at the very first word in the buffer. */
-static int
-point_backward_word (WINDOW *win)
-{
- mbi_iterator_t iter;
- int col;
-
- window_compute_line_map (win);
- col = window_point_to_column (win, win->point, &win->point);
-
while (1)
{
long point;
- char *buffer;
- size_t buflen;
- if (col <= 0)
- {
- if (point_prev_line (win))
- return 1;
- col = win->line_map.used;
- }
- col--;
- if (point_skip_ws_backward (win, &col))
- return 1;
-
- buffer = win->node->contents;
- buflen = win->node->nodelen;
-
for (; col >= 0; col--)
{
- mbi_init (iter, buffer + win->line_map.map[col],
- buflen - win->line_map.map[col]);
- mbi_avail (iter);
- if (!(mbi_cur (iter).wc_valid && iswalnum (mbi_cur (iter).wc)))
- {
- win->point = win->line_map.map[col+1];
- return 0;
- }
+ win->point = win->line_map.map[col];
+ if (win->point == 0)
+ return;
+ if (!looking_at_alnum (win))
+ {
+ point_forward_char (win);
+ return;
+ }
}
- point = win->line_map.map[0] - 1;
- if (point > 0 && _looking_at_newline (win, point))
- {
- win->point = win->line_map.map[0];
- return 0;
- }
+ if (!point_prev_line (win))
+ return;
+ col = win->line_map.used - 1;
+
+ if (looking_at_newline (win, win->point))
+ {
+ point_forward_char (win);
+ return;
+ }
}
- return 1;
}
-/* Move WINDOW's point to the end of the true line. */
+/* Move WINDOW's point to the end of the logical line. */
DECLARE_INFO_COMMAND (info_end_of_line, _("Move to the end of the line"))
{
long point;
@@ -936,12 +822,9 @@
/* Find physical line with end of logical line in it. */
window_compute_line_map (window);
- while (!_looking_at_newline (window,
+ while (!looking_at_newline (window,
window->line_map.map[window->line_map.used - 1]))
- {
- if (point_next_line (window))
- break; /* No next line. */
- }
+ point_next_line (window);
if (window->line_map.used == 0)
return; /* This shouldn't happen. */
@@ -960,7 +843,7 @@
}
}
-/* Move WINDOW's point to the beginning of the true line. */
+/* Move WINDOW's point to the beginning of the logical line. */
DECLARE_INFO_COMMAND (info_beginning_of_line, _("Move to the start of the
line"))
{
int old_point = window->point;
@@ -970,7 +853,7 @@
{
window_compute_line_map (window);
point = window->line_map.map[0];
- if (point == 0 || _looking_at_newline (window, point-1))
+ if (point == 0 || looking_at_newline (window, point-1))
break;
point_prev_line (window);
}
@@ -991,22 +874,8 @@
info_backward_char (window, -count, key);
else
{
- while (count)
- {
- if (point_forward_char (window))
- {
- if (cursor_movement_scrolls_p
- && forward_move_node_structure (window,
- info_scroll_behaviour) == 0)
- window->point = 0;
- else
- {
- window->point = window->node->nodelen - 1;
- break;
- }
- }
- count--;
- }
+ while (count--)
+ point_forward_char (window);
info_show_point (window);
}
}
@@ -1018,27 +887,8 @@
info_forward_char (window, -count, key);
else
{
- while (count)
- {
- if (point_backward_char (window))
- {
- if (cursor_movement_scrolls_p
- && backward_move_node_structure (window,
- info_scroll_behaviour) == 0)
- {
- window->point = window->node->nodelen - 1;
- if (window->line_count > window->height)
- set_window_pagetop (window,
- window->line_count - window->height);
- }
- else
- {
- window->point = 0;
- break;
- }
- }
- count--;
- }
+ while (count--)
+ point_backward_char (window);
info_show_point (window);
}
}
@@ -1052,19 +902,9 @@
return;
}
- while (count)
- {
- if (point_forward_word (window))
- {
- if (cursor_movement_scrolls_p
- && forward_move_node_structure (window,
- info_scroll_behaviour) == 0)
- window->point = 0;
- else
- return;
- }
- --count;
- }
+ while (count--)
+ point_forward_word (window);
+
info_show_point (window);
}
@@ -1076,24 +916,9 @@
return;
}
- while (count)
- {
- if (point_backward_word (window))
- {
- if (cursor_movement_scrolls_p
- && backward_move_node_structure (window,
- info_scroll_behaviour) == 0)
- {
- if (window->line_count > window->height)
- set_window_pagetop (window,
- window->line_count - window->height);
- window->point = window->node->nodelen;
- }
- else
- break;
- }
- --count;
- }
+ while (count--)
+ point_backward_word (window);
+
info_show_point (window);
}
@@ -1136,22 +961,77 @@
"Continuous", "Next Only", "Page Only", NULL
};
-/* Controls whether scroll-behavior affects line movement commands */
-int cursor_movement_scrolls_p = 1;
-int search_skip_screen_p = 0;
+static void _scroll_forward (WINDOW *window, int count, int behaviour);
+static void _scroll_backward (WINDOW *window, int count, int behaviour);
-/* Choices for the scroll-last-node variable */
-char *scroll_last_node_choices[] = {
- "Stop", "Scroll", "Top", NULL
-};
+/* Change the pagetop of WINDOW to DESIRED_TOP, perhaps scrolling the screen
+ to do so. */
+void
+set_window_pagetop (WINDOW *window, int desired_top)
+{
+ int point_line, old_pagetop;
-/* Controls what to do when a scrolling command is issued at the end of the
- last node. */
-int scroll_last_node = SLN_Stop;
+ if (desired_top < 0)
+ desired_top = 0;
+ else if (desired_top > window->line_count)
+ desired_top = window->line_count - 1;
-static void _scroll_forward (WINDOW *window, int count, int behaviour);
-static void _scroll_backward (WINDOW *window, int count, int behaviour);
+ if (window->pagetop == desired_top)
+ return;
+ old_pagetop = window->pagetop;
+ window->pagetop = desired_top;
+
+ /* Make sure that point appears in this window. */
+ point_line = window_line_of_point (window);
+ if ((point_line < window->pagetop) ||
+ ((point_line - window->pagetop) > window->height - 1))
+ window->point =
+ window->line_starts[window->pagetop];
+
+ window->flags |= W_UpdateWindow;
+
+ /* Find out which direction to scroll, and scroll the window in that
+ direction. Do this only if there would be a savings in redisplay
+ time. This is true if the amount to scroll is less than the height
+ of the window, and if the number of lines scrolled would be greater
+ than 10 % of the window's height.
+
+ To prevent status line blinking when keeping up or down key,
+ scrolling is disabled if the amount to scroll is 1. */
+ if (old_pagetop < desired_top)
+ {
+ int start, end, amount;
+
+ amount = desired_top - old_pagetop;
+
+ if (amount == 1 ||
+ (amount >= window->height) ||
+ (((window->height - amount) * 10) < window->height))
+ return;
+
+ start = amount + window->first_row;
+ end = window->height + window->first_row;
+
+ display_scroll_display (start, end, -amount);
+ }
+ else
+ {
+ int start, end, amount;
+
+ amount = old_pagetop - desired_top;
+
+ if (amount == 1 ||
+ (amount >= window->height) ||
+ (((window->height - amount) * 10) < window->height))
+ return;
+
+ start = window->first_row;
+ end = (window->first_row + window->height) - amount;
+ display_scroll_display (start, end, amount);
+ }
+}
+
static void
_scroll_forward (WINDOW *window, int count, int behaviour)
{
@@ -1958,6 +1838,15 @@
info_set_node_of_window (window, node);
}
+/* Choices for the scroll-last-node variable */
+char *scroll_last_node_choices[] = {
+ "Stop", "Scroll", "Top", NULL
+};
+
+/* Controls what to do when a scrolling command is issued at the end of the
+ last node. */
+int scroll_last_node = SLN_Stop;
+
/* Move to 1st menu item, Next, Up/Next, or error in this window. */
static int
forward_move_node_structure (WINDOW *window, int behaviour)
@@ -2642,8 +2531,7 @@
info_error_was_printed = 0;
if (backward_move_node_structure (window, info_scroll_behaviour))
break;
- move_to_new_line (window->line_count, window->line_count - 1,
- window);
+ move_to_new_line (window->line_count - 1, window);
}
}
}
@@ -2664,7 +2552,7 @@
info_error_was_printed = 0;
if (forward_move_node_structure (window, info_scroll_behaviour))
break;
- move_to_new_line (0, 0, window);
+ move_to_new_line (0, window);
}
}
}
@@ -4037,6 +3925,8 @@
info_gc_file_buffers ();
}
+int search_skip_screen_p = 0;
+
DECLARE_INFO_COMMAND (info_search_next,
_("Repeat last search in the same direction"))
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [5612] info cursor movement commands,
Gavin D. Smith <=