~:: kalyan ::~

January 29, 2009

emacs tweak

Filed under: emacs, Linux, Script — Tags: — skalyanasundaram @ 5:34 pm

Backspace
While programming in emacs have you ever felt, you have a tab character (it is “\t” and not 8 contiguous space) and when you press backspace, instead of deleting the “\t” character, it deletes the characters one by one. It happens atleast in c, c++ mode and but not in python-mode. So you press a tab character to undo that press backspace 8 times. Isnt that tedious?

In the background the backspace character is attached to a function called “backward-delete-char-untabify”. This first converts the tab to chars and delete one character.

Lets fix it,

put this in your .emacs

(gloabl-set-key [backspace] ‘backward-delete-char)

This function does only one job, just delete the preceding character, including “\t”.

This gets applied globally everywhere in emacs. But we want to do this only when do programming. Lets do this only when we load the c-mode by doing the following

(add-hook ‘c-mode-hook ‘(lambda ()
(local-set-key [backspace] ‘backward-delete-char)))
Add this to the specific mode’s hook where ever you want to fix.

Update

Ofcourse, the above was a poor man’s solution. I did not mention it fully. When c-mode gets loaded the backspace is bound to c-electric-backspace. This take two direction based on the inputs and a variable.

first it checks the variable c-hungry-delete-key, if its true, it calls c-hungry-delete-backward which delete all the whitespace including the new line. By default this is set to nil. If you want this do M-x c-toggle-hungry-state.

Otherwise it calls the function pointed by the variable c-backspace-function. By default it points to backward-delete-char-untabify. This is where we reach if you have not modified any variable.
Now we have two solution,

1. set the variable “c-backspace-function” to “backward-delete-char”
2. The backward-delete-char-untabify again operate based on the variable “backward-delete-char-untabify-method” by default its untabify. It can take 4 values,
“untabify” – convert tab to space and delete one char
“hungry” – delete all the tabs, space backward
“all” – delete all the tabs, space and newline backward
nil – delete only one character whatever it is.

Our expectation is to delete one tab at a time. So set the variable backward-delete-char-untabify-method to nil. That should do the job

Advertisements

January 27, 2009

emacs tweak

Filed under: emacs, Linux, Script — Tags: — skalyanasundaram @ 8:36 pm

If you are working on a perl file and using emacs then emacs can really help. By default the perl-mode is loaded. Thats bit old I guess. Instead use cperl-mode which is much more improved than the perl-mode. With the cperl-mode you can get

  • Electric mode, its when you type if it automatically generate if () {}…
  • Better font-lock mode for perl
  • Help. Keep your cursor on some keyword for example use after a few seconds the minibuffer will show the help of use operator.

So make sure to replace the perl-mode by cperl-mode by doing the following in your .emacs

(defalias 'perl-mode 'cperl-mode)
and also load all the functionality by,
(setq cperl-hairy t)

Apart from this I also use flymake-mode which compiles your program as you type and mark it when there
is an error found. Load the file,
(load "~/.emacs.d/flymake.el") and enable the flymake mode.

I also see this flymake can work for c,c++,java, but haven't tried that. I also see some php extensions.

live dance programs chemistry

Filed under: General, life — skalyanasundaram @ 8:17 pm

Every live dance program starts from sun tv’s “manada mayilada” to AXN”s “you think you can dance”, every judge never forgets to say that the chemistry was good. Isn’t that the physiological factor that they are talking about? Why they are calling it as chemistry. Or is it that Androgen/Testosterone that they are talking about. What about botony, zoology then?

January 23, 2009

emacs tweak

Filed under: emacs, open-source, Script — Tags: — skalyanasundaram @ 5:58 pm

In my old project there used to be many #if 0 .. #endif which does not fall in to the comment-face of the c-mode. This always confuses me. It would be good if that block is colored like a comment. So that i can just ignore that place.

I wrote the following elisp code which adds the #if 0 section to the comment section keywords of the c-mode.
(font-lock-add-keywords
'c-mode
'(("\s-*#\s-*if\s-*0\s-*n\(.*n\)*?\s-*#\s-*endif\s-*" 0 font-lock-comment-face append)))

I have left \s-* in many places as it is because even using back reference does not improve any readability.

Blog at WordPress.com.