如何有效地输入lisp,括号如此之多?

时间:2022-11-22 20:13:53

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.

我用Emacs;括号本身没问题,我对它们很满意。而且我不喜欢自动为我输入的模式。

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

我想过将方括号重新映射到圆括号,反之亦然。这是一个好主意吗?其他人都做了什么?

16 个解决方案

#1


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.

我个人推荐Emacs,SLIME和paredit.el的致命组合Paredit允许你在sexp级别伪语义编辑LISP代码,这使得括号几乎完全消失。你可以移动sexps,好像它们是简单的单词,甚至可以用几个键击来改变它们。还有一种名为Redshank的小模式,它与Paredit一起工作,提供更多动力。

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.

我在我的时间里做了一些严肃的Common Lisp编程,事实证明paredit对我来说非常宝贵。如果没有我的工具箱,我甚至无法想到编写非平凡的LISP代码。毕竟这是应该的方式;你永远不必计算或匹配你的括号......一旦你掌握了Paredit,括号就会从你眼前消失。

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

将[]重新映射到()会有所帮助,但在开始使用Paredit后,您将停止关注。

Feel free to use the LISP specific portions from my dot-emacs.

随意使用我的dot-emacs中的LISP特定部分。

#2


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.

至于我,我使用程序员友好的非标准键盘布局,让我通过[超级] -j和[超级] -k键入括号。

#3


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

我有脚踏板。 LeftFoot =打开paren,RightFoot =关闭paren。

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

好吧,我没有,但我不使用Lisp。不过,这似乎不是一个坏主意。

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

你能想象使用缩进而不是parens的Lisp变体吗? (从Python规范中获取页面)

#4


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

我把手指从家里的钥匙上移开......

#5


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.

我尝试重新映射到Emacs,但它会产生新的问题:假设您正在通过ssh在终端窗口中进行编辑,并将一个片段粘贴到窗口中;然后parens和括号在你的粘贴中交换,而不仅仅是你的打字。如果您尝试此操作,请在系统中的较低级别重新映射,例如xmodmap。

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

(当然,显而易见的另一个问题是在没有重新映射的情况下使用其他计算机。这也是一件令人讨厌的事情,虽然可以忍受。)

#6


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.

我用xmodmap重新映射[]到()并且喜欢它。习惯于在使用[]的语言中编写代码有点奇怪,但是就像任何改变一样,你会习惯它。在Lisp中使用未移位的parens比在其他语言中没有未移位的括号更好,所以它可以解决。

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

无论如何,这是我的美国键盘必需的xmodmap咒语:

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

#7


"... so many parenethesis"

“......这么多的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.

我做的第一件事是将'('键连接到序列'('+')'+ right(),所以我的括号自动平衡,在编写新代码时留下一半的数量。

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.

您还需要一种方便的方法来导出一个paren - bind C-]到序列搜索(')')+ right()。现在,创作变短了,因为每次完成S-expr时,您都不需要离开原位 - 只需键入C-。

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.

有效地将一个项目从右侧推送到当前列表 - 对编辑现有代码非常有用。序列'(','<',C-S-],Space,'2'将“比较小于2”添加到现有表达式。结合C-],这使您可以从现有表达式中快速构建新表达式。

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

@jamesnvc,我没想到绑定()到[]键......我必须尝试一下,谢谢!

#8


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.

一旦你输入一个左边的parens,电子parens给你正确的权利。

#9


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.

如果您使用括号超过方括号,则无论如何都要重新映射。我不知道它是如何造成任何问题的,比如,左右交换鼠标按钮。

#10


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.

当我编写代码时,我通常会花更多的时间思考和阅读我的代码,而不是输入代码。我过去曾尝试过几次切换到Dvorak键盘布局,但我缺乏明显的动机,因为我的打字速度比我想象的要快得多。编程语言语法是一个类似的问题 - 只要我可以在不离开键盘的情况下键入代码(即使用鼠标会很糟糕),我很高兴。

#11


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.

大多数情况下,我只是键入它们,但有时候,我使用M-(和M-)(特别是当我在“舞台后期”添加LET绑定时),以包含相关的数字表达式。

#12


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).

我还改变了我的(dvorak)键盘布局(通过xmodmap)来切换括号(“[]”)和parens,以及paredit-mode(这确实需要一些人习惯)。

#13


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)).

