Tag Archives: learning

Emacs IS magic

Emacs isn’t a swiss army knife

The typical Emacs’ user would argue that Emacs is a swiss army knife for programmer. On this, I beg to differ. Emacs isn’t only for programmers; it’s for everyone who needs to use a computer daily for his work. It isn’t a swiss army knife either. Emacs is what magic would look like if it was real.

A magical realm

Everything in Emacs is a function. Even when you hit the a key, you are in fact calling the self-insert-command with the character “a” as an argument. If you want to replace a string, you have to do M-x replace-string. No menu bar (well there is one, but you should really try to learn the commands), no “click there”, no easy way… or so you would think. This is until you realize that Emacs is like magic. Then you are not entering a function name, but rather saying a magic formula. You want to format your text with 80 characters max per line? Close your eyes, take a deep breath, and then call auto-fill-mode.

In magic, knowing something’s true name grants power over it. In Emacs, when you know a function’s name, you acquire its power. M-x shell will invoke the shell. M-x org-mode will activate the all-powerful Org-mode.

Alchemy circle and text

Text in Emacs isn’t simply text, just like an alchemy circle isn’t simply a drawing. If text is entered in a correct pattern, such as (+ 1 2 3), you can ask Emacs to evaluate it by doing C-x+C-e.

https://frozenlock.files.wordpress.com/2011/11/wpid-alchemy.jpg

Here is a compelling example:

If you are using Emacs 22, you already have the needed url package, and you can eval this code:

(let ((buffer (url-retrieve-synchronously
http://tromey.com/elpa/package-install.el“)))
(save-excursion
(set-buffer buffer)
(goto-char (point-min))
(re-search-forward “^$” nil ‘move)
(eval-region (point) (point-max))
(kill-buffer (current-buffer))))

In layman terms, you copy the code and paste it in a temporary buffer. Then, you roll up your sleeves, close your eyes and M-x eval-buffer. At this point, imagine the brooms from Fantasia awakening to do their master’s desires.

https://frozenlock.files.wordpress.com/2011/11/wpid-broom.gif

Magic scrolls

In order to learn, or at least to use new magic formula, a wizard needs a scroll. The same thing exists in Emacs: a .el file. This file has the architecture of a new formula in it. Inert when opened in an ordinary text editor, it will be full of life once in Emacs and permits wonders of new possibilities.

This scroll can then be added to the spell-book (saved and added to the load-path) or kept temporarily for a single use in a buffer.

New formula

In order to “invent” a new magic formula, a wizard must combines already existing one. He takes a little ido-completing-read, add ding and use one of his own pre-made list. With this, he can conjure a whole new function which will help him choose in a list and make a sound once the choice is done:

(defun choice-helper ()
  (interactive)
  (ido-completing-read "Choose this: " pre-made-list)
  (ding))

The sorcerer investment

In Dungeons and Dragons genre, as well as fantastic books, becoming a sorcerer is pretty much always the hardest thing one can do. It requires time, effort and a great deal of learning. However, once the apprentice starts to be proficient, he becomes stronger than everyone else. Not only that, but his powers seem to grow exponentially. This time again, Emacs is similar.

Sure, you will probably get this “little text” done faster in notepad (or, God forbid, Word) if it’s the only text you will ever do on a computer. You laugh at your friend struggling for his first time in Emacs… but soon enough, he will do things you can only describe as “magic”. What would take you a hundred keystrokes and fifty clicks, he will do in 3 functions. And then he will merge these 3 functions into one, binding it to <f5>, leaving you forever in the dust.