从Emacs生成代码

Yoo*_*Yoo 4 emacs code-generation

如何在emacs中快速编写以下代码?

\newcommand{\cA}{\mathcal A}
\newcommand{\cB}{\mathcal B}
\newcommand{\cC}{\mathcal C}
...
...
\newcommand{\cY}{\mathcal Y}
\newcommand{\cZ}{\mathcal Z}
Run Code Online (Sandbox Code Playgroud)

有没有比写作更快的方法

A
B
C
D
.
.
.
Y
Z
Run Code Online (Sandbox Code Playgroud)

然后在每一行做宏?(将A更改为\newcommand {\ cA} {\ mathcal A})

HD.*_*HD. 7

我同意键盘宏会以最快的速度获得结果.

更有趣的是程序化方法:

(loop 
      for n from (string-to-char "A") to (string-to-char "Z")
      for c = (char-to-string n)
      do (insert (concat "\\newcommand{\\c" c "}{\\mathcal " c "}\n")))
Run Code Online (Sandbox Code Playgroud)


use*_*568 5

一般来说,当你第一次遇到这种问题时,你会使用键盘宏,就像JB已经说过的那样.

第二次,查看Steve Yegge撰写的这篇非常有趣的文章:http://steve-yegge.blogspot.com/2006/06/shiny-and-new-emacs-22.html ,其中包含完全像问题的解决方案你的.

为了您的方便和我自己的照明,我实际上继续进行测试:

我会先说

A
...
A

26次

做一个

Mx replace-regexp

A
\\newcommand{\\c\,(string (+ ?A \#))}{\\mathcal \,(string (+ ?A \#))}