First of all, you shouldn't be using accept-process-output if you want asynchronous processing. Emacs will accept output every time when it is waiting for user input.
The proper way to go is to use filter functions to intercept the output. You don't need to create or delete the filter(s) depending on whether you still have lines to send. Rather, you will ...
You can save the buffer-local value of comint-input-ring in a global variable when an *ielm* buffer is killed and restore it in inferior-emacs-lisp-mode-hook:
;; global copy of the buffer-local variable
(defvar ielm-comint-input-ring nil)
(defun set-ielm-comint-input-ring ()
;; create a buffer-local binding of kill-buffer-hook
Running eval "$(direnv hook $0)" defines a function that hooks into $PROMPT_COMMAND, which is never called when bash is run as bash -ic because there is no prompt. You can change the line:
eval "$(direnv hook $0)"
eval "$(direnv hook $0)" && _direnv_hook
to explicitly call the hook function.
Edit: Just realized rekado gave a very similar ...
This doesn't seem to be a problem with Emacs but with bash. shell-command just executes call-process on the shell and passes arguments. I tried this on a regular shell:
bash -ic "cd ~/code/foo && echo $PATH"
~/.bashrc is sourced, but the direnv hook is not run. When direnv hook bash is executed, a function _direnv_hook is output and prepended to ...
Here's a simple function that gets the pid of the process running in the current buffer and then calls the pstree command to get the process tree of that process:
(defun iproc ()
(let ((pid (process-id (get-buffer-process (current-buffer)))))
(shell-command (format "pstree -p %d" pid))))
If I have a *shell* buffer running bash, run ...
Note: Made following minor changes to your code block:
Moved #!/bin/bash into code block header :shebang #!/bin/bash to automatically set executable file permissions when block is tangled into dir-input.sh.
Added debug code to show $TEST_DIR was assigned correctly from read input_variable.
#+BEGIN_SRC sh :results output :export ...
Thanks to Rekado and Erik for pointing out how the direnv hook works by using $PROMPT_COMMAND. Since shell-command doesn't use a prompt, this wasn't getting executed.
While Erik's answer works in my example of calling a shell command with M-! with default-directory set, it wouldn't work in the following example:
(let ((default-directory "~/code/"))
For the reasons you provided, I generally prefer to hold on to the buffer.
Then I write a foo-proc function which returns the corresponding process, potentially re-starting it if needed. And I even sometimes then write a foo-buffer function which calls foo-proc so that not only it gives me the buffer but it also ensures that the process is running.
inferior-emacs-lisp-mode (aka ielm), like various other subshell modes in Emacs, derives from comint-mode, a general COMmand INTerpreter. This means that ielm inherits a lot of comint's functionality and key bindings.
Emacs 25 added the command comint-clear-buffer, by default bound to C-c M-o, which works in any comint derivative, including ielm.
In older ...
You'll need to write your own function for doing this.
You'll want to read up on the functions get-buffer-process and signal-process to learn about how to send the right signal to the ESS process.
Here is an example: An interactive function that sends a SIGINT to a buffer of your choosing.
You can modify this function to target whatever ESS buffer you ...
You can test the current major-mode by querying the major-mode variable.
(if (eq major-mode 'eshell-mode) ...)
(if (eq major-mode 'comint-mode) ...)
If you would like to test a mode, and all of it's child modes, try this instead:
(if (derived-mode-p 'eshell-mode) ...)
(if (derived-mode-p 'comint-mode) ...)
Could someone explain this behavior?
The documentation of line-end-position has a note at the end that explains this behavior:
This function constrains the returned position to the current field
unless that would be on a different line than the original,
unconstrained result. If N is nil or 1, and a rear-sticky field ends
at point, the scan stops ...
I followed this guide:
and also took hint of a comment in the similar SO-question you mentioned (which advised using the LOCAL argument of add-hook, but see note below!). So this seems to work for me:
(defun comint-write-history-on-exit (process event)
"Write comint ...
You're looking for the commands comint-previous-matching-input-from-input and comint-next-matching-input-from-input, which by default are bound to C-c M-r and C-c M-s.
I recommend binding these command to M-p and M-n, like so:
;; originally on C-c M-r and C-c M-s
(define-key comint-mode-map (kbd "M-p") #'comint-...
Dan's comment helped me on the way. Comint achieves the prompt protecting functionality with text-properties. I can add the needed properties in eshell by evaluating.
there must be something wrong with my config, but I don't know what to look for that might be causing it.
So that's your question, in fact: How do I find how my init file caused a problem?
The answer is to use the usual binary search (O(logN)): Recursively bisect your init file until you find what introduces the problem.
You can do this by commenting out ...
I realize it's an old question, but since it was left unanswered, I will bring the fix I found here after running into the same issue.
Make sure your version of IPython is at least 5.4
Install rlipython (sudo pip install rlipython)
Run IPython and then run inside import rlipython; rlipython.install()
And that's it.
All the best!
I'm a beginner when it comes to Emacs (Lisp) but the following seems to work (at least for me). I'm also using the Spacemacs configuration framework so there's a possibility of some stuff being Spacemacs-only (feel free to edit such stuff).
For those not yet familiar with imaxima, it's an Emacs package that comes prepackaged with Maxima. To start using it, ...
nowadays you would likely want to use https://github.com/wbolster/emacs-direnv
it works similar to the hook that direnv installs in your shell. the emacs environment is updated on request (or automatically when switching buffers) to match what direnv states is the correct environment for the current directory.
by modifying exec-path and process-environment ...
As far as I can tell, comint offers the variable comint-input-ring-file-name for this. It wouldn't make much sense to use this globally, because all "frontend" functions that use comint under the hood would mix their history.
Instead, the frontends maintain their own history by making comint-input-ring-file-name buffer-local and setting it to something ...
After some research, I was able to solve it by adding this to my init.el:
(define-key rust-mode-map (kbd "C-r") 'my-cargo-run))
(defun my-cargo-run ()
"Build and run Rust code."
(run-win (display-buffer (get-buffer "*Cargo Run*") nil '...
Setting comint-input-ring-separator so that the whole timestamp is treated as part of the command separator worked for me. For example:
; Remember lots of previous commands in shell-mode
(setq comint-input-ring-size 100000)
(add-hook 'shell-mode-hook 'my-shell-mode-hook)
(defun my-shell-mode-hook ()
(setq comint-input-ring-file-name "~/.zsh_history")
So this isn't a proper solution but I ran your test the other way around (e.g. the while  on the second shell) and it works fine. As a work around you could ensure that any shell buffers that are likely to be generating heavy output are created later than the ones where you want interactivity. That way the interactive shells are the first to be handled by ...
Source of the problem
So the problem is in the ESS variable ess-microsoft-p. Defined as:
(defvar ess-microsoft-p (or (equal window-system 'w32)
(equal window-system 'win32)
(equal window-system 'mswindows))
"Value is t if the OS is one of Microsoft's, nil otherwise.")
When you run Emacs from a ...
Advise comint functions which use (accept-process-output proc), so that accept-process-output is redefined to send nil instead of proc. Without proc, it will use adaptive read buffering and a longer timeout. This was broken in recent emacs, (after emacs-24.3.91) but fixed and improved by me after ~25.05.50.
Change comint's accept-process-output ...
It was easier to find than I thought.
This was the culprit (hiwin-activate) from hiwin-mode
I opened this issue: https://github.com/yoshida-mediba/hiwin-mode/issues/7
I switched to https://github.com/mina86/auto-dim-other-buffers.el
Not sure which ipy mode, You are referring. I use ipython shell which comes with elpy. It also has the same problem.
By default up arrow (or M-p) are bind to (comint-previous-input ARG). So no matter what You have at cursor, it just shows the previous input.
There is another function called (comint-previous-matching-input-from-input N) which basically ...
One crude non-robust way to get the last output in term-modeis:
(defun term-recommended-hook ()
"Hook function recommended as `term-mode-hook'. (See file \"term.el\".)"
(setq term-prompt-regexp "^[^#$%>\n]*[#$%>] *")
(setq-local mouse-yank-at-point t)
(setq-local transient-mark-mode nil)
(setq tab-width 8 ))