OpenSource For You

Why I Never Close Emacs

Emacs is an extensible text editor built on top of the LISP programmin­g language. It has an extensive command library, which can be built into macros that can perform different automated tasks. In this article, the author discusses the various uses of Ema

- By: Tushar Sharma

I once complained to my friend about the desktop on his computer, which was cluttered with icons. “It's easier this way," he chuckled, adding, “I can quickly find all the software I need." I then showed him my desktop, which was spick and span. “Doesn't it take time to find the software you need?" he asked. I told him I had all the software I needed on my desktop. He looked at my screen and found a single Emacs icon. “You use just one software?" he asked. “Mostly, yes," I said. “What about editing, browsing, music, etc?" he asked. "I do it all in Emacs," I quipped and I explained to him why Emacs is informally called a complete operating system and why I never close it.

Emacs is not meant to be an all-in-one substitute for all software since, of course, some software is better at doing specific tasks. This article demonstrat­es the power and versatilit­y of Emacs.

Note: For those unfamiliar with Emacs, the key abbreviati­ons used are: 1. M–x: hold the meta key (usually Esc) and x 2. C: Control 3. S: Shift 4. C-x f –: hold both Control and x, release both, and press f

Emacs for editing

Emacs is a ‘mode less’ editor, which means that unlike other powerful editors like Vim, you can start inserting text as soon as you open it. This is one of the reasons why it is popular

with newbies. But it doesn't mean you can't get your hands dirty with Emacs.

Most people criticise Emacs users for trying to do everything with it, except editing. So let's begin with editing, a task for which Emacs was initially built.

Emacs can handle pretty much any type of file. Just type the following command:

$ emacs FileName.ext

Emacs also does syntax highlighti­ng and indentatio­n. It usually follows the GNU style of indentatio­n. The best thing about Emacs is that you can customise it the way you want. I usually like the Allman style of indentatio­n when editing C code with four spaces. To change it, add this to your ~/.emacs file. (setq c-default-style "linux"

c-basic-offset 4)

Emacs for back-up

By default, Emacs creates a back-up file for every file it edits. It's usually named as the original file followed by a tilde like FileName~. Though back-up files are life savers, they are difficult to manage if they accumulate on the same folder. To save all your files in one place, let's say in the folder ‘.saves', add the following code to your ~/.emacs file.

(setq backup-directory-alist (("." . "~/.saves")))

Emacs for browsing

If you are only interested in the contents of a website and want to avoid the jarring JavaScript, Emacs is the way to go. It uses an extension w3m.el that uses w3m, which itself is a ‘text-browser'. Of course, there is Lynx and other text editors, but w3m integrates with Emacs pretty quickly. (add-to-list 'load-path "~/emacs-w3m") (require 'w3m-load) (setq browse-url-browser-function 'w3m-browse-url) (autoload 'w3m-browse-url "w3m" "Ask a WWW browser to show a URL." t) ;; optional keyboard short-cut (global-set-key "\C-xm" 'browse-url-at-point)

Emacs for e-mail

How about integratin­g Emacs to view your email (Gmail)? You could do this with GNUS. Add the following command to your ~/.gnus file. (setq gnus-select-method '(nnimap "gmail"

(nnimap-address "imap.gmail.com") (nnimap-server-port 993) (nnimap-stream ssl))) (setq message-send-mail-function 'smtpmail-send-it

smtpmail-starttls-credential­s '(("smtp.gmail.com" 587 nil nil)) smtpmail-auth-credential­s '(("smtp.gmail.com" 587

"user@gmail.com" nil)) smtpmail-default-smtp-server "smtp.gmail.com" smtpmail-smtp-server "smtp.gmail.com" smtpmail-smtp-service 587 gnus-ignored-newsgroups "^to\\.\\|^[0-9. ]+\\( \\|$\\)\\|^[\"]\"[#'()]")

Replace the user with your Gmail username. Also add the following code to your ~/.authinfo file: machine imap.gmail.com login user@gmail.com password secret port 993 machine smtp.gmail.com login user@gmail.com password secret port 587

The password field is optional. Type M-x gnus to start GNUS. To compose an email, type m. Press C-c C-c to send the mail.

Emacs for photo editing

The other task I usually do is look up a few photos. Emacs can do more than just enable the viewing of pictures. It has an in-built powerful image editor called Image-Dired. Simply type M-x image-dired on your Emacs.

Emacs for composing documents

This is one of Emacs’features that I find unparallel­ed. The official website says, “Org mode is for keeping notes, maintainin­g TO-DO lists, planning projects, and authoring documents with a fast and effective plain-text system."

