bug-grub
[Top][All Lists]
Advanced

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

[PATCH][RFC] Add M-f/M-b keybinding to grub shell [0.93]


From: Daniele Bellucci
Subject: [PATCH][RFC] Add M-f/M-b keybinding to grub shell [0.93]
Date: Fri, 3 Oct 2003 00:50:27 +0200
User-agent: Mutt/1.4.1i



Hi All,
this patch add the following emacs keybindings:
M-b: move to previous word
M-f: move to next word


Be aware, 
- i replaced the ESC binding with M-x
- on some keyboards your metakey is ESC (rather than ALT)


patch looks good to and work fine too....

any feedback is much appreciated,
please apply.



--- grub-0.93.orig/ChangeLog    2002-12-04 05:42:41.000000000 +0100
+++ grub-0.93/ChangeLog 2003-10-03 00:11:20.000000000 +0200
@@ -1,3 +1,8 @@
+2003-10-02  Daniele Bellucci    <address@hidden>
+
+       * stage2/char_io.c (real_get_cmdline): Added M-b, M-f
+       Emacs bindings to move between words.
+       
 2002-12-04  Yoshinori K. Okuji  <address@hidden>
 
        * stage2/builtins.c (embed_func): When checking if the disk can
--- grub-0.93.orig/stage2/char_io.c     2002-12-03 00:49:07.000000000 +0100
+++ grub-0.93/stage2/char_io.c  2003-10-03 00:10:20.000000000 +0200
@@ -313,6 +313,8 @@
 #define CMDLINE_WIDTH  78
 #define CMDLINE_MARGIN 10
   
+  /* metakey is equals to 1 iff a metakey has been pressed */
+  static char metakey;
   int xpos, lpos, c, section;
   /* The length of PROMPT.  */
   int plen;
@@ -560,14 +562,130 @@
   grub_strcpy (buf, cmdline);
 
   cl_init ();
-
   while ((c = ASCII_CHAR (getkey ())) != '\n' && c != '\r')
     {
+
       /* If READLINE is non-zero, handle readline-like key bindings.  */
       if (readline)
        {
-         switch (c)
+         if (metakey == 1)
+           {
+             unsigned int count = 0;
+             switch(c)
+               {
+               case 120:           /* M-x immediately return 1  */
+                 return 1;
+
+
+               case 102:           /* M-f forward one word      */
+                 while (lpos + count < llen && buf[lpos + count ] == ' ') 
+                   count ++;
+
+                 if (buf[lpos + count] == 0)
+                   {
+                     /* break everything if end of section has
+                        been reached */
+                     break;
+                   }
+
+                 while (lpos + count < llen && buf[lpos + count ] != ' ') 
+                   count ++;
+
+                 cl_forward(count);
+                 break;
+
+
+               case 98:            /* M-b backward one word */
+
+                 if (lpos == 0)
+                   break;
+
+                 switch (buf[lpos])
+                   {
+                   case ' ':       
+                     /*
+                       buf[lpos] = ' '  
+                       
+                       grub> kernel /boot/vmlinux-2.4.22[ ]hdc=ide-scsi
+                       go back to previous space(if any)
+
+                       grub> kernel[ ]/boot/vmlinux-2.4.22 hdc=ide-scsi
+                     */
+                     while (lpos - count > 0 && 
+                            buf[lpos - count] == ' ')
+                       count ++;   /* eat trailing spaces */
+
+                     if (lpos == count)
+                       {
+                         /* break everything if begin of section has
+                            been reached */
+                         count = 0;
+                         break;
+                       }
+                     
+                     while (lpos - count > 0 && 
+                            buf[lpos - count] != ' ')
+                       count ++;   
+                     break;
+
+                   default:
+                     /* This is a very complicated task.
+                        Basically we have to check previous char at lpos - 1.
+                        Suppose that: buf[lpos - 1] == ' '
+
+                        grub> kernel /boot/vmlinux-2.4.22   [h]dc=ide-scsi
+                        go back until trailing spaces are over
+
+                        grub> kernel /boot/vmlinux-2.4.2[2]  hdc=ide-scsi
+                     */
+                     if (buf[lpos - 1] == ' ')
+                       {
+                         count = 1;
+                         while (lpos - count > 0 &&
+                                buf[lpos - count] == ' ')
+                           count ++;
+                       }
+
+                     if (lpos == count)
+                       {
+                         /* break everything if begin of section has
+                            been reached */
+                         count = 0;
+                         break;
+                       }
+                     
+                     /*
+                        grub> kernel /boot/vmlinux-2.4.2[2]  hdc=ide-scsi
+                        go back to previous space(if any):                     
 
+
+                        grub> kernel[ ]/boot/vmlinux-2.4.22  hdc=ide-scsi
+                     */
+                     while (lpos - count > 0 && 
+                            buf[lpos - count] != ' ')
+                       count ++;   /* find previous space */
+                     break;
+
+                   }
+
+                 /* if everything succeeded move to the next char:
+                    grub> kernel [/]boot/vmlinux-2.4.22  hdc=ide-scsi */
+                 if (count > 0 && lpos - count > 0)
+                   count --; 
+
+                 cl_backward(count);
+               }
+
+             /* revert metakey flag to 0 */
+             metakey = 0;
+             continue;
+           }
+
+
+         switch (c)
            {
+           case 27:            /* metakey */
+             metakey = 1;
+             continue;
            case 9:             /* TAB lists completions */
              {
                int i;
@@ -730,8 +848,6 @@
         backward, but that's ok.  */
       switch (c)
        {
-       case 27:        /* ESC immediately return 1 */
-         return 1;
        case 4:         /* C-d delete character under cursor */
          if (lpos == llen)
            break;



-- 



Daniele.






reply via email to

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