]> git.wh0rd.org Git - nano.git/commitdiff
- Backported do_prev_word() from 1.1. Command is Meta-Space. Added #ifndef NANO_SMAL...
authorChris Allegretta <chrisa@asty.org>
Sun, 28 Oct 2001 14:52:45 +0000 (14:52 +0000)
committerChris Allegretta <chrisa@asty.org>
Sun, 28 Oct 2001 14:52:45 +0000 (14:52 +0000)
git-svn-id: svn://svn.savannah.gnu.org/nano/branches/nano_1_0_branch/nano@895 35c25a1d-7b9e-4130-9fde-d3aeb78583b8

ChangeLog
nano.c

index 8b0027ad36a205d3cfe8b7dbb2280bfdf9f53e18..c84bd65f0e7eb0829687a53dcf78d80cb10ae0b6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -6,6 +6,9 @@ CVS code -
        - Changed header comments to say "version 2" instead of "version
          1" as the COPYING file is actually version 2 of the GPL (bug
          noticed by Jordi Mallach).
+       - Backported do_prev_word() from 1.1.  Command is Meta-Space.
+         Added #ifndef NANO_SMALL around both functions, as they
+         aren't needed for nano-tiny.
 - cut.c:
   do_cut_text()
        - Backported 1.1 fixes for just doing edit_update when we cut
diff --git a/nano.c b/nano.c
index 31fbdc2669b0ad96055b2ee53ee92998d0304b41..ee0a12c600169fe34698664b9029f470d47335b5 100644 (file)
--- a/nano.c
+++ b/nano.c
@@ -649,6 +649,7 @@ int do_enter_void(void)
     return do_enter(current);
 }
 
+#ifndef NANO_SMALL
 void do_next_word(void)
 {
     filestruct *fileptr, *old;
@@ -699,6 +700,80 @@ void do_next_word(void)
        update_line(current, current_x);
     }
 }
+/* the same thing for backwards */
+void do_prev_word(void)
+{
+    filestruct *fileptr, *old;
+    int i;
+
+    if (current == NULL)
+       return;
+
+    old = current;
+    i = current_x;
+    for (fileptr = current; fileptr != NULL; fileptr = fileptr->prev) {
+       if (fileptr == current) {
+           while (isalnum((int) fileptr->data[i])
+                  && i != 0)
+               i--;
+
+           if (i == 0) {
+               if (fileptr->prev != NULL)
+                   i = strlen(fileptr->prev->data);
+               else if (fileptr == fileage && filebot != NULL) {
+                   current_x = 0;
+                   return;
+               }
+               continue;
+           }
+       }
+
+       while (!isalnum((int) fileptr->data[i]) && i != 0)
+           i--;
+
+       if (i > 0) {
+           i--;
+
+           while (isalnum((int) fileptr->data[i]) && i != 0)
+               i--;
+
+           if (!isalnum((int) fileptr->data[i]))
+               i++;
+
+           if (i != 0 || i != current_x)
+               break;
+
+       }
+       if (fileptr->prev != NULL)
+           i = strlen(fileptr->prev->data);
+       else if (fileptr == fileage && filebot != NULL) {
+           current_x = 0;
+           return;
+       }
+    }
+    if (fileptr == NULL)
+       current = fileage;
+    else
+       current = fileptr;
+
+    current_x = i;
+    placewewant = xplustabs();
+
+    if (current->lineno <= edittop->lineno)
+       edit_update(current, CENTER);
+    else {
+       /* If we've jumped lines, refresh the old line.  We can't just use
+        * current->prev here, because we may have skipped over some blank
+        * lines, in which case the previous line is the wrong one.
+        */
+       if (current != old)
+           update_line(old, 0);
+
+       update_line(current, current_x);
+    }
+
+}
+#endif /* NANO_SMALL */
 
 #ifndef DISABLE_WRAPPING
 void do_wrap(filestruct * inptr, char input_char)
@@ -2464,6 +2539,13 @@ int main(int argc, char *argv[])
                modify_control_seq = 1;
                keyhandled = 1;
                break;
+#ifndef NANO_SMALL
+           case ' ':
+               /* If control-space is next word, Alt-space should be previous word */
+               do_prev_word();
+               keyhandled = 1;
+               break;
+#endif
            case 91:
                switch (kbinput = wgetch(edit)) {
                case '1':       /* Alt-[-1-[0-5,7-9] = F1-F8 in X at least */
@@ -2655,10 +2737,12 @@ int main(int argc, char *argv[])
                break;
 #endif
 #endif
+
            case 0:             /* Erg */
+#ifndef NANO_SMALL
                do_next_word();
                break;
-
+#endif
            case 331:           /* Stuff that we don't want to do squat */
            case -1:
            case 29:            /* Ctrl-] */