texinfo-commits
[Top][All Lists]
Advanced

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

[5747] save starting position of incremental searches instead of point


From: Gavin D. Smith
Subject: [5747] save starting position of incremental searches instead of point
Date: Tue, 12 Aug 2014 10:26:08 +0000

Revision: 5747
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5747
Author:   gavin
Date:     2014-08-12 10:26:06 +0000 (Tue, 12 Aug 2014)
Log Message:
-----------
save starting position of incremental searches instead of point

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-08-10 16:04:23 UTC (rev 5746)
+++ trunk/ChangeLog     2014-08-12 10:26:06 UTC (rev 5747)
@@ -1,3 +1,22 @@
+2014-08-12  Gavin Smith  <address@hidden>
+
+       * info/session.c (info_set_node_of_window): Clear search matches here
+       instead of in window_set_node_of_window in window.c.
+       (match_in_match_list): When searching backward, include the starting
+       byte in the area.
+
+       * info/window.h (SEARCH_STATE): Moved to session.c.  Store starting
+       position of search instead of position of point.
+       * info/window.c (window_get_state, window_set_state): Moved to
+       session.c.
+       * info/session.c (pop_isearch, push_isearch): Take extra argument to
+       save and restore starting search position.
+       (incremental_search): Save initial point position.  Clear search if
+       search string is erased.
+
+       * info/session.c (info_search_in_node_internal): Check search if
+       forwards when setting search start to 'body_start'.
+
 2014-08-10  Gavin Smith  <address@hidden>
 
        * info/session.c (incremental_search): Backspace always deletes last

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-08-10 16:04:23 UTC (rev 5746)
+++ trunk/info/session.c        2014-08-12 10:26:06 UTC (rev 5747)
@@ -808,11 +808,6 @@
       win->hist[win->hist_index - 1]->point = win->point;
     }
 
-  /* Clear displayed search matches if any.  TODO: do search again in new
-     node? */
-  free (win->matches);
-  win->matches = 0;
-
   /* Put this node into the window. */
   window_set_node_of_window (win, node);
 
@@ -3451,7 +3446,7 @@
   return NULL;
 }
 
-/* Search forwards or backwards for entries in MATCHES that are within
+/* Search forwards or backwards for entries in MATCHES that start within
    the search area delimited by BINDING.  The search is forwards if
    BINDING->start is greater than BINDING->end.  Return index of match in
    *MATCH_INDEX. */
@@ -3467,8 +3462,10 @@
     }
   else
     {
-      start = binding->end;
-      end = binding->start;
+      /* Include the byte with offset 'start' in our range, but not
+         the byte with offset 'end'. */
+      start = binding->end - 1;
+      end = binding->start + 1;
     }
   
   if (binding->start > binding->end)
@@ -3576,7 +3573,7 @@
       
       if (binding.start < 0)
        return -1;
-      else if (binding.start < node->body_start)
+      else if (dir > 0 && binding.start < node->body_start)
        binding.start = node->body_start;
       
       if (!match_regexp)
@@ -4052,6 +4049,7 @@
                    last_search_case_sensitive, 0, DFL_START);
 }
 
+
 /* **************************************************************** */
 /*                                                                  */
 /*                      Incremental Searching                       */
@@ -4073,6 +4071,16 @@
   incremental_search (window, -count, key);
 }
 
+/* Structure defining the current state of an incremental search. */
+typedef struct {
+  NODE *node;           /* The node displayed in this window. */
+  long pagetop;         /* LINE_STARTS[PAGETOP] is first line in WINDOW. */
+  long start;           /* Offset in node contents where search started. */
+  int search_index;     /* Offset of the last char in the search string. */
+  int direction;        /* The direction that this search is heading in. */
+  int failing;          /* Whether or not this search failed. */
+} SEARCH_STATE;
+
 /* Incrementally search for a string as it is typed. */
 /* The last accepted incremental search string. */
 static char *last_isearch_accepted = NULL;
@@ -4088,9 +4096,27 @@
 static size_t isearch_states_index = 0;
 static size_t isearch_states_slots = 0;
 
+/* Get the state of WINDOW, and save it in STATE. */
+static void
+window_get_state (WINDOW *window, SEARCH_STATE *state)
+{
+  state->node = window->node;
+  state->pagetop = window->pagetop;
+}
+
+/* Set the node, pagetop, and point of WINDOW. */
+static void
+window_set_state (WINDOW *window, SEARCH_STATE *state)
+{
+  if (window->node != state->node)
+    window_set_node_of_window (window, state->node);
+  window->pagetop = state->pagetop;
+}
+
 /* Push the state of this search. */
 static void