我使用了paredit和pair-mode包,但是,对于快速括号输入,我使用电子点划线来代替a()中的双周期,延迟5 ms(如果我慢慢输入,那么我得到两个点)。这是一个很棒的包(我为了个人喜好而黑了一点;当我用Dvorak键盘输入时,我用斜线替换了短划线键(//在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).

为了避免麻烦,我将一个名为'highlight-parentheses的包添加到我的工具集中,并且为了最大限度地提高sexp抓取或文本导航的效率,我也使用vimpulse(因为我是Vim上瘾者)。

#14


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.

DrScheme默认情况下可以翻转parens和方括号的按键。它还有一个功能,它可以神奇地猜测你的意思中的哪一个,所以你很少达到shift-9。

Quack has a similar feature to that of DrScheme.

Quack与DrScheme的功能类似。

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

DivaScheme(我的编辑),完全不同。它在sexp级编辑,因此parens不再妨碍。

#15


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

将*重新绑定到“(”并让编辑器自动插入“)”为您。

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

(这也有助于其他语言有很多括号,例如HTML ......)

#16


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 (.

我使用Vim与vim-sexp和vim-sexp-mappings-for-regular-people然后映射 u让我进入正常模式的新内容(。

map <leader>u i(

地图 u i(

#1


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.

我个人推荐Emacs,SLIME和paredit.el的致命组合Paredit允许你在sexp级别伪语义编辑LISP代码,这使得括号几乎完全消失。你可以移动sexps,好像它们是简单的单词,甚至可以用几个键击来改变它们。还有一种名为Redshank的小模式,它与Paredit一起工作,提供更多动力。

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.

我在我的时间里做了一些严肃的Common Lisp编程,事实证明paredit对我来说非常宝贵。如果没有我的工具箱,我甚至无法想到编写非平凡的LISP代码。毕竟这是应该的方式;你永远不必计算或匹配你的括号......一旦你掌握了Paredit,括号就会从你眼前消失。

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

将[]重新映射到()会有所帮助,但在开始使用Paredit后,您将停止关注。

Feel free to use the LISP specific portions from my dot-emacs.

随意使用我的dot-emacs中的LISP特定部分。

#2


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.

至于我,我使用程序员友好的非标准键盘布局,让我通过[超级] -j和[超级] -k键入括号。

#3


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

我有脚踏板。 LeftFoot =打开paren,RightFoot =关闭paren。

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

好吧,我没有,但我不使用Lisp。不过,这似乎不是一个坏主意。

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

你能想象使用缩进而不是parens的Lisp变体吗? (从Python规范中获取页面)

#4


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

我把手指从家里的钥匙上移开......

#5


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.

我尝试重新映射到Emacs,但它会产生新的问题:假设您正在通过ssh在终端窗口中进行编辑,并将一个片段粘贴到窗口中;然后parens和括号在你的粘贴中交换,而不仅仅是你的打字。如果您尝试此操作,请在系统中的较低级别重新映射,例如xmodmap。

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

(当然,显而易见的另一个问题是在没有重新映射的情况下使用其他计算机。这也是一件令人讨厌的事情,虽然可以忍受。)

#6


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.

我用xmodmap重新映射[]到()并且喜欢它。习惯于在使用[]的语言中编写代码有点奇怪,但是就像任何改变一样,你会习惯它。在Lisp中使用未移位的parens比在其他语言中没有未移位的括号更好,所以它可以解决。

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

无论如何,这是我的美国键盘必需的xmodmap咒语:

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

#7


"... so many parenethesis"

“......这么多的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.

我做的第一件事是将'('键连接到序列'('+')'+ right(),所以我的括号自动平衡,在编写新代码时留下一半的数量。

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.

您还需要一种方便的方法来导出一个paren - bind C-]到序列搜索(')')+ right()。现在,创作变短了,因为每次完成S-expr时,您都不需要离开原位 - 只需键入C-。

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.

有效地将一个项目从右侧推送到当前列表 - 对编辑现有代码非常有用。序列'(','<',C-S-],Space,'2'将“比较小于2”添加到现有表达式。结合C-],这使您可以从现有表达式中快速构建新表达式。

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

@jamesnvc,我没想到绑定()到[]键......我必须尝试一下,谢谢!

#8


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.

一旦你输入一个左边的parens,电子parens给你正确的权利。

#9


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.

如果您使用括号超过方括号,则无论如何都要重新映射。我不知道它是如何造成任何问题的,比如,左右交换鼠标按钮。

#10


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.

当我编写代码时,我通常会花更多的时间思考和阅读我的代码,而不是输入代码。我过去曾尝试过几次切换到Dvorak键盘布局,但我缺乏明显的动机,因为我的打字速度比我想象的要快得多。编程语言语法是一个类似的问题 - 只要我可以在不离开键盘的情况下键入代码(即使用鼠标会很糟糕),我很高兴。

#11


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.

大多数情况下,我只是键入它们,但有时候,我使用M-(和M-)(特别是当我在“舞台后期”添加LET绑定时),以包含相关的数字表达式。

#12


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).

我还改变了我的(dvorak)键盘布局(通过xmodmap)来切换括号(“[]”)和parens,以及paredit-mode(这确实需要一些人习惯)。

#13


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)).

我使用了paredit和pair-mode包,但是,对于快速括号输入,我使用电子点划线来代替a()中的双周期,延迟5 ms(如果我慢慢输入,那么我得到两个点)。这是一个很棒的包(我为了个人喜好而黑了一点;当我用Dvorak键盘输入时,我用斜线替换了短划线键(//在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).

为了避免麻烦,我将一个名为'highlight-parentheses的包添加到我的工具集中,并且为了最大限度地提高sexp抓取或文本导航的效率,我也使用vimpulse(因为我是Vim上瘾者)。

#14


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.

DrScheme默认情况下可以翻转parens和方括号的按键。它还有一个功能,它可以神奇地猜测你的意思中的哪一个,所以你很少达到shift-9。

Quack has a similar feature to that of DrScheme.

Quack与DrScheme的功能类似。

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

DivaScheme(我的编辑),完全不同。它在sexp级编辑,因此parens不再妨碍。

#15


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

将*重新绑定到“(”并让编辑器自动插入“)”为您。

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

(这也有助于其他语言有很多括号,例如HTML ......)

#16


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 (.

我使用Vim与vim-sexp和vim-sexp-mappings-for-regular-people然后映射 u让我进入正常模式的新内容(。

map <leader>u i(

地图 u i(