views:

1850

answers:

16

I try to keep my fingers on home row as much as possible.

Typing all the parentheses makes me move away from there a fair bit.

I use Emacs; the parentheses themselves are no issue, I'm comfortable with them. And I don't like modes that type them for me automatically.

I've thought about remapping the square brackets to parentheses and vice versa. Is this a good idea? What does everyone else do?

+7  A: 

I take my fingers off the home keys....

cgreeno
I go one step further: I don't even use the home row.http://stackoverflow.com/questions/339048/do-you-use-the-home-row
Kyle Cronin
+0.5 for the humour, and +0.5 for the common sense approach: get used to it.
nickf
+1  A: 

If you use the parentheses more than the square brackets, by all means, remap away. I don't see how it could pose any more problems than, say, a lefty swapping her mouse buttons.

Adam Jaskiewicz
+7  A: 

With many non-US keyboard layouts, typing square brackets or braces is even more cumbersome than typing parentheses, anyway, which makes programming in most languages very strainful, so consider yourself lucky. ;)

As for me, I use a programmer-friendly non-standard keyboard layout that lets me type parentheses via [Super]-j and [Super]-k.

Matthias Benkard
What program do you use to create these mappings?
Kibbee
xkeycaps. It may seem a bit anachronistic, but it works. :)
Matthias Benkard
You can actually add an english layout to most mainstream OSes.
Adriano Varoli Piazza
We use an english keyboard layout. Or a custom one that maps the special symbols on the home row and right alt.
Roman Plášil
+4  A: 

I tried remapping in Emacs, but it creates new problems: say you're editing in a terminal window through ssh and you paste a snippet into the window; then parens and brackets get swapped in your pasting, not just your typing. If you try this, remap at a lower level in your system, like xmodmap.

(Of course, the obvious other problem is using other computers without your remapping. That was a nuisance too, though bearable.)

Darius Bacon
A: 

When I'm writing code, I generally spend much more time thinking and reading my code, than I do typing it. I've tried a couple of times in the past to switch to the Dvorak keyboard layout, but I lack obvious motivation because I can type much faster than I can think. Programming language syntax is a similar issue - as long as I can type code without leaving the keyboard (ie. using the mouse would be bad), I'm happy.

Greg Hewgill
+7  A: 

I have foot pedals. LeftFoot = open paren, RightFoot = close paren.

Well, I don't, but I don't use Lisp. It doesn't seem like a bad idea, though.

Could you imagine a variation on Lisp that used indentation instead of parens? (taking a page from the Python spec)

Jay Bazuzi
Ergh, I hate lexical whitespace! Although I reserve the right to change my opinion in the future....Since Lisp is fully-parenthesized notation, there can be (usually are) multiple parenthesized expressions on one line. dropping them separate, indented lines would be a nightmare!+ * 3 6 4
Michael Paulukonis
okay, that didn't work -- that's + /new line /tab * 3 6 /new line /tab 4...
Michael Paulukonis
Now, that _could_ work, it would just take up a lot more vertical space.And horizontal.
Michael Paulukonis
The issue is lack of glue words. Python has to have an else keyword, while brace syntax could use if{true}{false}. Thus, the issues are when a )( is struck
Demur Rumed
Python uses whitespace only for some things, but Lisp uses lists for almost everything. Would you like to use indentation to mark up array literals in Python? Indent all function arguments? ...
Rene Saarsoo
I heard this thing is already implemented in Scheme.
AnSGri
Why is this answer up-mod'd? It doesn't answer the question. "Q: how do you do X efficiently" "A: joke. admit ignorance. suggest something other than X". it's a bad answer.
Aaron
+2  A: 

I have to take my fingers off the home row to reach all the other shift-number operators, so I never thought about it much.

And once you type a left-parens, electric-parens give you the right.

Michael Paulukonis
+2  A: 

Thanks guys.

I may try paredit mode, see if I can get used to it.

Chris Poole
A: 

I also changed my (dvorak) keyboard layout (via xmodmap) to switch the brackets ("[]") and parens, in conjunction with paredit-mode (which does indeed take some getting used to).

jamesnvc
+3  A: 

I remapped [] to () with xmodmap and like it. It was a bit weird getting used to writing code in languages that use [], but like any change, you get used to it. Having unshifted parens in Lisp is nicer than not having unshifted brackets in other languages, so it works out.

Anyway, here is the necessary xmodmap incantation for my US keyboard:

!! swap () and []
keycode  18 = 9 bracketleft
keycode  19 = 0 bracketright
keycode  34 = parenleft braceleft
keycode  35 = parenright braceright
jrockway
+1  A: 

"... so many parenethesis"

The first thing I did was bind the '(' key to the sequence '('+')'+right(), so my parenthesis auto balance, leaving half as many left to type when writing new code.

You also want a convenient way to navigate out one paren -- bind C-] to the sequence search(')')+right(). Authoring becomes shorter now, as you don't need to take hands off the home position -- just type C-] every time you complete an S-expr.

