kaz-yos / eval-in-repl

Consistent ESS-like eval interface for various REPLs
174 stars 27 forks source link

Suggestion: Make eir-jump-after-eval buffer local #19

Open diadochos opened 7 years ago

diadochos commented 7 years ago

Suggestion

Why don't we make eir-jump-after-eval a buffer local variable?

Because whether we want to move lines after evaluation depends on our workflow, and the workflows can differ among the languages. It would be great if we can toggle this setting according to the language we are in, or based on some other condition.

kaz-yos commented 7 years ago

Sounds like a good idea. The main problem is that I don't know much about buffer local variables. I'll investigate, but I would appreciate if you could point me to some explanations or examples.

diadochos commented 7 years ago

Thanks for looking into this. What I would look at is the manual which you are likely to be already looking at. The key function is make-local-variable. Basically the flow would be:

  1. Define a variable with defvar
  2. make-local-variable to make it local
  3. Optionally add hooks to setq-local to set values as far as I understand.
kaz-yos commented 7 years ago

Hi, I'm sorry for the super-slow response.

It looks like you could use a language-specific hook to create a local binding. For example,

(add-hook 'python-mode-hook
          '(lambda ()
             (setq-local eir-jump-after-eval nil)))

As I understand, this will make eir-jump-after-eval buffer local and set it to nil when the buffer opens up in the python-mode.

I could (make-variable-buffer-local 'eir-jump-after-eval) within eval-in-repl to make it everywhere buffer-local, but then we need to use setq-default to change the global default, which may be a little confusing.

Please let me know if this hook-based solution is good enough.

Reference: https://www.gnu.org/software/emacs/manual/html_node/elisp/Creating-Buffer_002dLocal.html#Creating-Buffer_002dLocal https://stackoverflow.com/questions/21917049/how-can-i-set-buffer-local-value-for-a-variable-defined-by-defcustom

diadochos commented 6 years ago

I beg your pardon, I just noticed I had not replied to your post. As a workaround, I think the suggested hook-based method should be fine. Thank you very much. As for making eir-jump-after-eval a buffer-local variable, I am still not sure how.

kaz-yos commented 6 years ago

Please feel free to send a pull request If there is a specific way you want it to be implemented.

kaz-yos commented 6 years ago

Also this package may also be interesting to you. https://melpa.org/#/repl-toggle

diadochos commented 6 years ago

In fact, as of today, my daily workflow does not rely on REPL executions, because most of the time I execute rather heavy programs on a remote server. I have no concrete idea for the implementation right now. Next time when I bump into the need for this feature, I may try to make a pull-request. Also, thank you very much for pointing to the library. I will take a look at it.