vi editing crashes within the shell-mode of emacs - shell

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

Related

How to open a file in emacs from the terminal without a new instance of emacs opening?

Does anyone know why my terminal opens a new instance of emacs whenever I run emacs "filename" from my terminal?
My google results about the issue showed too many occurrences of people trying to do this liberately, but my emacs is doing this by default for some reason.
I've found no resolving cases in my init.el or ~/.zshrc
If emacs is already running, you can start a server (M-x start-server) from within emacs, and open files with emacsclient on the command line. You may create an alias for that.
Spacemacs has a dotspacemacs-enable-server setting in your init.el file (SPC f e d) to always enable the server.
This is a pretty normal default behavior for any program. If you have a cat process running in one terminal, and you run cat again in another, they're not going to somehow share: you get two copies of cat running. The same thing applies to emacs. There are configuration options to change this, basically by making the first instance of emacs act as a server. Then the second emacs still starts a new process, but instead of continuing to set up a brand new editor it just sends information to the server process.

Implicitly launch detached program (&) from terminal

I feel sure this will end up as a duplicate, but I don't know how to word it so that I can search for it...
I like to do my programming in emacs, which I launch from the terminal. When I use my mac I use aquamacs and the command
aquamacs Program.py
will launch aquamacs in a separate window ready to edit Program.py. When I work on my linux machine however to get the same result I must type
emacs Program.py &
And I'm always forgetting the "&". So 70% of the time I end up closing the emacs window, and relaunching again with the "&". Now I understand why that "&" is there, but is there a way to set up my system so that the command
emacs Program.py
always launches as a detached process? The only time I might not want that behavior is if I was SSHing in over a slow connection, in which case I usually use "-nw" anyway.
You can click on the terminal and press Ctrl-Z to move an already running foreground process to the background.
Alternatively you could add this function to your ~/.bashrc:
emacs() {
command emacs "$#" &
}
For the specific case of emacs, I use a shell script, which is more complicated than this but for your purposes boils down to
#!/bin/csh -f
/bin/emacs $*:q &
Put it in a directory which is earlier in your $path than where the "real" emacs is, and replace /bin/emacs with the real path to emacs on your system.

open a file in an emacs buffer while in emacs terminal

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.

Can I get GNU Emacs to TAB complete filenames after using ssh in the *shell* buffer?

I am using GNU Emacs 23.1.50.1 (i486-pc-linux-gnu).
What I want is conceptually simple, [TAB] indicates that I press the
TAB key.
M-x shell
erik#furby:~$ ls
bin Desktop Documents Dropbox R.tools
erik#furby:~$ cd Drop[TAB]
and tab completion works fine (i.e., Dropbox is completed)
However, as soon as I ssh, this no longer works.
ssh erik#remote.edu
Terminal = dumb
erik#remote:~> ls
bin private
erik#remote:~> cd priv[TAB]
and the minibuffer displays
"No completions of priv"
I've found others with the same problems, but
could not discern the solution.
http://www.linuxforums.org/forum/red-hat-fedora-linux/56103-tab-completion-problem-ssh-shell-through-emacs.html
Emacs remote shell
OK, after I posted the question, I stumbled on dirtrack-mode , which appears to have a solution, although not entirely trivial. It uses dirtrack-mode, and the author says:
"It took me a long time to figure out how to get tab-completion working in shell-mode when I was ssh’d into another computer."
It's been annoying me for years; I'm glad I'm not the only one!
This answer to a duplicate worked for me:
C-x C-f /user#host:~ (open a directory on the remote server in dired mode)
M-x shell in the dired buffer
It works with eshell if you instead of doing ssh user#host you do cd /ssh:user#host: however it doesn't seem to work with shell.

Launching server emacs from shell

I'm in a class that uses an implementation of Emacs on a school server. I'm on a mac running snow leopard, and I have my own implementation of Emacs on it. To access the server-Emacs, I ssh into the server and launch Emacs from its location there.
I'm relativly new to emacs, and I have a particular problem whenever I try to access the server-emacs from my local-emacs' shell-mode, having ssh'd into the server. It gives me the error that "Screen size -1x80 is too small", and doesn't launch the server-emacs.
I've the separate issue that when I try to do this in Apple's terminal, it does launch the server-emacs, but I really, really dislike the interface when emacs is launched within a terminal.
I've tried a couple of times to launch the server-emacs within a new window, in both scenarios, but apparently I'm not doing it right.
I think it'd be useful to understand what you're trying to do.
Do you just want to edit files on the server? If that's the case, read the documentation for tramp, and try:
C-x C-f //user#server:/path/to/file
If you really want to use the emacs running on the server, try creating a frame on your
(if so, look up tramp) If you want to actually use the emacs from the server, but have the window display on your mac:
ssh server
setenv DISPLAY mymac:0
emacsclient file &
This does assume you're running X11, and know how to resolve the display for your Mac. You can get X11 for the Mac here.
It's a bit hard to tell what you are doing, but you probably want to ssh to the server with an X tunnel, then run emacs there which will pop up the window on your mac.
First, don't use Terminal.
On your mac, start up X11 (google for XQuartz if you don't already have it).
Start up an XTerm (it should do this by default). From that XTerm, ssh to your server with the -Y option:
ssh -Y me#server.something
This should get you a remote shell and setup the DISPLAY environment to tunnel right back to your Mac's X server. Test it by running an xterm from there. If that works, you can instead run emacs. If that works, you can combine it with the ssh invocation:
ssh -Y me#server.something /usr/bin/emacs # or whatever path you need
You should set up ssh to not require a password but that's more than you asked for.
I think that Trey Jackson's suggestion of tramp (or the more old-fashioned 'ange-ftp) is probably your best bet.
In general, running emacs inside an emacs is never a good idea. You either want to run emacs on the server (in -nw mode inside the terminal, or via some $DISPLAY magic) or run it on your mac (via tramp). There isn't really a good way to do both.

Resources