1

I am new to the Common Lisp universe. In order to code in Common Lisp, I have started using Emacs and Slime (among other stuff, such as ParEdit).

Emacs is another universe on its own. I realized that there are some counter-intuitive things in the emacs universe which, after a while, they start to make sense (such as using C-n instead of scroll down with the mouse or using the down arrow key).

Sometimes, I need to see an explanation to clarify things and solve the classic "you do not know that you do not know" problems.

One thing that intrigues me on Slime is the commands M-n and C-down. Both do roughly the same thing. Using the describe-key command I can see the definitions:

M-n runs the command slime-repl-next-input (found in slime-repl-mode-map), which is an interactive Lisp function in ‘slime-repl.el’.

It is bound to M-n, .

(slime-repl-next-input)

Cycle forwards through input history. See ‘slime-repl-previous-input’.

With a prefix-arg, do replacement from the mark.

And:

C-down runs the command slime-repl-forward-input (found in slime-repl-mode-map), which is an interactive Lisp function in ‘slime-repl.el’.

It is bound to .

(slime-repl-forward-input)

Cycle forwards through input history.

What is the rationale of having both? Just giving the users an option to use arrow keys and another option that avoids arrow keys?

Am I missing something about its architecture/design?

1
  • 4
    The keys in question are traditional "cycle history in a REPL" keys in Emacs, so it's not particularly strange that they're both bound, but it is intriguing that they're not bound to the same command. I don't know why they both exist, but it sounds like they behave differently with a prefix argument which may be sufficient reason. Note that you can bind a command to more than one key sequence -- there's no reason to define two commands if the only goal is to provide two key bindings.
    – phils
    Jul 17, 2021 at 23:15

1 Answer 1

1

You were close to figure it out, but you needed to dig a little bit deeper.

These commands are completely different beasts. I'll explain with an example, using slime-repl-previous-input (bound to M-p) and slime-repl-backward-input (bound to C-up), without loss of generality.

Start the REPL and evaluate the following s-exps: (* 2 2) and (+ 2 2).

At the next prompt, calling either of the functions does the same.

What if you type (+ M-p? (Think for a while). Bingo, you're asking to get all of the previous commands that start with "(+"! Whereas typing (+ C-up would simply scroll up through all the history.

In practice, I don't ever use C-up/down. Why are those commands there? Because on a typical bash shell, you cycle through commands with the up/down arrow keys. Notice that in Slime you need to prefix it with Control, otherwise you'd be moving the cursor up/down lines. Yes, Emacs is 2-dimensional, whereas the command line is 1-dimensional.

Tip: If you're a beginner, don't use a nuclear power station to power a laptop. Before using ParEdit, take a look at (info "(emacs) Parentheses"). Copy this s-exp into Emacs and evaluate it with C-x C-e.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.