When I do python development in emacs, I want an IPython shell available. Here is my current way of accomplishing this:
M-x ansi-term
Which prompts me with Run program: /bin/bash, which I replace with /usr/bin/ipython
It's often the case that I want another terminal in emacs, perhaps to run the app, so I do:
M-x rename-buffer
and change the name of the buffer to ipython so that I can change buffers easily, with having to remember which terminal was the IPython shell.
It seems that there would be a way to create an emacs command that would accomplish all of this with a few keystrokes, but I don't know the right way to begin, being fairly inexperienced with Emacs.
Here's the code:
(defun ipython ()
(interactive)
(ansi-term "/usr/bin/ipython" "ipython"))
Also, smex makes it even faster to start.
Suggest to run IPython from a python-mode.
M-x ipython RET would be sufficient if python-mode.el is loaded.
python.el comes with comments in head how to configure, so M-x run-python RET will open an properly named IPython-shell buffer.
Related
In the ESS (Emacs speaks Statistics) manual, it says if I use Cygwin bash shell, I should run M-x S RET.
and if MSDOS prompt shell, run something like M-x S+6-msdos RET.
so what's the proper syntax for starting a Stata process? I tried M-x stata-msdos RET, M-x sta-msdos, and M-x Stata-msdos and failed.
EDIT 1: I'm using Windows 8.1 and MSDOS prompt shell (this is the shell pops up when I use M-x shell)
It seems there is some problem when I use M-x stata RET (might not be the right command for msdos shell), instead of opening a new buffer in Stata mode, Emacs starts Stata in its own window and leaves the old Emacs window irresponsive, which I have to force kill in the end.
EDIT 2: I asked roughly the same question in the ess mailing list and someone mentioned that it seems in Windows Stata Can only be used with its own GUI, not the command line, and that explains why when I M-x stata RET it always opens its own window ( I thought it was because I was using the wrong command). I asked the question because I didn't see the question being asked, now I guess I understand (sadly) why: because it can not be solved..
When I try to get rlwrap to work inside an Emacs (version 24.3.50.1) shell buffer (either M-x shell or M-x eshell), I get this error message:
rlwrap: Oops, crashed (caught SIGFPE) - this should not have happened!
For example:
rlwrap telnet google.com 80
wors fine from a regular terminal (like xterm), but crashes from a shell inside an Emacs buffer.
Several people are having similar issue but the only "answer" I could find so far is a "RTFM" style answer on mailing lists. I did read that part of Emacs' doc and I don't understand what I'm supposed to do to make rlwrap work from within Emacs.
Try using M-xansi-term instead of shell/eshell.
shell and eshell do not provide terminal emulation functionality, but readline requires terminal emulation capabilities to move the cursor etc.
Steps to reproduce this:
open emacs
M-x shell RET
vi tmpfile RET
Then you'll see the vi interface is a mess. To quit this, try to blind input :q! or just close the shell buffer.
The reason I use "vi" within emacs is that I use emacs shell-mode heavily and sometimes I ssh to another host within it. On the remote host, i have a reason to use "vi" when i need to edit some file and emacs is absent there.
Your help is appreciated.
I strongly suspect that a proper terminal emulator is necessary for anything like that.
Emacs has one, happily. Try running M-x ansi-term. You can run a shell within that (the default option) and then ssh to the remote host as you were in shell mode.
(If you didn't need to change hosts then you could run vi directly, instead of a shell.)
You might also find Remote ssh connection from within Emacs useful.
You will undoubtedly want to stick to char-mode in the terminal when using vi.
See: C-hig (emacs) Terminal emulator RET
Suppose I am in terminal in Emacs (M-x term), and I list the following files in current directory:
text_code.R
Now I am in bash-3.2$ (terminal) and hope to open this .R file in another Emacs buffer and then edit. Is there a way to do it? This might be a trivial question, for I am a newbie to Linux and Emacs. Thanks in advance!
Remember that in Term Mode you can type C-c C-f to open a file (just like C-x C-f outside Term Mode). The prompt will already be on your current directory, so you just have to start typing the name of the file and autocomplete it with TAB.
I don't know the official procedure for what you want to do, but here is a procedure that works:
Either tell emacs to run as a daemon (Ref: EmacsAsDaemon) or in emacs start daemon via M-x server-start.
In the term, a command like emacsclient -n filename will start editing the specified file in the current window. Note, emacsclient also has a -c, --create-frame option to edit in a new frame. You probably will want to use a -n option as above, so you can continue using your term, after selecting it from the buffers list in another pane or frame.
If you start the daemon via M-x server-start in emacs, the daemon will terminate when you exit from emacs. If you set it up via reference mentioned above, use kill-emacs or save-buffers-kill-emacs commands or shell command emacsclient -e '(kill-emacs)' to stop it, as mentioned in part 6 of reference.
I have been researching how to get Cygwin to work under emacs. I have it working, but now I want to write a macro that will do the following:
Launch by typing M-x cygwin
Have the script stored in some obvious place (probably my .emacs file)
M-x shell
Rename the buffer to cygwin (or cygwin1, cygwin2, cygwin3, ... if cygwin exists) probably using M-x rename-buffer
M-x ansi-color-for-comint-mode-on
M-x set-buffer-process-coding-system 'undecided-unix 'undecided-unix
Open and run cygwin
It will basically do all of the above steps. I think most of the organization for this little project is done. How do I tie it all together so I can just type M-x cygwin and see a happy new cygwin buffer? What exactly needs to be added to .emacs? Also, where exactly is .emacs in Windows?
I still want the ability to run M-x shell for the windows shell for now. I may also make similar macros for MSYS and ssh'ing to my Linux boxes. How do I get started?
Many questions, here are some answers:
Your .emacs can exist many places, it depends, read here. In short try C-x C-f .emacs, or check the value of the variable 'user-init-file (C-h v user-init-file).
I think the command you want is something along the lines of this:
(require 'comint) ; this does require comint
(defun cygwin ()
"do what i want for cygwin"
(interactive)
(let ((buffer (get-buffer-create (generate-new-buffer-name "cygwin"))))
(pop-to-buffer buffer)
(unless (comint-check-proc buffer)
(apply 'make-comint-in-buffer (buffer-name buffer) buffer "c:/cygwin/Cygwin.bat"
nil
nil)
(ansi-color-for-comint-mode-on)
(set-buffer-process-coding-system 'undecided-unix 'undecided-unix))))
Note: I directly ran the process Cygwin.bat instead of running shell and then starting that batch program. I believe the effect is the same, and more straight forward. I did choose the easy way out for naming the buffer (using 'generate-new-buffer-name) - you'll want to customize to what you want.
You can dump the above command in your .emacs easiest by doing the C-x C-f .emacs and pasting it in the buffer that gets opened up. Save it and restart (or do M-x eval-defun when your cursor is in the body of that command. Then M-x cygwin will run the command.