March 18, 2011
Here is a very simple tip that has been really useful to me over the last few months.
The way I work in Emacs is by opening lots and lots of files and then quickly selecting the buffer I want with ido-mode.
However, this breaks down if I have more than one project loaded in my Emacs session. For example, when working on Rails projects, I want to be able to find the routes.rb file with just a few keystrokes. To avoid restarting Emacs whenever I switch project, I need multiple instances running simultaneously, which is not “supported” in OSX (or rather, it’s just not the OSX way).
To workaround this, I use a really simple hack: Copying Emacs
So to create Emacs2 and Emacs3 in addition to just Emacs, do
cp -r /Applications/Emacs.app /Applications/Emacs2.app cp -r /Applications/Emacs.app /Applications/Emacs3.app
That’s it! Now you can fire up three Emacs instances at the same time. Next step will be to replace the icons of the clones to make it easier to spot them when switching applications.
As discussed in the comments below, I can just start new instances with “open -n -a Emacs.app”. Thanks tali713 for bringing this to my attention!
June 24, 2010
Here’s a really useful Emacs tip that is easy to miss.
All Emacs users know that C-SPC sets the mark (set-mark-command). But not everybody knows that the mark is not a single value. Every time a new mark is set, it is also pushed to the mark ring. The really useful thing about this is that you can move back through that ring by giving a prefix argument to set-mark-command.
will take you back to the previous place you set the mark. It turns out that this is often what you want. For example, this could be where you last yanked a block of text or started an isearch. If you want to go back further, just repeat the jump.
An example: Say I’m editing somewhere in the middle of a long file and want to do an isearch from the beginning of the buffer. The sequence of commands would then be:
M-< (sets the mark, then jumps to beginning of buffer)
C-s (do the isearch, will also set the mark unless cancelled)
Make a few changes
C-u C-SPC C-u C-SPC (jump to previous mark twice)
I should mention that there are in fact two mark rings in Emacs: A local and a global one. Local and global in this context refers to buffer – the local ring is a per-buffer ring, the global one is across buffers.
You can backtrack along the global one with pop-global-mark:
The and global mark rings are described in sections 11.4 and 11.5 of the Emacs manual.
January 3, 2010
I’ve been considering upgrading my Emacs installation on OSX for a while. Until now, I’ve been using Carbon Emacs, and I have been quite pleased with it.
However, Emacs 23 has been the recommended release for a while now, and it’s probably time to move on. So I thought I’d use this entry to sum up my findings so far about making the switch.
First, a note about naming. “Carbon Emacs” is Emacs 22.x, distributed by Apple (CORRECTION: No, it is built and distributed by Seiji Zenitani. Thanks Ian). Not maintained or supported by Apple, but they have a pretty download page for it nonetheless. As of this writing, the build is about 6 months old.
To get Emacs 23 on the Mac, you need the Cocoa version, called simply “Emacs.app”. It can be downloaded from here, and the current version is 23.1.
Much nicer fonts
Ah yes, this is what everybody has been talking about. I know very little about typography, but I think it has to do with antialiasing and the fact that Emacs.app uses the Cocoa libraries instead of Carbon (which has been around since Mac OS 9).
The fonts look great. At first I almost couldn’t tell the difference, but it becomes very apparent once you switch to a smaller font. In Carbon Emacs, I never managed to use a 10pt font for very long at a time, because it was pretty hard for me to read. Now, it is very clear. This is obviously a huge improvement because it allows me to have more text on the screen.
I haven’t really played with this yet, but it looks cool.
This feature allows you to run emacs in “daemon mode”, meaning that it evaluates all startup files but does not open a frame. It then opens a socket and listens for clients.
To open an Emacs frame, use emacsclient. It seems to require a little extra tweaking in my setup, because when opening a client frame the toolbar is not disabled, the Meta key is not properly set up etc. But I’m sure that would be easy to fix.
The great news here is that it allows you to have one master instance of Emacs running and open files in it easily. For example, set your $EDITOR variable to “emacsclient -t”. The advantage of this method is that you can use the same instance of Emacs throughout your system. Right now I’m used to invoking something like “emacs -q -nw /etc/foo” if I need to quickly edit a file in the shell and don’t want to wait for my sea of customizations to be loaded.
weblogger.el is messed up again
I know I have no right to say this, but I want to be honest. This really, really pisses me off. I cannot believe how fragile the weblogger.el/xml-rpc.el combination is.
Until I updated to the latest versions, it didn’t work at all. I already forgot what was wrong, because I’ve gotten so used to just trying out all sorts of tweaks until it works (or I give up).
So after installing the latest versions, I am able to download the list of posts (with weblogger-fetch-entries). But alas, all of a sudden there is some issue with longlines-mode, so when writing a new entry, the text just becomes invisible. Figuring that out within a few minutes gave me a sense of Deja Vu. I must have been bitten by this issues at some time in the past, or I would never have figured out so quickly what was wrong. (UPDATE: It turned out that only the showing of hard newlines had to be turned off, and that this is not related to weblogger.el. But somewhere along the way, this entry was messed up so real newlines were inserted.)
Having to disable longlines-mode is painful to be sure, but the annoyance passes quickly as I discover another two issues.
After saving an entry (weblogger-send-entry) the *weblogger-entry* buffer is buried. Why?? (UPDATE: It turns out that this was also the case in the previous versions. I had just forgotten that I had made a dirty hack in weblogger.el to fix it).
Also, the interaction with wordpress.com is just painfully slow. It takes me about 10 secs to save an entry. I have no idea why that is. I haven’t started using https or anyting like that. A quick look at tcpdump reveals an 8 second pause that is new since my Emacs 22 setup.
This is another regression I just discovered while writing this entry. When trying to run twit-show-recent-tweets, I get the following error.
error in process sentinel: Symbol's value as variable is void: url-http-attempt-keepalives
Again, no idea what is wrong. I updated to the latest twit.el (which worked fine in Carbon Emacs). When trying in an Emacs with no customizations, it just hangs.
Fullscreen mode broken
This is a well-known issue, and a pretty serious one IMO. I get some extra text from reducing the font size, but it is wasted on menubar and window decorations as long as I can’t properly fullscreen the frame.
So, is it time for me to upgrade to Emacs 23? Absolutely not. It has taken me way too long just to write this blog entry simply because stuff keeps falling apart.
I’m afraid I’ll have to spend a significant amount of time tweaking all my customizations to work with Emacs 23. And I’m afraid it is going to be a while before I have nothing better to do. Until then, I’m stuck with Emacs 22.
But hey, that’s not so bad, is it?
December 19, 2009
Today I took another step towards Emacs adulthood: I disabled transient-mark-mode.
Big deal, you say? Well, I vividly remember the relief I felt when I found out how to enable it as a novice Emacs user two years ago. Not having a visible selection was just too wierd.
But now I’m ready to change that habit as well. I enjoy the reduced visual clutter, and ironically, I find it easier than before to quickly extend the region to the part of the buffer I want. A frequent annoyance with transient-mark-mode enabled was that I often highlighted text by accident.
However, I’m a bit annoyed that some commands don’t behave the way they used to. For example, comment-dwim (which I use a lot) needs transient-mark-mode to be enabled on the region to (un-)commet. I know that I can temporarily enable transient-mark-mode by doing two C-SPCs instead of one, so I guess it is a small price to pay. But I don’t understand why it can’t just work on the region.
I’m not sure why I suddenly decided to ditch transient-mark-mode. Maybe I accidentally highlighted a region one time too many. But it got me thinking, yet again, about the way I use Emacs. I’ve used it for a few years now, and I think I know and use the most important productivity tricks. But obviously I know that there’s so much still to learn. And now that I feel comfortable, moderately productive and (most importantly) almost never annoyed at anything, I don’t learn as much as I should. I still customize stuff at least few times a week, but I don’t learn significant new features, modes etc. very often.
I want to change that. I really want to be an Emacs wizard, not just an experienced user.
So where should I find inspiration to learn new stuff? The hard part is that I don’t know what I’m missing anymore. As a novice user, I knew what Emacs could do, but not how. Now I need to find out what else Emacs can do. Apart from the plentitude of Emacs-related blogs out there, I’ve found a really good source of inspiration. At VMware, we have a “Tips & tricks” mailing list to which I’m subscribed. Often, useful Emacs, Vim, Sed, Awk etc. tips are posted on that list. I just need to pay attention, which can be hard when you receive hundreds of emails every day.
So let that be the tip of the day. If you work with other Emacs users, learn from them. Create a forum on which you can exchange tips and tricks, be it a mailing list, wiki page or whatever.
And be sure to forward a copy of each tip to me😉
Wow, that entry ended up way too chatty.
April 16, 2009
Finally solved an issue has been driving me crazy for weeks! If I can help one other poor soul out there with this writeup, it’ll be worth it. Even if not, I need this entry to make sure I never forget how to fix this problem.
At work, I’m running Ubuntu 8.10 on my workstation. I also have an XP VM running most of the time, so when I need to do Windows work, I can just RDP into it.
I’m using rdesktop as my RDP client, and it is working great, mostly. Very lightweight and fast. So when running it in fullscreen mode, the user experience is pretty much as if I had XP running locally.
Except…there was one small but extraordinarily annoying issue.
Sometimes, after pressing the left Alt and Shift keys simultaneously, the keyboard would get into some state where it acted as if the left Windows key was depressed. The effect was that subsequent keypresses would pop up windows with dogs in them (“f”), Explorer windows (“e”) or similar. It would stay this way until I actually pressed the Windows key to somehow reset it.
It turns out that when the Alt key is depressed before the Shift key, an ALT_L window event (or whatever it’s called, I don’t even want to know) is generated for the Alt key.
But when the Shift key is depressed before the Alt key, a META_L event was generated instead!! How lame is that?!?
So this was what tripped rdesktop, and it was really a bitch to find. It seemed to pop up randomly, the randomness being caused by whichever key I happened to strike first…
Almost forgot to mention the trick I found to fix the issue. Simply put this in your .profile:
xmodmap -e "remove mod1 = Meta_L"
This causes the left Alt key to always generate an ALT_L event. Problem solved.
Seems the above method didn’t quite cut it… I also needed to add this to “.profile”:
xmodmap -e "keycode 64 = Alt_L"
For some reason, I think this has become necessary since upgrading to 9.04…?
March 4, 2009
I’m posting this mostly so I’ll know where to look the next time I forget…
This is definitely the king of obscure Emacs key combinations. To change the encoding of an existing file, use C-x RET f <encoding> RET.
Tab-completion works for the encoding. “utf-8” is the one I use most often, but “unix” and “dos” are also useful.
To make Emacs open files in UTF-8 per default, use the following snippet in .emacs:
(setq locale-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8)
October 21, 2008
I had been blogging on blogger.com for a while, but the last few months, I have been increasingly annoyed with the service. Little things, mostly, like the way the editor works and how the Preview mode is very far from the appearance of the published entry.
However, the main reason for the switch was the fact that I simply could not get Emacs support working. g-client took me some of the way, but it wasn’t nearly good enough in its current state.
Just one example: To create a new blog entry, I needed to specify a “post URL”. And to obtain that, I needed to invoke some method (forgot the name) which created a temporary webpage on my harddisk and launched Safari to show it to me! On that webpage, I could then see an overview of the blogs I had on Blogger (a list with 1 element), copy the link to the “post URL” of the blog and paste it back into Emacs.
Also, to save my new entry as a draft, I had to modify the template used for new entries to include some XML snippet that I had to look up in the Google API. And after saving or publishing an entry, the buffer was completely garbled for some reason.
OK, that was a few more examples😉
I’m not sure if it was just me who completely misunderstood how to use this library, but it seemed extremely rough around the edges.
As I have described in another entry, blogging from Emacs works beautifully with WordPress. And Emacs is where I want to spend my time, also when blogging. I like it here, it’s comfy.
Actually, I was planning on doing a thorough comparison between Blogger and WordPress, but I have realized that this would be pointless, because hundreds of others have done just that. So just google for it if you’re considering which to choose.