In Emacs, you don’t open a file, you visit it with a buffer. Simply said, you take the content of the file and dump it in a temporary space (buffer) in order to see or edit it. It’s only when you save that you will need to access the file again. You can of course use a buffer without any associated file. Simply C-x+b any-name RET, and you have a new buffer to take notes. It is quite similar to doing win+r notepad RET, but faster and inside emacs (obviously better).

If you have some text manipulation to do, simply dump it inside a buffer and use emacs insane functions to do your bidding. You can also use a temporary buffer for text manipulation by a program only. This function is called with-temp-buffer. Everything in this function will behave exactly like a normal buffer, except it won’t show it. (Anyone who has done some programming has noticed one day or another that printing stuff on the screen takes time.)

Here is the interesting part of this post: http://xahlee.blogspot.com/2011/12/emacs-lisp-processing-5-thousand-files.html By using with-temp-buffer instead of find-file, Xah Lee was able to process 5565 files in 22 seconds! A staggering 1/50 of the time previously required! If there is something you should remember, it’s to always use with-temp-buffer when there’s an opportunity.

Playing around with the numbers, you can find it took about 1s per 252 files. When I say computers can do it faster than humans, I mean it. You should use this fabulous power as often as you can!

If you want an example on how to use with-temp-buffer, I used it in a little function here.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: