ffevotte / isend-mode.el

Interactively send parts of an Emacs buffer to an interpreter
78 stars 17 forks source link

Interesting recommendation: a defadvice to have code be executed automatically? #7

Closed amelio-vazquez-reina closed 8 years ago

amelio-vazquez-reina commented 8 years ago

I found this article which includes some recommended modifications to isend-mode.el.

Specifically it recommends defining advice for isend. Quoting literally:

But there is another annoying problem, isend only sends the code to a specified buffer, but the code won’t be executed automatically.

With the following advice (with an advice you could run some commands before/after a specified function is invoked), after sending code, Emacs will switch to the destination buffer, execute the code that is sent and switch back to the original buffer.

1:  (defadvice isend-send (after advice-run-code-sent activate compile)
2:    "Execute whatever sent to the (Python) buffer"
3:    (interactive)
4:    (let ((old-buf (buffer-name)))
5:      (progn
6:        (switch-to-buffer isend--command-buffer)
7:        (goto-char (point-max))
8:        (comint-send-input)
9:        (switch-to-buffer old-buf))))

What do you think of this suggest this @ffevotte ? Is it really needed?

ffevotte commented 8 years ago

Hi,

thanks for your message, I'm always happy to see someone use `isend'. Could you please include a link to the mentioned article?

Regarding the recommendation you mention, here is how isend handles things:

So there is an issue only if you want to execute code in a buffer that (a) is not a terminal, and (b) for which pressing RETURN does not execute the last line. I personally have not encountered such cases. But if you have (or if the author of the article you mention has), I would be more than happy to fix isend-mode to handle more specific cases once I know about them.

Also, the advice mentioned here is not necessarily very idiomatic. If for some reason you still want to do this outside of isend-mode, please ask and I can propose alternative ways to implement this.

I hope this answers your question. Please ask if something is unclear or you want anything to be implemented in isend-mode.

amelio-vazquez-reina commented 8 years ago

Thanks @ffevotte ! Sorry I forgot to include the link. Here it is (I also updated the OP). I frankly never found the need to change isend-mode in any way. It has always been working for me perfectly. It was running into this problem what prompted me to look up if anyone else had encountered any problems (although IPython 5 came out just this week) what led me to the article I included above.

amelio-vazquez-reina commented 8 years ago

BTW, the author seems to be using M-x shell maybe that's why?

ffevotte commented 8 years ago

Thanks for the update. I don't know what happened, but I missed your other two issues. I'll try to debug this ASAP...