Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Learning Elisp - what are the highest quality libraries to read source code?

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.

like image 794
Thorsten Avatar asked Mar 12 '11 15:03

Thorsten


2 Answers

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.

like image 149
Joe Casadonte Avatar answered Nov 01 '22 01:11

Joe Casadonte


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.

like image 20
Trey Jackson Avatar answered Nov 01 '22 00:11

Trey Jackson