Next thing I did was bind a key to a subroutine that pushes an existing item onto the current list ... so if // is the cursor position, then this command will transform:

(if (< //) (+ x 1) 
    (x) 
  (y))

to

(if (< (+ x 1) //)
    (x) 
  (y))

Effectively pushing one item from the right into the current list -- very useful for editing existing code. The sequence '(', '<', C-S-], Space, '2' adds "compare less than 2" to an existing expression. Combined with C-], this lets you build new expressions very quickly from existing ones.

@jamesnvc, I didn't think about binding () to [] keys... I'll have to try that, thx!

Aaron
You don't have to do all this yourself -- paredit already offers these functions (and more).
Florian Jenn
A: 

I use paredit and pair-mode packages but, for fast parenthesis typing I use electric-dot-and-dash to replace a double period in a () on a 5 ms delay (if I type slowly I get two dots then). It's a wonderful package (I hacked a bit for my personal preference; as I type with Dvorak keyboard, I replaced the dash key by a slash (// is not so common in lisp)).

To avoid the mess in parens, I add a package named 'highlight-parentheses to my tool set, and for maximum efficiency on sexp grabbings or text navigation in general, I also use vimpulse (as I am a Vim addict).

A: 

DrScheme has the keystrokes for parens and square braces flipped by default. It also has a feature where it magically guesses which one of the two you meant, so you rarely reach for shift-9.

Quack has a similar feature to that of DrScheme.

DivaScheme (my editor), is something completely different. It edits at the sexp level, so that the parens are no longer in the way.

Guillaume Marceau
A: 

Rebind capslock to "(" and have the editor autoinsert ")" for you.

(This also helps for other languages with a lot of brackets, for instance HTML...)

Ant P.
+12  A: 

I would personally recommend the lethal combo of Emacs, SLIME & paredit.el Paredit allows you to pseudo-semantically edit the LISP code at sexp level, and that makes the parentheses disappear almost completely. You can move around sexps as if they are simple words and even mutate them with just a couple of key-strokes. There is also a minor mode called Redshank which works in conjunction with Paredit and that provides more power.

Consider simple these examples (| is the position of the cursor):

(foo bar (baz| quux) zot) + C-( => (foo (bar baz| quux) zot)
(foo (bar |baz) quux zot) + C-) => (foo (bar |baz quux) zot)

(foo (bar baz |quux) zot) + C-{ => (foo bar (baz |quux) zot)
(foo (bar |baz quux) zot) + C-} => (foo (bar |baz) quux zot)

I have done some serious Common Lisp programming in my time, and paredit has proved to be invaluable to me. I can't even think of writing non-trivial LISP code without my toolbox. And after all that's the way it should be; you should never have to count or match your parentheses... once you master Paredit, the parentheses will just disappear from in front of your eyes.

Remapping the [] to () will help, but you will stop caring much after you start using Paredit.

Feel free to use the LISP specific portions from my dot-emacs - http://github.com/ghoseb

Baishampayan Ghose
+1  A: 

Mostly, I just type them, but occasionally, I use M-( and M-) (especially when I am adding a LET binding "late in the stage"), to enclose the relevant nnumber of expressions.

Vatine