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):
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.
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.
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.)
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!
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:
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.
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.
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.
大多数情况下,我只是键入它们,但偶尔,我使用 M-( 和 M-) (特别是当我“在阶段后期”添加 LET 绑定时),以包含相关的 n 个表达式。
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.
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).
为了避免括号中的混乱,我在我的工具集中添加了一个名为 'highlight-parentheses 的包,并且为了最大限度地提高 sexp 抓取或一般文本导航的效率,我还使用 vimpulse(因为我是 Vim 瘾君子)。
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).
发布评论
评论(16)
我个人推荐 Emacs、SLIME & paredit.el
Paredit 允许您在 sexp 级别上伪语义地编辑 LISP 代码,这使得括号几乎完全消失。 您可以像简单的单词一样移动 sexp,甚至只需按几下按键即可改变它们。 还有一个名为 Redshank 的次要模式,它与 Paredit 结合使用,并提供更多的力量。
考虑一下这些简单的例子(| 是光标的位置):
我曾经做过一些认真的 Common Lisp 编程,事实证明 paredit 对我来说是无价的。 如果没有我的工具箱,我什至无法想象编写重要的 LISP 代码。 毕竟事情本来就该如此; 你永远不必计算或匹配你的括号...一旦你掌握了Paredit,括号就会从你眼前消失。
将 [] 重新映射到 () 会有所帮助,但在开始使用 Paredit 后您将不再关心。
请随意使用我的 dot-emacs 中的 LISP 特定部分 。
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):
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.
无论如何,在许多非美国键盘布局中,键入方括号或大括号比键入括号更麻烦,这使得大多数语言的编程都非常紧张,所以请认为自己很幸运。 ;)
对于我来说,我使用程序员友好的非标准键盘布局,让我可以通过 [Super]-j 和 [Super]-k 键入括号。
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.
我有脚踏板。 LeftFoot = 左括号,RightFoot = 右括号。
嗯,我不知道,但我不使用 Lisp。 不过,这似乎并不是一个坏主意。
你能想象 Lisp 的一个变体,使用缩进而不是括号吗? (摘自 Python 规范)
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)
我把手指从主页键上移开......
I take my fingers off the home keys....
我尝试在 Emacs 中重新映射,但它会产生新问题:假设您正在通过 ssh 在终端窗口中进行编辑,然后将代码片段粘贴到窗口中; 然后括号和方括号会在您的粘贴中被交换,而不仅仅是您的打字。 如果您尝试这样做,请在系统中的较低级别重新映射,例如 xmodmap。
(当然,另一个明显的问题是在没有重新映射的情况下使用其他计算机。这也很麻烦,尽管可以忍受。)
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.)
“...这么多括号”
我做的第一件事就是将 '(' 键绑定到序列 '('+')'+right(),这样我的括号就会自动平衡,在写入时留下一半的内容需要输入 您还需要
一种方便的方法来导航出一个括号 - 将 C-] 绑定到序列 search(')')+right()。 现在创作变得更短,因为您不需要将手从起始位置移开 - 每次完成 S-expr 时只需键入 C-] 即可。
我做的下一件事是将一个键绑定到一个子例程,该子例程将现有项目推送到当前列表...因此,如果 // 是光标位置,那么此命令将转换为:
有效
地将一项从右侧推送到当前列表-- 对于编辑现有代码非常有用。 序列 '(', '<', CS-], Space, '2' 将“比较小于 2”添加到现有表达式中。与 C-] 结合使用,您可以从现有表达式中快速构建新表达式。
@jamesnvc,
我没有考虑将 () 绑定到 [] 键...我必须尝试一下,谢谢!
"... 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:
to
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!
我用 xmodmap 将 [] 重新映射到 () 并喜欢它。 习惯用使用 [] 的语言编写代码有点奇怪,但就像任何改变一样,你会习惯它。 在 Lisp 中使用未移动的括号比在其他语言中没有未移动的括号更好,所以它是有效的。
无论如何,这是我的美国键盘必需的 xmodmap 咒语:
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:
我必须将手指从主行移开才能接触到所有其他班次操作员,所以我从来没有考虑太多。
一旦你输入了左括号,电动括号就会给你右括号。
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.
如果您使用括号的次数多于方括号,请务必重新映射。 我不明白这会带来什么比左撇子交换鼠标按钮更多的问题。
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.
当我编写代码时,我通常会花更多的时间思考和阅读代码,而不是打字。 我过去曾多次尝试切换到德沃夏克键盘布局,但我缺乏明显的动力,因为我的打字速度比我想象的要快得多。 编程语言语法是一个类似的问题 - 只要我可以在不离开键盘的情况下键入代码(即使用鼠标会很糟糕),我就很高兴。
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.
DrScheme 默认情况下翻转括号和方括号的击键。 它还有一个功能,可以神奇地猜测您指的是两者中的哪一个,因此您很少会使用shift-9。
Quack 具有与 DrScheme 类似的功能。
DivaScheme(我的编辑)是完全不同的东西。 它在 sexp 级别进行编辑,因此括号不再妨碍。
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.
大多数情况下,我只是键入它们,但偶尔,我使用 M-( 和 M-) (特别是当我“在阶段后期”添加 LET 绑定时),以包含相关的 n 个表达式。
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.
我还更改了我的(dvorak)键盘布局(通过 xmodmap)以切换括号(“[]”)和括号,与 paredit-mode 结合使用(这确实需要一些时间来适应)。
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).我使用 paredit 和pair-mode 软件包,但是,为了快速括号输入,我使用电动点划线来替换 () 中的双句号,延迟 5 毫秒(如果我打字缓慢,那么我会得到两个点)。 这是一个很棒的包(我根据个人喜好进行了一些修改;当我使用 Dvorak 键盘打字时,我用斜杠替换了破折号键(// 在 lisp 中并不常见))。
为了避免括号中的混乱,我在我的工具集中添加了一个名为 'highlight-parentheses 的包,并且为了最大限度地提高 sexp 抓取或一般文本导航的效率,我还使用 vimpulse(因为我是 Vim 瘾君子)。
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).
将大写锁定重新绑定到“(”,并让编辑器自动插入“)”。
(这对于其他带有大量括号的语言也有帮助,例如 HTML...)
Rebind capslock to "(" and have the editor autoinsert ")" for you.
(This also helps for other languages with a lot of brackets, for instance HTML...)
我将 Vim 与 vim-sexp 和 vim-sexp-mappings-for-regular-people 然后映射
u
将我置于新的(
.mapui(
I use Vim with vim-sexp and vim-sexp-mappings-for-regular-people then have mapped
<leader>u
to put me in normal mode inside of a new(
.map <leader>u i(