Posts Tagged hacks
Emacs – select entire buffer macro
This is some emacs lisp code that makes -c a select the entire buffer. This is all terribly simple to do (if you spend a while looking at the documentation) – but I’d quite like to be able to cut and paste this without think. This has to pasted into your .emacs file to work.
(fset 'select-buffer [?\C-a ?\M-]) (global-set-key "^Ca" (quote select-buffer))
Of course, if you, unlike me, read documentation before deciding to impose your views upon people you might just use the mark-whole-buffer macro instead, which seems to be bound to C-x h by default.
1 comment March 15, 2008
How to not break your hands when using key combinations (using *nix)
I find that trying to use both hands when entering key combinations feels slightly less inclined to cause injury than using the same hand. For example, instead of pressing control-C with only your left hand, you hold the control button with your right hand and with you left hand press a control button. This approach seems to limit the degree to which you need to contort your fingers – however I’m not a doctor, so perhaps you shouldn’t believe what I say.
As one might expect, there is a slight hurdle to jump to retrain oneself to use a completely new set of keybindings, which just happen to be pressing the same keys.
Before one can set out on such a mission there are some problems with the alt key that need to be negotiated. The alt key on the right-hand side is used as a modifier to enter interesting characters.By rebinding it so as to behave like the alt key on the right hand-side, you can perform alt-containing key combinations with either hand.
This rebinding can be done for one session by typing the following commands into the shell:
xmodmap -e "keycode 113 = Alt_L" #This should make the left hand alt key (key 113) behave like a left handed alt. xmodmap -e "clear mod5" #This should stop any key (and particular key 113) from being used to insert non-latin characters.
To make this permament one needs to modify the .xmodmap file in one’s home directory – or create it should it not exist. The arguments to the -e options are then added to this file. .xmodmap should then be executed by xmodmap when X starts.
For the purpose of cutting and pasting, the new section added to one’s .xmodmap file looks like:
<pre>
keycode 113 = Alt_L
clear mod5
</pre>
Notes
See “man xmodmap” for more details on how it works.
If your love for bizarre characters exceeds you desire for possible less contorted hands, you could try rebinding a different key to act as ‘mod5′. I might recommend using the windows (super) and context menu keys for this.
You should be able to do this with the ‘add’ command – though not that this takes keysyms rather than keycodes as arguments. (This will, hopefully, make sense after consulting the manual).
On windows one can use the freeware program Sharpkeys to carry out this change. This works by setting changing an appropriate registry key.
Add comment March 9, 2008
Switches should include all cases
It would probably be useful if all switch statements contained labels corresponding to every possible value of the switched variable rather than using the default case to pick up all the missing cases.
This means you end up writing code like this:
switch(var)
{
case ONE:
...case UNHANDLED1:
case UNHANDLED2:
case UNHANDLED2:
default:
... ((deal with default case))
}
The advantage to this approach is that a reader can tell when a case has been unintentionally left out or not yet implemented at a glance. Also, as a side effect, when programming in this manner one is less likely to forget about cases – since one is listing all case.
This is an example of a more general idea of programming so as to make one’s intent clear… you just have to bear in mind that making one’s intent clear is secondary to making something that works.
Add comment December 21, 2007