Posts tagged ‘hacks’

Emacs – select entire buffer macro

You can use the mark-whole-buffer. This is bound to C-x h by default.

March 15, 2008 at 12:00 am 1 comment

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 press C with your left hand. This approach seems to limit the degree to which you need to contort your fingers. (However, I have no experience with RSI, so perhaps you shouldn’t believe what I say)

Learning to use these new fingerings takes a little mental reprogramming.

If you are going to try to be religious about this, one problem that you will face is that a keyboard only has one alt key: the alt key on the right hand side of the keyboard normally being used to insert non-ascii characters. By rebinding this alt key to have a slightly more mundane meaning you can save yourself some contortion.

This rebinding can temporarily be done using the following shell commands.

xmodmap -e "keycode 113 = Alt_L"
# Make the left hand alt key (key 113) behave like a left handed alt.
xmodmap -e "clear mod5"
#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. .xmodmap will be executed by xmodmap when X starts.

<pre>
keycode 113 = Alt_L
clear mod5
</pre>

Notes

See “man xmodmap”.

If you love for your native language exceeds your loathing for hand contortion, you could try rebinding a different key to act as ‘mod5’. I might recommend using the windows (super) or 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 a registry key.

March 9, 2008 at 2:53 pm Leave a comment

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.

December 21, 2007 at 3:07 pm Leave a comment


June 2017
M T W T F S S
« Nov    
 1234
567891011
12131415161718
19202122232425
2627282930