Sometimes when in comint mode the point is anywhere in the buffer and I press Return by mistake. This sends the text at point to the underlying process, which can be really dangerous. Often this text contains many lines and, by chance or not, one of them could be a valid command.

Is there any way to tell comint not to execute anything on Return except the last input?

  • A comment in comint.el:comint-get-old-input-default seems to indicate that the behavior you observe is a bug. I suggest that you report it as such using M-x report-emacs-bug. – sds Jul 11 at 13:56
  • I don't think it is a bug, it has been a consistent behavior of any inferior mode for years, and that comment seems to be related to the fact that the commented function returns different things when the point is at an input line than when it is at an output one. – memeplex Jul 11 at 16:33

The documented way seems to be override comint-get-old-input variable with a custom function. Easiest will be something like this:

(setq comint-get-old-input (lambda () (end-of-buffer) (comint-get-old-input-default)))

It goes to the end of buffer first, and only then calls coming-get-olt-input-default, effectively not messing with the previous output. Put it in your init.el, brief testing shows that it works.

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.