学习 Elisp - 阅读源代码的最高质量的库是什么?

发布于 2024-10-21 18:27:10 字数 435 浏览 4 评论 0原文

在学习一门新的编程语言时,“阅读源代码”是专家们收到的常见建议。然而,对于像 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

疯了 2024-10-28 18:27:10

正如Trey所说,使用Emacs本身的elisp来学习。我通常会做以下两件事之一:

1)如果我想了解如何使用特定函数,我会打开一个 dired 窗口并执行:

% g foobar

where foobar code> 是我有兴趣学习如何使用的函数的名称。这将标记所有使用 foobar 的文件,然后我会搜索它们以了解如何调用它,在什么上下文中调用它,等等。2

)如果我想弄清楚知道如何做某事,并且我知道一种可以做类似事情的模式,我会去查看该模式的源代码,看看他们是如何做到的。如果您不知道从哪里开始,但知道如何执行您想要做的事情,那么一个方便的做法是通过键绑定查找它。例如,在 dired 缓冲区中,执行以下操作:

C-h k % g

将显示:

% g runs the command dired-mark-files-containing-regexp, which is an
% interactive compiled Lisp function in `dired.el'.

It is bound to % g, <menu-bar> <regexp> <mark-cont>.
(dired-mark-files-containing-regexp regexp &optional marker-char)

Mark all files with contents containing regexp for use in later
commands. A prefix argument means to unmark them instead.
`.' and `..' are never marked.

单击上述文本中的 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:

% g foobar

where foobar is the name of the function I'm interested in learning how to use. That will mark all of the files that use foobar 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:

C-h k % g

and that will bring up:

% g runs the command dired-mark-files-containing-regexp, which is an
% interactive compiled Lisp function in `dired.el'.

It is bound to % g, <menu-bar> <regexp> <mark-cont>.
(dired-mark-files-containing-regexp regexp &optional marker-char)

Mark all files with contents containing regexp for use in later
commands. A prefix argument means to unmark them instead.
`.' and `..' are never marked.

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.

马蹄踏│碎落叶 2024-10-28 18:27:10

我推荐的源代码是 Emacs 本身的源代码。从简单的东西开始(双关语),然后按照您习惯的方式查看其他文件。

M-x find-library simple RET

我认为 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.

M-x find-library simple RET

I think it's self-explanatory as to why Emacs' own lisp code is a good example of Emacs lisp.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文