We’re rewarding the question askers & reputations are being recalculated! Read more.

Hot answers tagged

19

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 ...


6

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.


5

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 (make-local-variable '...


5

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)" to: eval "$(direnv hook $0)" && _direnv_hook to explicitly call the hook function. Edit: Just realized rekado gave a very similar ...


5

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 ...


5

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 ...


5

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 () (interactive) (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 ...


5

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 ...


4

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/")) (...


4

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 ...


4

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) ...)


4

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: (eval-after-load 'comint '(progn ;; originally on C-c M-r and C-c M-s (define-key comint-mode-map (kbd "M-p") #'comint-...


4

Try this 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 ...


3

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 ...


3

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, ...


3

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. (add-text-properties (point-at-bol) (point) '(inhibit-line-move-field-capture t rear-nonsticky t field ...


3

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 ...


3

You can do M-x ess-interrupt.


2

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") ; ...


2

So this isn't a proper solution but I ran your test the other way around (e.g. the while [1] 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 ...


2

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 ...


2

I followed this guide: https://oleksandrmanzyuk.wordpress.com/2011/10/23/a-persistent-command-history-in-emacs/ 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 ...


2

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!


2

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 ...


2

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 UPDATE I switched to https://github.com/mina86/auto-dim-other-buffers.el


2

two options: 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 ...


2

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) (auto-fill-mode -1) (setq tab-width 8 )) (add-hook #...


2

I slightly modify @npostavs 's answer for my own use. I'll accept his answer and give him the credit. (defvar python-shell-output-chunks nil) (defun python-shell-filter-long-lines (string) (push string python-shell-output-chunks) (if (not (string-match comint-prompt-regexp string)) "" (let* ((out (mapconcat #'identity (nreverse python-shell-...


2

As suggested by the comments, the book is out of date in this respect. That command no longer kills the region; it just deletes it. The change was released in GNU Emacs 19.34 (21-aug-96) Commit a9a6f83ff3b4db87187e7f79f0a4e31d9663062a Commit 4e217e5069de0bfe49900b79f696f3feec9da6b9


2

Sorry not sure how to paste this as a comment, this works for ESS: (defun my-interrupt-ess-buffer-process () "Send a SIGINT to script's iESS process." (interactive) (signal-process (ess-get-process-buffer) 'sigint))


Only top voted, non community-wiki answers of a minimum length are eligible