-push_isearch (WINDOW *window, int search_index, int direction, int failing)
+push_isearch (WINDOW *window, int search_index, int direction, int failing,
+              long start_off)
 {
   SEARCH_STATE *state;
 
@@ -4099,6 +4125,7 @@
   state->search_index = search_index;
   state->direction = direction;
   state->failing = failing;
+  state->start = start_off;
 
   add_pointer_to_array (state, isearch_states_index, isearch_states,
                         isearch_states_slots, 20);
@@ -4106,7 +4133,8 @@
 
 /* Pop the state of this search to WINDOW, SEARCH_INDEX, and DIRECTION. */
 static void
-pop_isearch (WINDOW *window, int *search_index, int *direction, int *failing)
+pop_isearch (WINDOW *window, int *search_index, int *direction, int *failing,
+             long *start_off)
 {
   SEARCH_STATE *state;
 
@@ -4118,6 +4146,7 @@
       *search_index = state->search_index;
       *direction = state->direction;
       *failing = state->failing;
+      *start_off = state->start;
 
       free (state);
       isearch_states[isearch_states_index] = NULL;
@@ -4199,6 +4228,8 @@
   int case_sensitive = 0;
   long start_off = -1;
 
+  long saved_point = window->point;
+
   if (count < 0)
     dir = -1;
   else
@@ -4217,7 +4248,7 @@
   isearch_is_active = 1;
 
   /* Save starting position of search. */
-  push_isearch (window, isearch_string_index, dir, search_result);
+  push_isearch (window, isearch_string_index, dir, search_result, start_off);
 
   while (isearch_is_active)
     {
@@ -4285,16 +4316,23 @@
           else
             {
               pop_isearch (window, &isearch_string_index,
-                           &dir, &search_result);
+                           &dir, &search_result, &start_off);
               isearch_string[isearch_string_index] = '\0';
               if (isearch_string_index == 0)
-                continue; /* Don't search for an empty string. */
+                {
+                  /* Don't search for an empty string.  Clear the search. */
+                  free (window->matches);
+                  window->matches = 0;
+                 window->point = saved_point;
+                  display_update_one_window (window);
+                  continue;
+                }
             }
         }
       else if (quoted || (key >= 32 && key < 256
                      && (isprint (key) || (type == ISFUNC && func == NULL))))
         {
-          push_isearch (window, isearch_string_index, dir, search_result);
+          push_isearch (window, isearch_string_index, dir, search_result, 
start_off);
 
           if (isearch_string_index + 2 >= isearch_string_size)
             isearch_string = xrealloc
@@ -4357,8 +4395,8 @@
              stack back to the last unfailed search. */
           terminal_ring_bell ();
           while (isearch_states_index && (search_result != 0))
-            pop_isearch
-              (window, &isearch_string_index, &dir, &search_result);
+            pop_isearch (window, &isearch_string_index, &dir,
+                         &search_result, &start_off);
           isearch_string[isearch_string_index] = '\0';
           show_isearch_prompt (dir, (unsigned char *) isearch_string,
                                search_result);

Modified: trunk/info/window.c
===================================================================
--- trunk/info/window.c 2014-08-10 16:04:23 UTC (rev 5746)
+++ trunk/info/window.c 2014-08-12 10:26:06 UTC (rev 5747)
@@ -557,6 +557,12 @@
   window->goal_column = 0;
   recalculate_line_starts (window);
   window_compute_line_map (window);
+
+  /* Clear displayed search matches if any.  TODO: do search again in new
+     node? */
+  free (window->matches);
+  window->matches = 0;
+
   window->flags |= W_UpdateWindow;
   if (node)
     {
@@ -1026,25 +1032,6 @@
   window_make_modeline (window);
 }
 
-/* Get the state of WINDOW, and save it in STATE. */
-void
-window_get_state (WINDOW *window, SEARCH_STATE *state)
-{
-  state->node = window->node;
-  state->pagetop = window->pagetop;
-  state->point = window->point;
-}
-
-/* Set the node, pagetop, and point of WINDOW. */
-void
-window_set_state (WINDOW *window, SEARCH_STATE *state)
-{
-  if (window->node != state->node)
-    window_set_node_of_window (window, state->node);
-  window->pagetop = state->pagetop;
-  window->point = state->point;
-}
-
 
 /* A place to buffer echo area messages. */
 static NODE *echo_area_node = NULL;

Modified: trunk/info/window.h
===================================================================
--- trunk/info/window.h 2014-08-10 16:04:23 UTC (rev 5746)
+++ trunk/info/window.h 2014-08-12 10:26:06 UTC (rev 5747)
@@ -100,14 +100,6 @@
   size_t hist_slots;            /* Number of slots allocated to HIST. */
 } WINDOW;
 
-/* Structure defining the current state of an incremental search. */
-typedef struct {
-  WINDOW_STATE_DECL;    /* The node, pagetop and point. */
-  int search_index;     /* Offset of the last char in the search string. */
-  int direction;        /* The direction that this search is heading in. */
-  int failing;          /* Whether or not this search failed. */
-} SEARCH_STATE;
-
 #define W_UpdateWindow  0x01    /* WINDOW needs updating. */
 #define W_WindowIsPerm  0x02    /* This WINDOW is a permanent object. */
 #define W_WindowVisible 0x04    /* This WINDOW is currently visible. */
@@ -228,10 +220,6 @@
 /* Get and return the printed column offset of the cursor in this window. */
 extern int window_get_cursor_column (WINDOW *window);
 
-/* Get and Set the node, pagetop, and point of WINDOW. */
-extern void window_get_state (WINDOW *window, SEARCH_STATE *state);
-extern void window_set_state (WINDOW *window, SEARCH_STATE *state);
-
 extern size_t process_node_text
         (WINDOW *win, char *start,
          int (*fun) (WINDOW *, size_t, size_t, size_t, char *,
@@ -245,8 +233,6 @@
 
 extern void window_line_map_init (WINDOW *win);
 
-extern long window_end_of_line (WINDOW *win);
-
 extern long window_log_to_phys_line (WINDOW *window, long ln);
 
 #endif /* not INFO_WINDOW_H */




reply via email to

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