学习 Elisp - 阅读源代码的最高质量的库是什么?
在学习一门新的编程语言时,“阅读源代码”是专家们收到的常见建议。然而,对于像 emacs 这样一个由许多人数十年构建的庞大系统,初学者要弄清楚哪些库是惯用的 Elisp 编程的最佳示例并不容易。因此,我想得到一些关于以下标准的建议:
惯用的 elisp 编程风格
遵守 emacs 编程指南
根据 emacs 指南巧妙使用 cl-package
巧妙使用 eieio-package
单个 .el 文件库的示例性组织
多文件/多包库的示例性组织
您认为重要的任何标准
给出您推荐某些库用于自学学习的原因为什么对于 Emacs lisp 编程的初学者来说肯定会提供信息。
When learning a new programming language, "read source code" is a common advice received by the experts. However, with such a huge system like emacs, build over decades by many people, it is not so easy for the beginner to figure out which libraries are the best examples of idiomatic Elisp progamming. Therefore I would like to get some recommendations with regards to the following criteria:
idiomatic elisp programming style
adherence to emacs programming guidelines
clever use of the cl-package in accordance to emacs guidelines
clever use of eieio-package
exemplary organisation of a single .el file library
exemplary organisation of a multi-file/multi-package library
any criteria you consider important
Giving the reasons why you recommend certain libraries for auto-didactic studies would certainly be informative to beginners in Emacs lisp programming.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如Trey所说,使用Emacs本身的elisp来学习。我通常会做以下两件事之一:
1)如果我想了解如何使用特定函数,我会打开一个
dired
窗口并执行:where
foobar
code> 是我有兴趣学习如何使用的函数的名称。这将标记所有使用 foobar 的文件,然后我会搜索它们以了解如何调用它,在什么上下文中调用它,等等。2)如果我想弄清楚知道如何做某事,并且我知道一种可以做类似事情的模式,我会去查看该模式的源代码,看看他们是如何做到的。如果您不知道从哪里开始,但知道如何执行您想要做的事情,那么一个方便的做法是通过键绑定查找它。例如,在
dired
缓冲区中,执行以下操作:将显示:
单击上述文本中的
dired.el
(在 emacs 缓冲区中)将打开源代码并带您直接到达该函数定义。这是通过示例学习的好方法。不要忘记使用 elisp 调试器来准确了解正在发生的情况并跟踪代码的逐步执行。您可以使用 edebug-defun 标记代码进行调试,然后照常调用它,此时 emacs 将引导您完成代码。
As Trey said, use the elisp from Emacs itself to learn. I usually do one of two things:
1) If I'm trying to find out how to use a specific function, I'll bring up a
dired
window and do:where
foobar
is the name of the function I'm interested in learning how to use. That will mark all of the files that usefoobar
and then I go and search through them to see how to call it, in what context it's being called, etc.2) If I'm trying to figure out how to do something, and I know a mode that does something similar, I'll go look at that mode's source code to see how they do it. If you don't know where to start, but you know how to execute what it is you want to do, a handy thing to do is to look it up by key-binding. For example, in a
dired
buffer, do the following:and that will bring up:
Clicking on
dired.el
in the above text (in an emacs buffer) will open up the source code and take you right to that function definition. It's a great way to learn by example.Don't forget the elisp debugger as a way to see exactly what's going on and following along as the code executes step-by-step. You can mark the code for debugging using
edebug-defun
and then invoke it as usual, at which point emacs will step you through the code.我推荐的源代码是 Emacs 本身的源代码。从简单的东西开始(双关语),然后按照您习惯的方式查看其他文件。
我认为 Emacs 自己的 lisp 代码是 Emacs lisp 的一个很好的例子是不言而喻的。
The source code I'd recommend would be that of Emacs itself. Start off with the simple stuff (pun intended), and look at other files as you are wont.
I think it's self-explanatory as to why Emacs' own lisp code is a good example of Emacs lisp.