texinfo-commits
[Top][All Lists]
Advanced

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

[5916] rewrite of read_key_sequence


From: Gavin D. Smith
Subject: [5916] rewrite of read_key_sequence
Date: Fri, 07 Nov 2014 13:12:28 +0000

Revision: 5916
          http://svn.sv.gnu.org/viewvc/?view=rev&root=texinfo&revision=5916
Author:   gavin
Date:     2014-11-07 13:12:25 +0000 (Fri, 07 Nov 2014)
Log Message:
-----------
rewrite of read_key_sequence

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

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog     2014-11-07 12:17:44 UTC (rev 5915)
+++ trunk/ChangeLog     2014-11-07 13:12:25 UTC (rev 5916)
@@ -11,6 +11,8 @@
        * info/infodoc.c (HELP_NODE_GETS_REGENERATED)
        (internal_info_help_node_contents): Removed.
 
+       * info/session.c (read_key_sequence): Rewrite for clarity.
+
 2014-11-07  Gavin Smith  <address@hidden>
 
        * info/session.c (info_dispatch_on_key, read_key_sequence):

Modified: trunk/info/session.c
===================================================================
--- trunk/info/session.c        2014-11-07 12:17:44 UTC (rev 5915)
+++ trunk/info/session.c        2014-11-07 13:12:25 UTC (rev 5916)
@@ -4893,15 +4893,16 @@
   int reading_universal_argument = 0;
 
   int numeric_arg = 1, numeric_arg_sign = 1, *which_explicit_arg;
+  VFunction *func;
 
-  info_initialize_numeric_arg ();
-
   /* Process the right numeric argument. */
   if (!echo_area_is_active)
     which_explicit_arg = &info_explicit_arg;
   else
     which_explicit_arg = &ea_explicit_arg;
 
+  *which_explicit_arg = 0;
+
   initialize_keyseq ();
 
   key = get_input_key ();
@@ -4920,172 +4921,166 @@
       return 0;
     }
 
-  goto begin2;
-begin:
-  if (display_was_interrupted_p && !info_any_buffered_input_p ())
-    display_update_display ();
+  add_char_to_keyseq (key);
 
