fast tooth
fast tooth

Reputation: 2459

elisp, how to switch to the opening shell in another window and issue the last command

often I found myself running two windows side by side in EMACS, one for editing and another for compiling, so one is text mode and another is shell mode. The shell only runs a single compiling command, and I find it is too many keystroke to C-x o from editing window to shell window, and then M-p for the most recent command and then switch back to the editing window. I wrote the following elisp script in my .emacs for this job, but it is not actually issuing the command, it displays the last command in another window and switch back, it misses an "RET" after the comint-previous-input .

(defun issue-last-command-in-the-shell-in-another-window ()
  "issue the last command in the shell in another window" 
  (interactive)
  (progn
    (other-window 1)
    (comint-previous-input 1)
    (other-window 1 )
    ))

This is my first time write elisp, can someone help me on this? or is there already a key combination that does this? or if there is some packages that you find handy for this case?

Thank you

Upvotes: 1

Views: 153

Answers (2)

Kyle Meyer
Kyle Meyer

Reputation: 1586

There is no need for a custom function. Run the command with compile and then use recompile to rerun it. See (info "(emacs) Compilation") for more information.

Upvotes: 4

Steve Vinoski
Steve Vinoski

Reputation: 20024

In your function, after the (comint-previous-input 1) call, add the following line, which will send the input to the shell:

(comint-send-input)

Upvotes: 1

Related Questions