如何用paredit中已经写好的外部表单来包装表单

时间:2013-09-23 19:07:20

标签: emacs lisp paredit

假设我有这段代码

(hello world)
(hi world)

然后我想到我应该用以下形式包装它:

(let (acc)
  <>
  (nreverse acc))

产生此代码:

(let (acc)
  (hello world)
  (hi world)
  (nreverse acc))

以下是我通常如何进行包装。首先,我在这样的待包装形式之前写一个不完整的外形:

(let (acc))
(hello world)
(hi world)

然后我按两次C-)paredit-forward-slurp-sexp)来捏造事物:

(let (acc)
  (hello world)
  (hi world))

然后我最后在最后添加(nreverse acc)

现在我想知道如果我首先编写这样的完整外部表单模板会是什么?

(let (acc)
  (nreverse acc))
(hello world)
(hi world)

或者像这样

(hello world)
(hi world)
(let (acc)
  (nreverse acc))

是否有一小段paredit或非paredit命令,我可以按此命令从那开始完成工作?

我可以移动点,剪切两个待包装的表格,移动点,粘贴表格。但我想知道是否有更方便的方式。

我对如何进行包装感到满意,但感觉我可能会错过一些其他整齐的编辑技巧,这些技巧可以从不同的开始找到。

2 个答案:

答案 0 :(得分:7)

不是重复使用paredit-forward-slurp-sexp或杀死该区域,您可以将性别区域标记为封闭并使用paredit-wrap-round M - (

如果我输入你的例子,我会从最后一个表达开始:

(hello world)
(hi world)
(nreverse acc)_

C-SPC CMa CMa CMa M - (产量:< / p>

(_(hello world)
  (hi world)
  (nreverse acc))

插入let (acc)并以 RET C-M-h TAB 结束以重新识别。

可能有一种更好的方法=),但即使你不使用transient-mark-mode,你也可以提供其他包装选项:

  • C-u 换行到缓冲区或封闭列表的末尾
  • C-u#包装以下#个词组

请参阅paredit-wrap-sexp

的文档字符串

答案 1 :(得分:1)

你可能还想看看redshank,一个emacs包,可以做很多有用的事情。与paredit非常合作。