lostwebsite.net/ emacs

This page aggregates posts in the 'Emacs' section off this blog.

superuser-edit

I'm a big fan of GNU Emacs. It's a very good programming editor but tends to be much more then that once you start digging into its feature and extensions people have spent a lot of time to write.

This makes Emacs quite unique in the world of generic text editor. Emacs users very often have their editor fired and ready to go. It might be because they always have a file to edit; programmers do that. It might also be because they use some Emacs extensions to fill-in for other programs like their IRC or mail client, like I do.

For me Emacs is always on. I can use it for most of my editing tasks by using the remote controller gnuclient.

What I could not use it for, and which annoyed me, was that I couldn't edit files owned by root inside Emacs opened as my current use.

Luckily, somebody on Planet Emacsen lead me to discover you can use TRAMP to edit files using the 'sudo' method. TRAMP enables you to access remote files from inside Emacs, like on an FTP or SFTP server, for instance. The 'sudo' access method, in that case, is just a twist of the concept, allowing you to edit files as another user on your own system.

TRAMP comes standard with Emacs 22. I personnaly use Emacs 23.something on all the computers I use, so I have not personally tested it on Emacs 22 but I have the feeling it should work fine.

To open a file as root, for example, do:

M-x find-file, /sudo::/etc/motd

And, TA-DA, it might work out of the box like that!

Yes, might. On my systems, I prefer to use ZSH. The prompt I use, and a ZSH-specific feature, conflict with TRAMP default configuration. TRAMP loads a shell with sudo in background and needs to see the shell prompt to make sure its able to send editing commands. So to be able to use TRAMP, I had to change the prompt for Emacs, or make TRAMP recognize my active prompt.

Changing the prompt is easier than it look, and can be made into a special-case for Emacs. TRAMP set the TERM environment variable to 'dumb' when it loads the shell. Since the dumb terminal mode is not something I use or want to use, I just did something like this in root's .zshrc:

if [ $TERM = "dumb" ]; then
   ...
   unsetopt zle
   PS1='$ '
fi

'$' being the cannonical UNIX shell prompt. The unsetopt zle disables the feature that might conflict with ZSH.

Posted Tue Aug 26 22:02:29 2008