-  if (active_window != the_echo_area)
-    display_cursor_at_point (active_window);
+  while (1)
+    {
+      int dash_typed = 0, digit_typed = 0;
+      func = 0;
 
-  key = get_another_input_key ();
+      if (display_was_interrupted_p && !info_any_buffered_input_p ())
+        display_update_display ();
 
-begin2:
-  /* If reading a universal argument, both <digit> and M-<digit> help form the 
-     argument. */
-  if (reading_universal_argument)
-    {
-      int k = key;
-      if (k >= KEYMAP_META_BASE)
-        k -= KEYMAP_META_BASE;
-      if (k == '-')
+      if (active_window != the_echo_area)
+        display_cursor_at_point (active_window);
+
+      /* If reading a universal argument, both <digit> and M-<digit> help form 
+         the argument.  Don't look up the pressed key in the key map. */
+      if (reading_universal_argument)
         {
-          goto dash;
+          int k = key;
+          if (k >= KEYMAP_META_BASE)
+            k -= KEYMAP_META_BASE;
+          if (k == '-')
+            {
+              dash_typed = 1;
+            }
+          else if (isdigit (k))
+            {
+              digit_typed = 1;
+            }
+          else
+            /* Note: we may still read another C-u after this. */
+            reading_universal_argument = 0;
         }
-      else if (isdigit (k))
+
+      if (!dash_typed && !digit_typed && map[key].type == ISFUNC)
         {
-          goto digit;
+          func = map[key].function ? map[key].function->func : 0;
+          if (!func)
+            {
+              dispatch_error (info_keyseq);
+              return 0;
+            }
         }
-      else
-        /* Note: we may still read another C-u after this. */
-        reading_universal_argument = 0;
-    }
 
-  switch (map[key].type)
-    {
-    case ISFUNC:
-      {
-        VFunction *func;
+      if (dash_typed || digit_typed || func == &info_add_digit_to_numeric_arg)
+        {
+          int k = key;
+          if (k > KEYMAP_META_BASE)
+            k -= KEYMAP_META_BASE;
+          reading_universal_argument = 1;
+          if (dash_typed || k == '-')
+            {
+              if (!*which_explicit_arg)
+                {
+                  numeric_arg_sign = -1;
+                  numeric_arg = 1;
+                }
 
-        func = map[key].function ? map[key].function->func : 0;
-        if (!func)
-          {
-            add_char_to_keyseq (key);
-            dispatch_error (info_keyseq);
-            return 0;
-          }
-        if (func == info_do_lowercase_version)
-          {
-            int lowerkey;
+            }
+          else if (digit_typed || isdigit (k))
+            {
+              if (*which_explicit_arg)
+                numeric_arg = numeric_arg * 10 + (k - '0');
+              else
+                numeric_arg = (k - '0');
+              *which_explicit_arg = 1;
+            }
+        }
+      else if (func == info_do_lowercase_version)
+        {
+          int lowerkey;
 
-            if (key >= KEYMAP_META_BASE)
-              {
-                lowerkey = key;
-                lowerkey -= KEYMAP_META_BASE;
-                lowerkey = tolower (lowerkey);
-                lowerkey += KEYMAP_META_BASE;
-              }
-            else
-              lowerkey = tolower (key);
+          if (key >= KEYMAP_META_BASE)
+            {
+              lowerkey = key;
+              lowerkey -= KEYMAP_META_BASE;
+              lowerkey = tolower (lowerkey);
+              lowerkey += KEYMAP_META_BASE;
+            }
+          else
+            lowerkey = tolower (key);
 
-            /* TODO: Point of this? */
-            if (lowerkey == key)
-              {
-                add_char_to_keyseq (key);
-                dispatch_error (info_keyseq);
-                return 0;
-              }
-            key = lowerkey;
-            goto begin;
-          }
+          if (lowerkey == key)
+            {
+              dispatch_error (info_keyseq);
+              return 0;
+            }
+          key = lowerkey;
+          continue;
+        }
+      else if (func == &info_universal_argument)
+        {
+          /* This means multiply by 4. */
+          /* info_explicit_arg seems to be doing double duty so that
+             C-u 2 doesn't mean 42. */
+          numeric_arg *= 4;
+          reading_universal_argument = 1;
+        }
+      else if (menu && func == &info_menu_digit)
+        {
+          /* key can either be digit, or M-digit for --vi-keys. */
 
-        add_char_to_keyseq (key);
-
-        if (func == &info_universal_argument)
-          {
-            /* This means multiply by 4. */
-            /* info_explicit_arg seems to be doing double duty so that
-               C-u 2 doesn't mean 42. */
-            numeric_arg *= 4;
-            reading_universal_argument = 1;
-            goto begin;
-          }
-
-        if (func == &info_add_digit_to_numeric_arg)
-          {
-            reading_universal_argument = 1;
-            if (key == '-')
-              {
-dash:
-                add_char_to_keyseq (key);
-                if (!*which_explicit_arg)
-                  {
-                    numeric_arg_sign = -1;
-                    numeric_arg = 1;
-                  }
-
-              }
-            else if (isdigit (key))
-              {
-digit:
-                add_char_to_keyseq (key);
-                if (*which_explicit_arg)
-                  numeric_arg = numeric_arg * 10 + (key - '0');
-                else
-                  numeric_arg = (key - '0');
-                *which_explicit_arg = 1;
-              }
-            goto begin;
-          }
-
-        /* Don't update the key sequence if reading a key sequence in the echo 
-           area.  This means that a key sequence like "C-u 2 Left"
-           appears to take effect immediately, instead of there being a 
-           delay while the message is displayed. */
-        if (!echo_area_is_active && info_keyseq_displayed_p)
-          display_info_keyseq (0);
-
-        if (menu && func == &info_menu_digit)
-          {
-            /* key can either be digit, or M-digit for --vi-keys. */
-            menu_digit (active_window, 1, key);
-            return 0;
-          }
-
-        if (insert
-            && (func == &ea_possible_completions || func == &ea_complete)
-            && !echo_area_completion_items)
-          {
-            ea_insert (the_echo_area, 1, key);
-          }
-        if (count)
-          *count = numeric_arg * numeric_arg_sign;
-        return func;
-      }
-      break;
-
-    case ISKMAP:
-      add_char_to_keyseq (key);
-      if (map[key].function != NULL)
+          int k = key;
+          if (k > KEYMAP_META_BASE)
+            k -= KEYMAP_META_BASE;
+          menu_digit (active_window, 1, k);
+          return 0;
+        }
+      else if (insert
+               && (func == &ea_possible_completions || func == &ea_complete)
+               && !echo_area_completion_items)
         {
-          map = (Keymap)map[key].function;
-          do
-            key = get_another_input_key ();
-          while (key == KEY_MOUSE);
+          ea_insert (the_echo_area, 1, key);
+        }
+      else if (func)
+        {
+          /* Don't update the key sequence if we have finished reading a key 
+             sequence in the echo area.  This means that a key sequence like 
+             "C-u 2 Left" appears to take effect immediately, instead of there 
+             being a delay while the message is displayed. */
+          if (!echo_area_is_active && info_keyseq_displayed_p)
+            display_info_keyseq (0);
 
-          goto begin;
+          if (count)
+            *count = numeric_arg * numeric_arg_sign;
+          return func;
         }
-      else
+      else if (map[key].type == ISKMAP)
         {
-          dispatch_error (info_keyseq);
-          return 0;
+          if (map[key].function != NULL)
+            map = (Keymap)map[key].function;
+          else
+            {
+              dispatch_error (info_keyseq);
+              return 0;
+            }
+
+          if (info_keyseq_displayed_p)
+            display_info_keyseq (1);
         }
-      break;
+
+      do
+        key = get_another_input_key ();
+      while (key == KEY_MOUSE);
+      add_char_to_keyseq (key);
     }
+
   return 0;
 }
 
 /* Add the current digit to the argument in progress. */
 DECLARE_INFO_COMMAND (info_add_digit_to_numeric_arg,
                       _("Add this digit to the current numeric argument"))
-{}
+{} /* Declaration only. */
 
 /* C-u, universal argument.  Multiply the current argument by 4.
    Read a key.  If the key has nothing to do with arguments, then
    dispatch on it.  If the key is the abort character then abort. */
 DECLARE_INFO_COMMAND (info_universal_argument,
                       _("Start (or multiply by 4) the current numeric 
argument"))
-{}
+{} /* Declaration only. */
 
 /* Create a default argument. */
 void




reply via email to

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