Showing posts with label Emacs. Show all posts
Showing posts with label Emacs. Show all posts

Sunday, January 9, 2011

Changing the Color Scheme in Emacs: the color-theme extension

If you are new to Emacs, as I am, you are probably are a little bothered by how it looks out of the box. Those of us who are just learning to use Emacs in this day and age have most probably worked with other editors (such as Textmate) that provide more eye candy right out of the box. There is no reason to be disappointed. As I have mentioned in earlier posts, Emacs is infinitely extensible and there are great color themes available to make Emacs more beautiful and more pleasing to your eyes.

For modifying the color scheme of Emacs you can use the wonderful color-theme extension. I recently installed it to work with Emacs 23.2 on Mac OS X. I have explained the steps below. These may work for other versions of Emacs.

  1. Go to http://download.savannah.gnu.org/releases/color-theme/ and download color-theme-6.6.0.zip to your computer.

    For the purpose of discussion, suppose you save this zip file in your ~/Downloads folder.
  2. Unzip the downloaded zip file. This will result in a folder named
    color-theme-6.6.0 within your ~/Downloads folder (or wherever you saved the color-theme-6.6.0.zip file).

    You may prefer to keep the color-theme-6.6.0 extension folder where you saved the color-theme-6.6.0.zip file, or you may prefer to move it to some other place on your computer where you keep downloaded Emacs extensions. If you want to move it to another place on your computer, ensure that you move the entire color-theme-6.6.0 folder. (I read this tip on some forum and had planned to link from here. Unfortunately, I deleted it and cannot find it again.)
  3. Add the following lines to your Emacs init file (~/.emacs file).
    (add-to-list 'load-path "~/Downloads/color-theme-6.6.0")
        (require 'color-theme)
        (eval-after-load "color-theme"
        '(progn
        (color-theme-initialize)
        (color-theme-dark-blue2)))
    
    Note that ~/Downloads/color-theme-6.6.0 is the folder where you saved the color-theme-6.6.0 folder. Also, dark-blue2 in the last line of the above code snippet is the name of one of the many available color themes. You can replace this by the name of the theme you like (see below how to find theme names).
  4. Close Emacs and start it again and enjoy the beautiful colors.

If you want to see the other themes that came with the extension that you downloaded, you can use M-x color-theme-select. This will open a new buffer with a list of available color themes. You can change to a theme in this list by moving the cursor to that theme in the buffer and pressing Enter.

If you want to see what different themes look like before changing yours, you can also go here: http://color-theme-select.heroku.com/#color-theme-light

Wednesday, December 29, 2010

Finding command names and customizing key-bindings in Emacs

Of the zillion things that make Emacs a great editor, one is the ability to access all its functionality using the keyboard. However, you may find that a particular key combination is not convenient for you. For example, I find it inconvenient to use M-/ (pressing the ALT key and the / key together) for word completion. No problem! Of those zillion things, another one is the ability to modify the key bidings to your liking. I explain below how to assign word completion to S-SPC (that is, getting word completion by pressing Shift and Space keys together).

1.   The first step in customizing key bindings is finding the name of the command for a given key sequence. This is done using:

    C-h c key-sequence    

Note that you should not type the key-sequence, you have to press it the way you would for invoking the command. For example, to find the name of the command that is executed when M-/ is pressed, you cannot type letter M followed by a /, you have to press ALT and / together. This will return:

     M-/ runs the command dabbrev-expand     

in the minibuffer. There, you know the name of the command.

2.   The second step is to bind your custom key-sequence to this command. Suppose you want dabbrev-expand command to be executed when Shift and Space keys are pressed together. Do the following: open ~/.emacs (or, whichever is your Emacs init file) and add the following line to that file:

     (global-set-key (kbd "S-SPC") 'dabbrev-expand)     


3.   Close Emacs and restart. You can now use your custom key-sequence for the command you assigned to it.

If you are thinking, "okay, from your example I know that I have to use
S for Shift key and SPC for the Space key, but what do I use for some other keys, say the function keys. You can find useful information regarding this and a lot more about custom key bindings at http://xahlee.org/emacs/keyboard_shortcuts.html

Tuesday, December 21, 2010

Emacs, what can you do with it?

Recently, when searching the web for a good python IDE, I came across PyCharm and a review of it by none other than the great Guido Van Rossum (see here).  From his review I learnt that he is a big fan of Emacs.  I had heard of Emacs before and I knew that it had been around for ages (Emacs development began in 1970s), but I had never given it a serious try.  Around this time, I was also looking for a good text editor.  Motivated by the knowledge that Guido was so happy with Emacs, I did a search on Google to find out whether Emacs was still worth learning. I felt this was necessary given the plethora of new editors that have been written since Emacs first came into being. Given that Emacs is so old, I thought there must be something better out there.

I found many rave reviews about emacs.  People talked about all the different things you can do with it.  Many said that it is not a text editor, it is more of an IDE. Some likened it to an operating system.  I read that Emacs has:

  1. powerful text editing and navigation commands and the ability to access all these commands with the keyboard
  2. ability to issue shell commands from within Emacs
  3. ability to perform numerous directory and file operations from within Emacs such as renaming and removing files, creating and deleting directories, browsing them etc.
  4. content sensitive editing modes for many programming languages and for TeX, LaTeX and ConTeXt.
  5. ability to function (with the help of modes such as the powerful org-mode) as a Planner, Calendar and Task manager.  (I had also been looking for a good Calendar and Task manager and most that I came across were not satisfactory for one reason or another).
  6. ability to access email and newsgroups.
    You can even play games in Emacs... I have not tried that. I was impressed after reading these things and decided to give Emacs a serious try. While I have used it for only a few weeks now,  I am quite impressed with the things that I have tried so far and am using it for increasing number of my tasks.

    If you also want to try Emacs and you use Mac OS X, the following are two possible options for downloading it:
    • GNU Emacs for Max OS X - These are vanilla builds that do not contain additional packages or patches not contained in the official release of GNU Emacs
    • Emacs for OS X modified - This is also based on GNU Emacs but come with AUCTeX and ESS. AUCTeX is useful for those who use TeX or its relatives for writing. From the ESS (Emacs Speaks Statistics) website, ESS is designed to support editing of scripts and interaction with various statistical analysis programs such as R, S-Plus, SAS, Stata and JAGS. 
    I will post here as I learn how to do various cool things in Emacs that are not possible in most other text editors.