Thursday, July 9, 2009


When we speak of variables in a programming language, we are generally referring to its name as the name is the only thing we can be sure of. The contents of a variable can and do change over time and that is why it is called a variable. The variable concept in emacs lisp is very flexible as it has very limited types but it does have typing. It could be a primitive type like a string, number, list or a more complex type like an association list, a hash table and so on. In order to know the value that is contained in a variable all you have to do is place the cursor at the end of the variable name and press C-x C-e. There are many in-built variables for emacs such as fill-column and others as given in the code below.
Code :
  1. fill-column
  2. 'fill-column
  3. (concat (number-to-string fill-column) " width")
  4. (message "Hi %s!\nHow are you" user-login-name)
In order to set the variable there are two functions called set and setq. The syntax of set is (set var val) where var is the variable to be set and val is its (new) value. More on set and setq can be referred here. Check out what happens when you set the variables given below. You need to be running the graphic version of emacs in order to see the changes. If you are running the graphical version of emacs then you will see some strange things happen to the cursor as you set the values below one after another.
Code :
  1. (setq initial-cursor cursor-type)
  2. (setq cursor-type 'box)
  3. (setq cursor-type 'hollow)
  4. (setq cursor-type 'bar)
  5. (setq cursor-type '(bar . 5))
  6. (setq cursor-type 'hbar)
  7. (setq cursor-type '(hbar . 5))
  8. (setq cursor-type initial-cursor)
For the next set of commands you must be running the graphical version of emacs and you must place the cursor inside the emacs window where there is no text.
Code :
  1. (setq initial-pointer void-text-area-pointer)
  2. (setq void-text-area-pointer 'arrow)
  3. (setq void-text-area-pointer 'text)
  4. (setq void-text-area-pointer 'hand)
  5. (setq void-text-area-pointer 'vdrag)
  6. (setq void-text-area-pointer 'hdrag)
  7. (setq void-text-area-pointer 'modeline)
  8. (setq void-text-area-pointer 'hourglass)
  9. (setq void-text-area-pointer initial-pointer)
Now, before I wind up there is one small thing I would like to tell you. It is about your .emacs file. You can customise emacs endlessly by storing some commands like the ones given above to be executed automatically.For instance open your ~/.emacs file and save the following lines. You can add any more commands that you would like emacs to execute automatically after startup.
Code :
  1. (setq default-directory "~/Desktop/")
  2. (setq initial-scratch-message "Hello World!")
Setting the default-directory variable will result in C-x C-f (find-file) prompting you with the deafault path you set it to. Setting the scratch-message will result in the message appearing in the *scratch* buffer. If you would like to see this happpen you have to save the above lines in your ~/.emacs file and restart emacs.


Post a Comment