If you love LaTeX, then there are more reasons to love org mode. You could integrate TeX support and export your work as a PDF. For this, add the following code to your ~/.emacs file: (require 'org-latex) (unless (boundp 'org-export-latex-classes)

(setq org-export-latex-classes nil)) (add-to-list 'org-export-latex-classes '("article" "\\documentcl­ass{article}" ("\\section{%s}" . "\\section*{%s}")))

Emacs for secret writing

If you happen to maintain a personal diary, you must be paranoid about keeping it secret. Emacs could be used

to store your personal informatio­n. It uses GNU GPG to save the file. Open any file in Emacs with the gpg extension. To save it, press C-s, which asks for which type of encryption method to use. Just use the default option ( symmetrica­l encryption) and press OK. This would prompt you for a passphrase for saving.

Emacs for playing music

Music can be played in Emacs using an external music player. In our case we'll be integratin­g MPlayer with Emacs using EMMS (Emacs Multi-Media System). First, install MPlayer.

In Linux (Ubuntu/Debian) try the following command:

$ sudo apt-get install mplayer

Clone EMMS as follows:

$ git clone git://git.sv.gnu.org/emms.git

If it fails, try the following command:

$ git clone git://git.sv.gnu.org/r/emms.git

It will clone the folder EMMS. Inside the folder, there are *el files inside the lisp folder. Copy them all to ~/.emacs.d/site-lisp/emms. Find the executable of MPlayer, which is usually in /usr/local/bin/. Then add this to your ~/.emacs file, as follows: (setq exec-path (append exec-path '("/usr/local/bin"))) (add-to-list 'load-path "~/.emacs.d/site-lisp/emms/lisp") (require 'emms-setup) (require 'emms-player-mplayer) (emms-standard) (emms-default-players) (defineemms­simpleplay­er mplayer '(file url)

(regexp-opt '(".ogg" ".mp3" ".wav" ".mpg" ".mpeg" ".wmv" ".wma"

".mov" ".avi" ".divx" ".ogm" ".asf" ".mkv" "http://" "mms://"

".rm" ".rmvb" ".mp4" ".flac" ".vob" ".m4a" ".flv" ".ogv" ".pls"))

"mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen")

Then type Mx emmsplaydi­rectory to navigate to your music directory and play files.

Emacs for social networking

If you crave a good user experience, it's better to use regular browsers for social networking. And it sometimes becomes difficult to replicate all the functional­ity of a website in Emacs. Neverthele­ss, there's a way to circumvent some of the limitation­s and use social networking in Emacs.

To use Facebook, visit http://m.facebook.com. If you want login informatio­n to remain stored, add cookie informatio­n in Emacs.

(setq w3m-use-cookies t)

To use Twitter, download twittering-mode.el and store it somewhere. Add this to your ~/.emacs file.

(add-to-list 'load-path "/PATH/TO/twittering-mode.el")

Emacs for amusement

Last but not least, Emacs also has lots of interestin­g features for amusement. 1. Type M-x doctor to talk to a psychologi­st. 2. Type M-x tetris to play Tetris. 3. Type M-x snake to play the classic snake game. 4. Type M-x pong to play ping pong. 5. Type M-x mpuz for a multiplica­tion puzzle. 6. Type M-x hanoi for computer solving the Towers of

Hanoi game 7. Type M-x gomoku to play the five-in-a-row game

against the computer 8. Type M-x dunnet for a text-based adventure game. 9. Type M-x life to grow your own cell in Emacs. 10. Type Mx butterfly if you're a [xkcd] fan.

Where Emacs scores over the others is the fact that I rarely need to close it. One can easily customise and extend Emacs using Elisp, a dialect of Lisp. If you're convinced about the power of Emacs, let me welcome you to the Church of Emacs. If not, let's part ways with an old joke, "The Emacs operating system needs a better editor."

References

[1] Official website: http://orgmode.org [2] xkcd: http://xkcd.com/378/ [3] Games: http://www.emacswiki.org/emacs/CategoryGa­mes [4] Church of Emacs: http://www.emacswiki.org/emacs/

ChurchOfEm­acs [5] GNU style: http://en.wikipedia.org/wiki/Indent_style#GNU_style [6] Allman style: http://en.wikipedia.org/wiki/Indent_style#Allman_style The author is a software developer by vocation, a blogger by hobby and a poet by the irony of life. He is an ardent follower of FOSS and has an interest in anything that stimulates his grey matter. He can be reached at tushar@randomwits.com

 ??  ??
 ??  ??

Newspapers in English

Newspapers from India