test
kaz-yos / eval-in-repl Goto Github PK
View Code? Open in Web Editor NEWConsistent ESS-like eval interface for various REPLs
Consistent ESS-like eval interface for various REPLs
test
Given the function:
def foo():
x = 1
y = x + 1
eir-eval-in-python
makes python/ipython thinks that the function ends after x = 1
, and tries to evaluate y = x + 1
, producing NameError
.
Looks like eir-send-to-python
is getting the whole string, but it's being misunderstood by the inferior python process. It is possible to send whole functions to *Python*
buffers, python-shell-send-defun
does the right thing, so I'm not sure what needs changing.
Currently, mark is always active after an expression is evaluated. We should restore the mark to its original state. That is, when mark-active
is nil
at the beginning, always restore it back afterward.
there is a package called js-comint
can do inferior-js-mode
and run-js
.
Hope you can support JavaScript.
When I execute M-x eir-eval-in-ruby
in a ruby buffer with an inf-ruby
mode, it gives the following error.
eir-send-to-repl: Wrong number of arguments: (lambda (command &optional name) "Run an inferior Ruby process, input and output in a new buffer.
The consecutive buffer names will be:
`*NAME*', `*NAME*<2>', `*NAME*<3>' and so on.
NAME defaults to \"ruby\".
Runs the hooks `comint-mode-hook' and `inf-ruby-mode-hook'.
(Type \\[describe-mode] in the process buffer for the list of commands.)" (setq name (or name "ruby")) (let ((commandlist (split-string-and-unquote command)) (buffer (current-buffer)) (process-environment process-environment)) (setenv "PAGER" (executable-find "cat")) (set-buffer (apply (quote make-comint-in-buffer) name (generate-new-buffer-name (format "*%s*" name)) (car commandlist) nil (cdr commandlist))) (inf-ruby-mode) (ruby-remember-ruby-buffer buffer) (setq inf-ruby-buffers (cons (current-buffer) inf-ruby-buffers)) (setq inf-ruby-buffer-impl-name name inf-ruby-buffer-command command)) (pop-to-buffer (setq inf-ruby-buffer (current-buffer)))), 0
However, M-x ruby-send-region
works correctly.
Has there been an incompatible update recently?
Sorry to bother, but it would be awesome if you could look into this (I will try to fix this after the new years when I get the time).
Is there a way of using this to send the whole buffer to the REPL?
AS the switch by mode is done by setting the same key to different functions in each keymap it is not as easy to generalise as select the buffer and call an eir function.
Hi I am new to emacs. Here is what I have done. Thank you for any help in advance.
install eval-in-repl from melpa-stable
install essh.el by placing in load path
install eval-in-repl-shell.el in load path
relevant .emacs cutout:
;;--------------------------------------------------------------;;
(require 'essh)
(defun essh-sh-hook ()
(define-key sh-mode-map "\C-c\C-r" 'pipe-region-to-shell)
(define-key sh-mode-map "\C-c\C-b" 'pipe-buffer-to-shell)
(define-key sh-mode-map "\C-c\C-j" 'pipe-line-to-shell)
(define-key sh-mode-map "\C-c\C-n" 'pipe-line-to-shell-and-step)
(define-key sh-mode-map "\C-c\C-f" 'pipe-function-to-shell)
(define-key sh-mode-map "\C-c\C-d" 'shell-cd-current-directory))
(add-hook 'sh-mode-hook 'essh-sh-hook)
;;--------------------------------------------------------------;;
;;--------------------------------------------------------------;;
;; require the main file containing common functions
(require 'eval-in-repl)
;; Uncomment if no need to jump after evaluating current line
;; (setq eir-jump-after-eval nil)
;; Uncomment if you want to always split the script window into two.
;; This will just split the current script window into two without
;; disturbing other windows.
;; (setq eir-always-split-script-window t)
;; Uncomment if you always prefer the two-window layout.
;; (setq eir-delete-other-windows t)
;; Place REPL on the left of the script window when splitting.
(setq eir-repl-placement 'below)
;; Shell support
(require 'eval-in-repl-shell)
(add-hook 'sh-mode-hook
'(lambda()
(local-set-key (kbd "C-") 'eir-eval-in-shell)))
;; Version with opposite behavior to eir-jump-after-eval configuration
;;(defun eir-eval-in-shell2 ()
;; "eval-in-repl for shell script (opposite behavior)
;;This version has the opposite behavior to the eir-jump-after-eval
;;configuration when invoked to evaluate a line."
;; (interactive)
;; (let ((eir-jump-after-eval (not eir-jump-after-eval)))
;; (eir-eval-in-shell)))
;;(add-hook 'sh-mode-hook
;; '(lambda()
;; (local-set-key (kbd "C-M-") 'eir-eval-in-shell2)))
;;--------------------------------------------------------------;;
Firstly, thank you for this excellent package!
I am brand new to both emacs and elisp, so forgive me if this is a trivial PR (or obviously a bad idea), but would it be possible to extend the package to allow the evaluation of bash code in multi-term
or ansi-term
as opposed to shell
?
Regardless, thanks for your work!
Given the Python:
def foo():
print "hello"
print "world"
If point is on the print "hello"
line, then I'd expect it to just send that line to *Python*
. Instead, it sends the whole function body.
As you wrote in your README, when developing, the workflow is to have code on one side and evaluate the changes of your functions in the repl.
I find not very useful to jump to the next form every time that you evaluate, and I would like to ask if possible to make it optional through a defcustom
so that it can be set to false (can be left on by default so we don't break the current behaviour).
Thank you for this wonderful addition, I was waiting for and when I found it I immediately share it on my twitter @richiardiandrea ๐
I use use-package
to load eval-in-repl
. Seems eval-in-repl
require js3-mode
explicitly. I think this should be conditionally by using if condition (featurep 'js3-mode)
to detect.
Here is the error I got:
Error (use-package): eval-in-repl/:config: Cannot open load file: No such file or directory, js3-mode
I am not able to see the executed command in the repl only the result for python. For example if I execute print("hello")
I only see the result hello
I am using spacemacs with emacs 27.2 on a windows machine.
Thx.
By frame support, I mean allowing the REPL buffers to show on a different "frame" (i.e. "window", in a normal term).
If this is made possible, the REPL output can be moved to a second display, which is the primary incentive for me to propose this.
I want to know what you would think.
Is this outside the scope of this library?
Would it be easy to implement this behavior?
This is already available through the eir-repl-start
function, but it would be nice to not have to replicate the knowledge of how those things are setup.
So for example wrap this inside a function:
(eir-repl-start "\\*ruby\\*" #'inf-ruby t)
Like:
(defun eir-repl-start-ruby ()
(interactive)
(eir-repl-start "\\*ruby\\*" #'inf-ruby t))
If this is something you agree with I could make the change for all packages. Then people who want to reuse the logic to get a REPL can require/autoload that part.
The first command (or region) I send using eir-eval-in-shell
(or eir-eval-in-shell2
) is not executed. Afterwards, while the buffer *shell*
exists, the commands work.
Tested using windows native shell (cmd
).
Right now control-return command in an org mode python source block fires up python repl. Can I associate that command with a jupyter-repl ?
Thx.
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.
Is this (require 'ess)
in many files an typo?
Because ess
is at here. https://github.com/emacs-ess/ESS
I want to improve my Python workflow in the following way:
I do the following with Elpy but since I use spacemacs I'd rather not use it since it is big.
(defun jv-python/elpy-shell-send-word ()
"Send word at cursor."
(interactive)
(elpy-shell--ensure-shell-running)
(when (not elpy-shell-echo-input) (elpy-shell--append-to-shell-output "\n"))
(elpy-shell--with-maybe-echo
(python-shell-send-string (thing-at-point 'symbol)))
)
Can someone please help me with the points above using spacemacs + eir?
Dear Kazuki,
Thank you for this great package -- I wanted ``geiser for (js|ruby|python|R)'' and here they are, all in one!
I found a small issue with js support (emacs24-nox on debian) -- it does not work out of the box, complaining about switch-to-js function. Brutal (defalias 'switch-to-js 'js-comint-switch-to-repl)
seems to do the trick, but I am pretty ignorant about elisp, so perhaps it's not the best solution?
Best regards!
Hello,
The error is occurring part way through the code submitted. It's a JS function, and the first line that appears in the backtrace is the fifth line of the code itself. I plugged the code into node by hand to confirm it is correct, nothing hinky there. The code is being run in an org-mode
source block.
Debugger entered--Lisp error: (wrong-number-of-arguments #<subr js-comint-start-or-switch-to-repl> 1) switch-to-js(t)
#f(compiled-function () #<bytecode 0x1e820db659a472>)() eir-send-to-repl(#f(compiled-function () #<bytecode
0x1e820db659a472>)
comint-send-input " const codeEnd = Math.ceil(Math.random()*factor);")
apply(eir-send-to-repl (#f(compiled-function () #<bytecode 0x1e820db659a472>) comint-send-input " const codeEnd =
Math.ceil(Math.random()*factor);")) eir-send-to-javascript(" const codeEnd = Math.ceil(Math.random()*factor);")
eir-eval-in-javascript() ober-eval-in-repl()
funcall-interactively(ober-eval-in-repl)
command-execute(ober-eval-in-repl)
GNU Emacs 29.0.50 (build 1, x86_64-w64-mingw32) of 2021-10-12
org-mode version 9.5
Windows 10 Pro
Hello,
I have been wanting something like this package for a very long time so that I may have the ease of ess in arbitrary languages. I was super pleased to find it.
While playing with it in python, I had some very strange and difficult-to-reproduce problems with 'Overlapping strings detected'. I eventually hunted down my problems to python-nav-forward-*. Since I know ess a bit more than python.el, I decided to yank the logic from there and implement a python version of 'ess-eval-region-or-function-or-paragraph-and-step' (eerofopas) by mostly copy/pasting from ess.
In the process of making it work, I found myself looking at eir-eval-in-python-repl/python.el and thinking that the logic should work pretty easily with perl's various REPLs. So I did a little more copy/pasting and made eir-eval-in-perl-repl.
Finally, I added a function to eval-in-repl which is just a (cond ...) to invoke the various eval flavors depending on the current buffer's major mode.
I only about 75% finished any of these tasks though, as I needed to get back to work. If any of them are of interest, I would be happy to finish them, clean them up, and send a PR, as they are currently sitting in my fork.
I hope you are doing well.
I found eval-in-repl will hide other windows, only show two windows, one is the source code buffer, and the other is the repl buffer. Sometimes I open many buffers, this behavior is bad. I have to open those buffers again, and I even can't remember which buffers I opened.
It has one benifit, it's clear.
I think this might need an option to toggle this behavior?
I found there is one line (essh-next-code-line)
in eir-eval-in-ruby
definition.
But I have not found essh
in Emacs library. And there there is no this package in MELPA.
Some commits in the past years have changed the way Geiser REPL buffers are named, see for instance emacsmirror/geiser@f9a40fe
or emacsmirror/geiser@47b3783
The issue could be fixed simply by editing the regexp function, I'll do this in a pull request.
I'm seeing that it hasn't been updated in years and that some deprecation issues have not been handled. Thanks for the work ;)
Hello again, this time with another idea !
Inf-clojure comes as a lighter alternative to cider
for Clojure and it is usually triggered by calling M-x inf-clojure
. People are using it because it does one thing only and well (as every tool should be!).
It would be a great fit in eval-in-repl
imho ๐
As usual, thanks for your work, I use this package a lot.
Hi,
please tag the latest release 0.2.0 as such in git, so that melpa-stable will also be able to pick it up.
Thanks!!
It would be handy to have a fully transparent eir-eval-in-repl-lisp
facade.
For example, we could pass arguments to it that would go directly downstream to the correct "implementation" (-cider
, ...).
Another use case, in lisp I am often instrumenting edebug
according to the following:
With a prefix argument, C-M-x instruments the function definition for Edebug, the Emacs Lisp Debugger. See Instrumenting for Edebug in the Emacs Lisp Reference Manual.
Do you think it would be hard to accomplish?
eval-in-repl-racket.el
uses the function racket--repl-show-and-move-to-end
from racket-mode
. However, this function is no longer available. I'm not sure what it has been replaced with, but the issue can be fixed by replacing the function with it's previous implementation. That is
(defalias 'eir-send-to-racket
(apply-partially 'eir-send-to-repl
;; fun-change-to-repl
#'(lambda ()
;; Show Racket REPL (focus comes back)
(racket--repl-show-and-move-to-end)
;; Go to the other window
(other-window 1))
;; fun-execute
#'comint-send-input)
"Send expression to *Racket REPL* and have it evaluated.")
Can be rewritten as
(defalias 'eir-send-to-racket
(apply-partially 'eir-send-to-repl
;; fun-change-to-repl
#'(lambda ()
;; Show Racket REPL (focus comes back)
(display-buffer racket-repl-buffer-name)
(save-selected-window
(select-window (get-buffer-window racket-repl-buffer-name))
(comint-show-maximum-output))
;; Go to the other window
(other-window 1))
;; fun-execute
#'comint-send-input)
"Send expression to *Racket REPL* and have it evaluated.")
Probably not the prettiest solution but it fixes the issue.
Hi,
I'm playing around with the python eval-in-repl and was wondering if there is a possibility to configure it so that when you press the key combo C- the line is sent but if you don't have the inferor mode buffer open the the buffer configuration will just stay as it is.
I usually have the buffers as I want them and this is changing that somewhat.
Hi,
Thanks for this nice package. FYI, there are many byte-compile warnings when installing this package, if you don't have all of the supported modes installed:
Leaving directory `/home/me/.emacs.d/elpa/eval-in-repl-20160418.1843'
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-cider.el at Tue Nov 8 01:57:03 2016
Entering directory `/home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/'
eval-in-repl-cider.el:36:1:Error: Cannot open load file: no such file or directory, cider
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-geiser.el at Tue Nov 8 01:57:03 2016
eval-in-repl-geiser.el:36:1:Error: Cannot open load file: no such file or directory, geiser-mode
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-hy.el at Tue Nov 8 01:57:03 2016
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-ielm.el at Tue Nov 8 01:57:03 2016
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-javascript.el at Tue Nov 8 01:57:04 2016
eval-in-repl-javascript.el:37:1:Error: Cannot open load file: no such file or directory, js3-mode
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-ocaml.el at Tue Nov 8 01:57:04 2016
eval-in-repl-ocaml.el:36:1:Error: Cannot open load file: no such file or directory, tuareg
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-prolog.el at Tue Nov 8 01:57:04 2016
In end of data:
eval-in-repl-prolog.el:87:1:Warning: the function `prolog-consult-region' is
not known to be defined.
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-python.el at Tue Nov 8 01:57:04 2016
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-racket.el at Tue Nov 8 01:57:04 2016
eval-in-repl-racket.el:36:1:Error: Cannot open load file: no such file or directory, racket-mode
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-ruby.el at Tue Nov 8 01:57:04 2016
eval-in-repl-ruby.el:37:1:Error: Cannot open load file: no such file or directory, inf-ruby
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-scheme.el at Tue Nov 8 01:57:04 2016
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-shell.el at Tue Nov 8 01:57:04 2016
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-slime.el at Tue Nov 8 01:57:05 2016
eval-in-repl-slime.el:36:1:Error: Cannot open load file: no such file or directory, slime
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl-sml.el at Tue Nov 8 01:57:05 2016
eval-in-repl-sml.el:36:1:Error: Cannot open load file: no such file or directory, sml-mode
Compiling file /home/me/.emacs.d/elpa/eval-in-repl-20160418.1843/eval-in-repl.el at Tue Nov 8 01:57:05 2016
eval-in-repl.el:136:1:Warning: Unused lexical variable `name-repl-buffer'
eval-in-repl.el:136:1:Warning: Unused lexical variable `name-script-buffer'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.