Calling up the last line typed with a single keystroke


#1

@Ginkgo suggested:

I’d like to suggest a feature: the possibility to call up at least just the last line typed into the local REPL with a single keystroke.

Here’s an initial attempt to implement this:

  1. Change the line:

    volatile int WritePtr = 0, ReadPtr = 0;
    

    to:

    volatile int WritePtr = 0, ReadPtr = 0, LastWritePtr = 0;
    
  2. Change:

  // Edit buffer
  if (c == '\n' || c == '\r') {
    pserial('\n');
    KybdAvailable = 1;
    ReadPtr = 0;
    return;
  }
  if (c == 8 || c == 0x7f) {     // Backspace key
    if (WritePtr > 0) {
      WritePtr--;
      Serial.write(8); Serial.write(' '); Serial.write(8);
      if (WritePtr) c = KybdBuf[WritePtr-1];
    }
  } else if (WritePtr < KybdBufSize) {
    KybdBuf[WritePtr++] = c;
    Serial.write(c);
  }

to:

  // Edit buffer
  if (c == '\n' || c == '\r') {
    pserial('\n');
    KybdAvailable = 1;
    ReadPtr = 0; LastWritePtr = WritePtr;
    return;
  }
  if (c == 8 || c == 0x7f) {     // Backspace key
    if (WritePtr > 0) {
      WritePtr--;
      Serial.write(8); Serial.write(' '); Serial.write(8);
      if (WritePtr) c = KybdBuf[WritePtr-1];
    }
  } else if (c == 9) { // tab or ctrl-I
    for (int i = 0; i < LastWritePtr; i++) Serial.write(KybdBuf[i]);
    WritePtr = LastWritePtr;
  } else if (WritePtr < KybdBufSize) {
    KybdBuf[WritePtr++] = c;
    Serial.write(c);
  }

Note: It assumes you have this enabled:

#define lineeditor

Now, pressing the Tab key will echo the previous line typed after the uLisp prompt, and allow you to edit it.

If you think this would be a useful feature I’ll incorporate it into the standard releases.


What would you like to see in uLisp in 2024?
#3

Awesome, thank you! Will integrate it within the next days into the KBFW version.


#4

This would certainly be appreciated!!


#5

Now implemented in KBFW version! Works great. Outer left special key calls up line entered before (keyboard backlight on/off removed in favor of this function, but still kept in comments if you want to change the keyboard translation map yourself).


Using uLisp with the Keyboard FeatherWing
#6

Hi David ,

Thanks ! This is really usefull.
Regards,
Ronny


#7

Great - thanks!


#8

Seconding — this would be awesome! It brings us closer to “misusing microcontrollers as full-blown Lisp machines”…


#9

I’ve now incorporated this feature in the ARM release 4.5a:

Download uLisp - ARM version


#10

Hi David

It’s look very useful with Lisp Badge LE (hard to press keys without serial connected), Hope to see it soon available on it, I’d like to try to integrate the patch by my self later.

Regards
Walter


#11

@Walter This is incorporated in Lisp Badge LE Release 2:

Lisp Badge LE on GitHub

To invoke it press SHIFT ENTER.


#12

Hi David

I’ve tested the last version, shift + enter works as expected, it helps a lot while typing with the key pad.

Thanks.


#13

Great! Thanks for letting me know.