texinfo-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[5761] scroll by whole number of screens for search-skip-screen=On


From: Gavin D. Smith
Subject: [5761] scroll by whole number of screens for search-skip-screen=On
Date: Wed, 20 Aug 2014 13:37:16 +0000

Revision: 5761
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5761
Author:   gavin
Date:     2014-08-20 13:37:15 +0000 (Wed, 20 Aug 2014)
Log Message:
-----------
scroll by whole number of screens for search-skip-screen=On

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/info/session.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-08-20 12:32:07 UTC (rev 5760)
+++ trunk/ChangeLog     2014-08-20 13:37:15 UTC (rev 5761)
@@ -1,5 +1,13 @@
 2014-08-20  Gavin Smith  <address@hidden>
 
+       * info/session.c (info_search_next, info_search_previous): Call
+       info_search_internal directly instead of via info_search_1.
+       <search-skip-screen=On>: Scroll up or down by a whole number of
+       screen-fulls to make match visible.  This makes traversing matches
+       with "}" and "{" less disorienting.
+
+2014-08-20  Gavin Smith  <address@hidden>
+
        * info/session.c (info_search_in_node_internal): Don't call
        window_adjust_pagetop.
        (info_search_1, incremental_search): Call it here instead.

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-08-20 12:32:07 UTC (rev 5760)
+++ trunk/info/session.c        2014-08-20 13:37:15 UTC (rev 5761)
@@ -3596,8 +3596,9 @@
    If the search succeeds and START_OFF is given, *START_OFF is given the
    start of the found string instance.
    
-   If the search fails, return non-zero, else zero.  Side-effect window
-   leaving the node and point where the string was found current. */
+   If the search succeeds, return non-zero, and set node and point of
+   window to where the string was found.  Return non-zero if the search
+   fails. */
 static int
 info_search_internal (char *string, WINDOW *window,
                      int dir, int case_sensitive,
@@ -3880,43 +3881,91 @@
 DECLARE_INFO_COMMAND (info_search_next,
                       _("Repeat last search in the same direction"))
 {
+  long start_off = window->point + 1;
+  NODE *starting_node = window->node;
+  int result;
+
   if (!last_search_direction || !search_string)
-    info_error ("%s", _("No previous search string"));
-  else if (search_skip_screen_p)
     {
+      info_error ("%s", _("No previous search string"));
+      return;
+    }
+
+  if (search_skip_screen_p)
+    {
       /* Find window bottom */
       long n = window->height + window->pagetop;
       if (n < window->line_count)
-       n = window->line_starts[n];
+       start_off = window->line_starts[n];
       else
-       n = window->node->nodelen;
-      info_search_1 (window, last_search_direction * count,
-                    last_search_case_sensitive, n);
+       start_off = window->node->nodelen;
     }
+
+  for (result = 0; result == 0 && count--; )
+    result = info_search_internal (search_string,
+                                   active_window, 1,
+                                   last_search_case_sensitive,
+                                  &start_off);
+
+  if (result == 0 && window->node == starting_node && search_skip_screen_p)
+    {
+      long match_line = window_line_of_point (window);
+      long new_pagetop;
+
+      /* Scroll down a whole number of screenfulls to make match visible. */
+      new_pagetop = window->pagetop;
+      new_pagetop += (match_line - window->pagetop) / window->height
+                      * window->height;
+
+      set_window_pagetop (window, new_pagetop);
+    }
   else
-    info_search_1 (window, last_search_direction * count,
-                   last_search_case_sensitive, DFL_START);
+    window_adjust_pagetop (window);
 }
 
 DECLARE_INFO_COMMAND (info_search_previous,
                       _("Repeat last search in the reverse direction"))
 {
+  long start_off = window->point - 1;
+  NODE *starting_node = window->node;
+  int result;
+
   if (!last_search_direction || !search_string)
-    info_error ("%s", _("No previous search string"));
-  else if (search_skip_screen_p)
     {
-      /* Find window bottom */
-      long n;
+      info_error ("%s", _("No previous search string"));
+      return;
+    }
 
-      n = window->line_starts[window->pagetop] - 1;
-      if (n < 0)
-       n = 0;
-      info_search_1 (window, -last_search_direction * count,
-                    last_search_case_sensitive, n);
+  if (search_skip_screen_p)
+    start_off = window->line_starts[window->pagetop] - 1;
+
+  /* start_off can be negative here, in which case info_search_internal
+     will go to the previous node straight away. */
+
+  for (result = 0; result == 0 && count--; )
+    result = info_search_internal (search_string,
+                                   active_window, -1,
+                                   last_search_case_sensitive,
+                                  &start_off);
+
+  if (result == 0 && window->node == starting_node && search_skip_screen_p)
+    {
+      long match_line = window_line_of_point (window);
+      long new_pagetop;
+
+      /* Scroll up a whole number of screenfulls to make match visible.
+         This means if 'info_search_next' was the last command, we'll
+         go back to the same place. */
+      new_pagetop = window->pagetop - window->height;
+      new_pagetop -= (window->pagetop - match_line) / window->height
+                      * window->height;
+
+      if (new_pagetop < 0)
+        new_pagetop = 0;
+      set_window_pagetop (window, new_pagetop);
     }
   else
-    info_search_1 (window, -last_search_direction * count,
-                   last_search_case_sensitive, DFL_START);
+    window_adjust_pagetop (window);
 }
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]