bug-texinfo
[Top][All Lists]
Advanced

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

Re: [PATCH] infokeys, scrolling behavior etc.


From: Sergey Poznyakoff
Subject: Re: [PATCH] infokeys, scrolling behavior etc.
Date: Mon, 16 Jul 2007 19:15:03 +0300

Benno Schulenberg <address@hidden> ha escrit:

> `info/infokey` followed by `info/ginfo info` still puts the
> cursor halfway the screen when scrolling up into the preceding
> node.  This is on a Konsole, but also in an xterm and on a VT.

Now that I see what you meant, I don't know if it can be considered a
bug :) Anyway, here is an improved patch, that makes info behave the
proposed way (i.e. placing the cursor at the end of node and locating
the end of node at the bottom of the window) and fixing the error
message discrepancy you have reported.   

Regards,
Sergey

Index: info/info-utils.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/info-utils.c,v
retrieving revision 1.7
diff -p -u -r1.7 info-utils.c
--- info/info-utils.c   1 Jul 2007 21:20:30 -0000       1.7
+++ info/info-utils.c   16 Jul 2007 16:06:18 -0000
@@ -289,7 +289,8 @@ info_references_internal (char *label, S
       strncpy (entry->label, refdef, offset - 1);
       entry->label[offset - 1] = '\0';
       canonicalize_whitespace (entry->label);
-
+      entry->line_number = 0;
+      
       refdef += offset;
       entry->start = start;
       entry->end = refdef - binding->buffer;
Index: info/infodoc.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/infodoc.c,v
retrieving revision 1.12
diff -p -u -r1.12 infodoc.c
--- info/infodoc.c      1 Jul 2007 21:20:30 -0000       1.12
+++ info/infodoc.c      16 Jul 2007 16:06:18 -0000
@@ -58,12 +58,15 @@ static char *info_internal_help_text[] =
               Picking a menu item causes another node to be selected.\n"),
   N_("\\%-10[xref-item]  Follow a cross reference.  Reads name of 
reference.\n"),
   N_("\\%-10[history-node]  Move to the last node seen in this window.\n"),
-  N_("\\%-10[move-to-next-xref]  Skip to next hypertext link within this 
node.\n"),
-  N_("\\%-10[move-to-prev-xref]  Skip to previous hypertext link within this 
node.\n"),
+  N_("\\%-10[move-to-next-xref]  Skip to next hypertext link [*].\n"),
+  N_("\\%-10[move-to-prev-xref]  Skip to previous hypertext link [*].\n"),
   N_("\\%-10[select-reference-this-line]  Follow the hypertext link under 
cursor.\n"),
   N_("\\%-10[dir-node]  Move to the `directory' node.  Equivalent to 
`\\[goto-node] (DIR)'.\n"),
   N_("\\%-10[top-node]  Move to the Top node.  Equivalent to `\\[goto-node] 
Top'.\n"),
   "\n",
+  N_("[*]    Command acts within this node or the entire document, depending 
on\n"
+     "the value of cursor-movement-scrolls variable\n"),
+  "\n",
   N_("Moving within a node:\n\
 ---------------------\n"),
   N_("\\%-10[beginning-of-node]  Go to the beginning of this node.\n"),
Index: info/session.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/session.c,v
retrieving revision 1.19
diff -p -u -r1.19 session.c
--- info/session.c      1 Jul 2007 21:20:31 -0000       1.19
+++ info/session.c      16 Jul 2007 16:06:18 -0000
@@ -604,8 +604,8 @@ move_to_new_line (int old, int new, WIND
       int goal;
 
       if (new >= window->line_count || new < 0)
-        return;
-
+       return;
+      
       goal = window_get_goal_column (window);
       window->goal_column = goal;
 
@@ -615,6 +615,9 @@ move_to_new_line (int old, int new, WIND
     }
 }
 
+static int forward_move_node_structure (WINDOW *window, int behaviour);
+static int backward_move_node_structure (WINDOW *window, int behaviour);
+
 /* Move WINDOW's point down to the next line if possible. */
 DECLARE_INFO_COMMAND (info_next_line, _("Move down to the next line"))
 {
@@ -623,11 +626,27 @@ DECLARE_INFO_COMMAND (info_next_line, _(
   if (count < 0)
     info_prev_line (window, -count, key);
   else
-    {
-      old_line = window_line_of_point (window);
-      new_line = old_line + count;
-      move_to_new_line (old_line, new_line, window);
-    }
+    while (count)
+      {
+       int diff;
+
+       old_line = window_line_of_point (window);
+       diff = window->line_count - old_line;
+       if (diff > count)
+         diff = count;
+
+       count -= diff;
+       new_line = old_line + diff;
+       if (new_line >= window->line_count
+           && cursor_movement_scrolls_p)
+         {
+           if (forward_move_node_structure (window, info_scroll_behaviour))
+             break;
+           move_to_new_line (0, 0, window);
+         }
+       else
+         move_to_new_line (old_line, new_line, window);
+      }
 }
 
 /* Move WINDOW's point up to the previous line if possible. */
@@ -638,11 +657,31 @@ DECLARE_INFO_COMMAND (info_prev_line, _(
   if (count < 0)
     info_next_line (window, -count, key);
   else
-    {
-      old_line = window_line_of_point (window);
-      new_line = old_line - count;
-      move_to_new_line (old_line, new_line, window);
-    }
+    while (count)
+      {
+       int diff;
+       
+       old_line = window_line_of_point (window);
+       diff = old_line + 1;
+       if (diff > count)
+         diff = count;
+       
+       count -= diff;
+       new_line = old_line - diff;
+       
+       if (new_line < 0
+           && cursor_movement_scrolls_p)
+         {
+           if (backward_move_node_structure (window, info_scroll_behaviour))
+             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);
+         }
+       else
+         move_to_new_line (old_line, new_line, window);
+      }
 }
 
 /* Move WINDOW's point to the end of the true line. */
@@ -691,11 +730,27 @@ DECLARE_INFO_COMMAND (info_forward_char,
     info_backward_char (window, -count, key);
   else
     {
-      window->point += count;
-
-      if (window->point >= window->node->nodelen)
-        window->point = window->node->nodelen - 1;
-
+      while (count)
+       {
+         int diff = window->node->nodelen - window->point;
+         
+         if (diff > count)
+           diff = count;
+         window->point += diff;
+         count -= diff;
+         if (window->point >= window->node->nodelen)
+           {
+             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;
+               }
+           }
+       }
       info_show_point (window);
     }
 }
@@ -707,11 +762,34 @@ DECLARE_INFO_COMMAND (info_backward_char
     info_forward_char (window, -count, key);
   else
     {
-      window->point -= count;
+      while (count)
+       {
+         int diff = count;
 
-      if (window->point < 0)
-        window->point = 0;
+         if (window->point < diff)
+           diff = window->point + 1;
+         
+         window->point -= diff;
+         count -= diff;
 
+         if (window->point < 0)
+           {
+             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;
+               }
+           }
+       }
       info_show_point (window);
     }
 }
@@ -738,8 +816,19 @@ DECLARE_INFO_COMMAND (info_forward_word,
   while (count)
     {
       if (point + 1 >= end)
-        return;
-
+       {
+         if (cursor_movement_scrolls_p
+             && forward_move_node_structure (window,
+                                             info_scroll_behaviour) == 0)
+           {
+             point = 0;
+             buffer = window->node->contents;
+             end = window->node->nodelen;
+           }
+         else
+           return;
+       }
+      
       /* If we are not in a word, move forward until we are in one.
          Then, move forward until we hit a non-alphabetic character. */
       c = buffer[point];
@@ -754,7 +843,20 @@ DECLARE_INFO_COMMAND (info_forward_word,
             }
         }
 
-      if (point >= end) return;
+      if (point >= end)
+       {
+         if (cursor_movement_scrolls_p
+             && forward_move_node_structure (window,
+                                             info_scroll_behaviour) == 0)
+           {
+             point = 0;
+             buffer = window->node->contents;
+             end = window->node->nodelen;
+           }
+         else
+           return;
+       }
+
 
       while (++point < end)
         {
@@ -786,8 +888,21 @@ DECLARE_INFO_COMMAND (info_backward_word
   while (count)
     {
       if (point == 0)
-        break;
-
+       {
+         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);
+             buffer = window->node->contents;
+             point = window->node->nodelen;
+           }
+         else
+           break;
+       }
+      
       /* Like info_forward_word (), except that we look at the
          characters just before point. */
 
@@ -835,6 +950,9 @@ char *info_scroll_choices[] = {
   "Continuous", "Next Only", "Page Only", (char *)NULL
 };
 
+/* Controls whether scroll-behavior affects line movement commands */
+int cursor_movement_scrolls_p = 0;
+
 /* Default window sizes for scrolling commands.  */
 int default_window_size = -1;  /* meaning 1 window-full */
 int default_scroll_size = -1;  /* meaning half screen size */
@@ -844,19 +962,22 @@ int default_scroll_size = -1;     /* meaning
                             && !is_dir_name (info_parsed_filename)))
 
 /* Move to 1st menu item, Next, Up/Next, or error in this window. */
-static void
+static int
 forward_move_node_structure (WINDOW *window, int behaviour)
 {
   switch (behaviour)
     {
     case IS_PageOnly:
       info_error ((char *) msg_at_node_bottom, NULL, NULL);
-      break;
+      return 1;
 
     case IS_NextOnly:
       info_next_label_of_node (window->node);
       if (!info_parsed_nodename && !info_parsed_filename)
-        info_error ((char *) msg_no_pointer, (char *) _("Next"), NULL);
+       {
+         info_error ((char *) msg_no_pointer, (char *) _("Next"), NULL);
+         return 1;
+       }
       else
         {
           window_message_in_echo_area ((char *) _("Following Next node..."),
@@ -880,7 +1001,7 @@ forward_move_node_structure (WINDOW *win
               window_message_in_echo_area ((char *) _("Selecting first menu 
item..."),
                   NULL, NULL);
               info_menu_digit (window, 1, '1');
-              return;
+              return 0;
             }
         }
 
@@ -892,7 +1013,7 @@ forward_move_node_structure (WINDOW *win
             window_message_in_echo_area ((char *) _("Selecting Next node..."),
                 NULL, NULL);
             info_handle_pointer ("Next", window);
-            return;
+            return 0;
           }
 
         /* Okay, there wasn't a "Next:" for this node.  Move "Up:" until we
@@ -964,7 +1085,7 @@ forward_move_node_structure (WINDOW *win
                      (void *) (long) up_counter, NULL);
 
                   info_handle_pointer ("Next", window);
-                  return;
+                  return 0;
                 }
               else
                 {
@@ -986,28 +1107,33 @@ forward_move_node_structure (WINDOW *win
                   window->flags |= W_UpdateWindow;
                   info_error ((char *) _("No more nodes within this 
document."),
                       NULL, NULL);
+                 return 1;
                 }
             }
         }
         break;
       }
     }
+  return info_error_was_printed; /*FIXME*/
 }
 
 /* Move Prev, Up or error in WINDOW depending on BEHAVIOUR. */
-static void
+static int
 backward_move_node_structure (WINDOW *window, int behaviour)
 {
   switch (behaviour)
     {
     case IS_PageOnly:
       info_error ((char *) msg_at_node_top, NULL, NULL);
-      break;
+      return 1;
 
     case IS_NextOnly:
       info_prev_label_of_node (window->node);
       if (!info_parsed_nodename && !info_parsed_filename)
-        info_error ((char *) _("No `Prev' for this node."), NULL, NULL);
+       {
+         info_error ((char *) _("No `Prev' for this node."), NULL, NULL);
+         return 1;
+       }
       else
         {
           window_message_in_echo_area ((char *) _("Moving Prev in this 
window."),
@@ -1025,9 +1151,12 @@ backward_move_node_structure (WINDOW *wi
           info_up_label_of_node (window->node);
           if (!info_parsed_nodename && (!info_parsed_filename
                                         || is_dir_name (info_parsed_filename)))
-            info_error ((char *)
-                _("No `Prev' or `Up' for this node within this document."),
-                NULL, NULL);
+           {
+             info_error ((char *)
+                   _("No `Prev' or `Up' for this node within this document."),
+                         NULL, NULL);
+             return 1;
+           }
           else
             {
               window_message_in_echo_area ((char *) _("Moving Up in this 
window."),
@@ -1087,6 +1216,7 @@ backward_move_node_structure (WINDOW *wi
         }
       break;
     }
+  return 0;
 }
 
 /* Move continuously forward through the node structure of this info file. */
@@ -1148,10 +1278,10 @@ _scroll_forward(WINDOW *window, int coun
           /* If there are no more lines to scroll here, error, or get
              another node, depending on BEHAVIOUR. */
           if (desired_top > window->line_count)
-            {
-              forward_move_node_structure (window, behaviour);
-              return;
-            }
+           {
+             forward_move_node_structure (window, behaviour);
+             return;
+           }
         }
       else
         desired_top = window->pagetop + count;
@@ -1185,10 +1315,10 @@ _scroll_backward(WINDOW *window, int cou
           desired_top = window->pagetop - (window->height - 2);
 
           if ((desired_top < 0) && (window->pagetop == 0))
-            {
-              backward_move_node_structure (window, behaviour);
-              return;
-            }
+           {
+             backward_move_node_structure (window, behaviour);
+             return;
+           }
         }
       else
         desired_top = window->pagetop - count;
@@ -4226,7 +4356,7 @@ info_gc_file_buffers (void)
 /* **************************************************************** */
 
 /* Move to the next or previous cross reference in this node. */
-static void
+static int
 info_move_to_xref (WINDOW *window, int count, unsigned char key, int dir)
 {
   long firstmenu, firstxref;
@@ -4270,7 +4400,7 @@ info_move_to_xref (WINDOW *window, int c
   if (firstmenu == -1 && firstxref == -1)
     {
       info_error ((char *) msg_no_xref_node, NULL, NULL);
-      return;
+      return cursor_movement_scrolls_p;
     }
 
   /* There is at least one cross reference or menu entry in this node.
@@ -4317,22 +4447,28 @@ info_move_to_xref (WINDOW *window, int c
      point, choose the first menu or xref entry appearing in this node. */
   if (placement == -1)
     {
-      if (firstmenu != -1 && firstxref != -1)
-        {
-          if (((dir == 1) && (firstmenu < firstxref)) ||
-              ((dir == -1) && (firstmenu > firstxref)))
-            placement = firstmenu + 1;
-          else
-            placement = firstxref;
-        }
-      else if (firstmenu != -1)
-        placement = firstmenu + 1;
+      if (cursor_movement_scrolls_p)
+       return 1;
       else
-        placement = firstxref;
+       {
+         if (firstmenu != -1 && firstxref != -1)
+           {
+             if (((dir == 1) && (firstmenu < firstxref)) ||
+                 ((dir == -1) && (firstmenu > firstxref)))
+               placement = firstmenu + 1;
+             else
+               placement = firstxref;
+           }
+         else if (firstmenu != -1)
+           placement = firstmenu + 1;
+         else
+           placement = firstxref;
+       }
     }
   window->point = placement;
   window_adjust_pagetop (window);
   window->flags |= W_UpdateWindow;
+  return 0;
 }
 
 DECLARE_INFO_COMMAND (info_move_to_prev_xref,
@@ -4341,7 +4477,16 @@ DECLARE_INFO_COMMAND (info_move_to_prev_
   if (count < 0)
     info_move_to_prev_xref (window, -count, key);
   else
-    info_move_to_xref (window, count, key, -1);
+    {
+      while (info_move_to_xref (window, count, key, -1))
+       {
+         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);
+       }
+    }
 }
 
 DECLARE_INFO_COMMAND (info_move_to_next_xref,
@@ -4350,7 +4495,19 @@ DECLARE_INFO_COMMAND (info_move_to_next_
   if (count < 0)
     info_move_to_next_xref (window, -count, key);
   else
-    info_move_to_xref (window, count, key, 1);
+    {
+      /* Note: This can cause some blinking when the next cross reference is
+        located several nodes further. This effect can be easily suppressed
+        by setting display_inhibited to 1, however this will also make
+        error messages to be dumped on stderr, instead on the echo area. */ 
+      while (info_move_to_xref (window, count, key, 1))
+       {
+         info_error_was_printed = 0;
+         if (forward_move_node_structure (window, info_scroll_behaviour))
+           break;
+         move_to_new_line (0, 0, window);
+       }
+    }
 }
 
 /* Select the menu item or reference that appears on this line. */
Index: info/session.h
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/session.h,v
retrieving revision 1.6
diff -p -u -r1.6 session.h
--- info/session.h      1 Jul 2007 21:20:31 -0000       1.6
+++ info/session.h      16 Jul 2007 16:06:18 -0000
@@ -59,6 +59,8 @@ extern char *info_scroll_choices[];
 #define IS_NextOnly   1 /* Try to get "Next:" menu item. */
 #define IS_PageOnly   2 /* Simply give up at the bottom of a node. */
 
+extern int cursor_movement_scrolls_p;
+
 /* Utility functions found in session.c */
 extern void info_dispatch_on_key (unsigned char key, Keymap map);
 extern unsigned char info_get_input_char (void);
Index: info/variables.c
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/variables.c,v
retrieving revision 1.6
diff -p -u -r1.6 variables.c
--- info/variables.c    1 Jul 2007 21:20:31 -0000       1.6
+++ info/variables.c    16 Jul 2007 16:06:18 -0000
@@ -60,10 +60,19 @@ VARIABLE_ALIST info_variables[] = {
       N_("Controls what happens when scrolling is requested at the end of a 
node"),
       &info_scroll_behaviour, (char **)info_scroll_choices },
 
+  /* Alternate spelling */
+  { "scroll-behavior",
+      N_("Same as scroll-behaviour"),
+      &info_scroll_behaviour, (char **)info_scroll_choices },
+
   { "scroll-step",
       N_("The number lines to scroll when the cursor moves out of the window"),
       &window_scroll_step, (char **)NULL },
 
+  { "cursor-movement-scrolls",
+    N_("Controls whether scroll-behavior affects cursor movement commands"),
+    &cursor_movement_scrolls_p, (char **)on_off_choices },
+  
   { "ISO-Latin",
       N_("When \"On\", Info accepts and displays ISO Latin characters"),
       &ISO_Latin_p, (char **)on_off_choices },
Index: info/variables.h
===================================================================
RCS file: /cvsroot/texinfo/texinfo/info/variables.h,v
retrieving revision 1.6
diff -p -u -r1.6 variables.h
--- info/variables.h    1 Jul 2007 21:20:31 -0000       1.6
+++ info/variables.h    16 Jul 2007 16:06:18 -0000
@@ -60,6 +60,7 @@ extern int gc_compressed_files;
 extern int show_index_match;
 extern int info_scroll_behaviour;
 extern int window_scroll_step;
+extern int cursor_movement_scrolls_p;
 extern int ISO_Latin_p;
 
 #endif /* not INFO_VARIABLES_H */




reply via email to

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