~:: 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.

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.

June 9, 2008

Emacs project

Filed under: emacs, General, Linux, open-source — Tags: — skalyanasundaram @ 3:46 pm

I had faced several configuration issue while using emacs as my primary development environment. All is configurable,. but it is just to put together.

I use desktop.el, cscope+.el, etags and each one of them annoyed by conflicting desktop files, having cscope key bindings while using erc or gnus, conflicting etgas between multiple projects correspondingly…

I had tried few things like, ecb, cedet but nothing suited for my requirement. So this is the initiative to make it nice.

I had kept my epr file here and here

May 16, 2008

emacs save all modified files

Filed under: emacs, open-source — Tags: — skalyanasundaram @ 10:43 pm

Few time I got bugged up with the situation where I forgot to save the buffer and trying to blame make, automake tools. It would be nice if there is some function which saves all modified buffers like “Save All” from any IDEs.

I was trying something like this

(setq var (buffer-list))
(unless (null var)
(string-match “.+.[ch].*” (buffer-name (car var)))
(save-buffer (car var))
(setq var (cdr var)))

ofcourse did not work with the last argument of string-match. Latter found save-buffer only saves current buffer and does not take buffer as argument. But which leads me to find save-some-buffers, and this what I was trying to write my own. :-/

save-some-buffers C-x s , saves all modified buffers which are all associated with files. It also ask for many questions. The beauty is if you dont remember what changes have been made in the buffer you can make a diff between the file and the buffer like the below. Review each hunk with M-n

***************
*** 19,25 ****

#include <config.h>

! #include <ctype.h>
#include <stdlib.h>
#include <string.h>
//Test
— 19,25 —-

#include <config.h>

! #kalyaninclude <ctype.h>
#include <stdlib.h>
#include <string.h>
//Test

Diff finished. Fri Jan 18 10:25:55 2008
There is an another option C-r which takes us to the modified buffer too.

Yet another nice feature 🙂

NetBeans supports emacs key bindings!!

Filed under: emacs, open-source — Tags: — skalyanasundaram @ 8:21 pm

I am working on DHCP JavaConsole recently. I though will give a try in NetBeans and I need to work on jdk1.4. Finally got NetBeans 5.0 which is compatible with jdk1.4. Surprisingly NetBeans supports the emacs key bindings. Tools=>Options in the option dialog the keybinding option need to be selected. It is satisfactory. But sometime I am getting confused with the key bindings like M-C-n M-C-p.. It would be good if NetBeans could understand .el files. So that I can customize for my own need. 😉

January 1, 2008

Happy New Year

Filed under: emacs, General, life, Linux, open-source — skalyanasundaram @ 11:47 am

After the Mumbai trip, had a chance to go to home. Novell had announced a shutdown for four days.  Good for me, home food, sleep, TV, Movie  and sleep all the remaining time. Unfortunately Jan 1st is the working day. I planned to return and not to take leave and I need to take more leaves on this month itself.  But I decided not to spend the new year in the travel, so did a day time travel. But still I thought I am going be late for just few mins or seconds for the new year. I was sad but luckily I got down at banaglore at 11:55, people started firing crackers for the new year. I felt like my arrival is being celebrated at bangalore. 😉 hehe I should be happy. Had called up few of my friends and slept alone thats all.

Emacs: 
I do not want the ERC> prompt. It actually confuses, because every channel buffer has the same prompt. Either remove it and keep a simple “>” mark like rcirc or make like #emacs>,  #dns> depend on the channel name. This following code actually helps

(setq erc-prompt (lambda ()
(if (and (boundp ‘erc-default-recipients) (erc-default-target))
(erc-propertize (concat (erc-default-target) “>”) ‘read-only t ‘rear-nonsticky t ‘front-nonsticky t)
(erc-propertize (concat “>”) ‘read-only t ‘rear-nonsticky t ‘front-nonsticky t))))

May 21, 2007

Browsing net at emacs with w3m

Filed under: emacs, Linux, open-source, web — skalyanasundaram @ 3:38 am

I thought should try out w3m support at emacs. Ok it looks good but not up to the expectation.

See the search result of tajmahal. Ofcourse it looks better but it does not support the CSS which is almost used by all the web site nowadays. Javascript support is not available. I think there are some alpha packages which tries these things.

emacs-tajmahal-w3m

My wordpress blog. The columns which are in right hand side gone down. 😦

emacs-myblog-w3m

After using firefox and with its great addons support no one will think of using emacs for browsing.

Create a free website or blog at WordPress.com.