2

I am trying to migrate from slime to sly. But I want to use paredit in sly-mrepl. Naive enabling of paredit in sly-mrepl leads to a problem where pressing RET in repl calls paredit-ret. But I want to call sly-mrepl-return.

How do I disable paredit-ret in sly-mrepl, call sly-mrepl-return and still use paredit goodness?

ruby_object
  • 427
  • 2
  • 12
  • What is the "usual key rebinding"? – NickD Dec 05 '22 at 16:02
  • Good question! I meant something like: (add-hook 'scheme-mode-hook (lambda () (swap-paredit))) – ruby_object Dec 05 '22 at 16:48
  • I can't find the definition of `swap-paredit` - is that your own function? If so, can you edit your question and add this information (plus the info from the previous comment)? Questions should, to the extent possible, be complete in themselves, not depending on comments to do that. – NickD Dec 05 '22 at 17:06

1 Answers1

3

Following the suggestions from NickD I have rewritten my emacs config file to include the following advice:

;;; globally in every buffer and mode check if paredit-RET was called in
;;; the repl buffer and call sly-mrepl-return
(advice-add 'paredit-RET
            :after
            (lambda ()
              (when (string-prefix-p "*sly-mrepl for"
                                     (buffer-name (current-buffer)))
                (sly-mrepl-return))))

That ensures calling sly-mrepl-return after emacs calls paredit-RET when I am in a repl buffer and solves the problem described in my question. Perhaps the question should have been entitled: how do I call sly-mrepl-return after calling paredit-RET when I am in a sly-mrepl buffer?

ruby_object
  • 427
  • 2
  • 12
  • 1
    If you modified the `paredit.el` file, there is no need to do that (and it's probably best if you don't): you can define your own modified function and make sure that it overrides the built-in function when loading (probably through a hook, but I haven't checked what is available). Or you can [advise](https://www.gnu.org/software/emacs/manual/html/elisp.html#Advising-Functions) the original `paredit-RET` appropriately. Or you can try changing the keybinding of whatever keymap `sly-mrepl` uses only and leaving other keymaps alone. These are what I would consider before changing paredit itself. – NickD Dec 05 '22 at 16:05
  • Good idea, but it would be better if you provided working links to your suggestions. The advise link gives 404 error. I tried to change the keymapping in the sly mrepl only and I could not find a way to do it that would work. – ruby_object Dec 05 '22 at 16:30
  • 1
    Eh, sorry I screwed up: that advice link should be https://www.gnu.org/software/emacs/manual/html_node/elisp/Advising-Functions.html – NickD Dec 05 '22 at 16:52
  • Dealing with the keymap properly involves understanding the priority of the various keymaps, so that you might change the appropriate one (something that I have not done and that I was too glib about in my original comment). You will need to do some investigation to do it properly. In the meantime, my first suggestion is probably the easiest to implement (but also probably the worst of the three). – NickD Dec 05 '22 at 16:57
  • Assuming that your current answer works to your satisfaction, I like it too :-) The only suggestion is to not spam the messages buffer with all those messages - it's okay for debugging, but after that it will be just noise. – NickD Dec 05 '22 at 17:11
  • You should realize however that the advised function is operative globally in every buffer and every mode, so you don't need to do it in the hook: the effect is the same. – NickD Dec 05 '22 at 17:13