12

I'm trying to get familiar with Emacs Lisp, its syntax, data structures etc, so I was wondering what are some built-in packages whose source could help me better understand how to use the language and learn its idioms?

caisah
  • 4,056
  • 1
  • 23
  • 43
  • 1
    Be aware that the built-in packages are full of legacy code and therefore less suitable for learning idioms. Have you considered using external packages and libraries instead? – wasamasa Sep 24 '14 at 09:27
  • 1
    Have you considered using the emacs tutorial (available as `info` file ? Some built-in functions are explained and detailed. – kiddouk Sep 24 '14 at 09:48
  • @wasamasa I see, I will look at more recent packages. – caisah Sep 24 '14 at 11:14
  • @kiddouk Yes I did but I can't cope with the writing/explaining style. – caisah Sep 24 '14 at 11:15

2 Answers2

12

I can recommend Ruby Mode in ruby-mode.el and Python Mode in python.el, for some aspects of their implementation. The former is a particularly great source for advanced indentation and navigation code based on the new SMIE engine. However, neither uses data structures in any particularly clever or advanced way.

I would also recommend some parts of Org Mode 8, for its design. Notably the exporter framework of Org 8 shows how to create an generic, extensible, object-like framework in plain Emacs Lisp. However, I'd recommend against most other parts of Org, for reasons already stated in comments: It's old, and full of legacy and harmful practices (e.g. find-file-noselect to read files non-interactively).

Gnus is also said to have good code, but again I'd be careful to determine how well-maintained the particular piece of code is that you are looking at.

Since Emacs itself is very old, and only superficially maintained in many places, the average quality of its code is actually rather low by modern standards. There's many legacy stuff in there. For instance, even in core parts such as the byte compiler you'll find “TODO”s and “DUNNO”s dating back years, if not decades. Also, since Emacs is very slow to take code and developers from the “outside” community due to the restrictive policies established by the FSF, the overall quality increases only slowly.

All in all, you are more likely to find good code in popular 3rd party packages maintained by high-profile community members, e.g. Magit, Projectile, etc.

Dmitry
  • 3,508
  • 15
  • 20
  • Does `ruby-mode.el` use SMIE? I couldn't find it. – shosti Sep 24 '14 at 15:34
  • 2
    Oh I see, they changed it for the latest trunk. – shosti Sep 24 '14 at 15:38
  • 3
    Those planning on taking a dive into gnus' code: Please do take care. Those are deep waters and we wouldn't want to loose anyone. – Malabarba Sep 25 '14 at 13:27
  • 2
    If you look at Magit then I recommend looking at its next branch. – tarsius Sep 25 '14 at 13:38
  • 2
    Do you have *anything* to backup your last claim? I would strongly expect the opposite... – rasmus Nov 19 '14 at 23:32
  • @rasmus What claim specifically? –  Nov 19 '14 at 23:40
  • 1
    What I had in mind was: "[...] Emacs is [...] superficially maintained in many places, the **average** quality of its code is actually rather low" versus "you are more likely to find good code in popular 3rd party packages". But "Emacs is very slow to take code and developers from the “outside”" also seems like nonsense IMO (do you read the `debbugs`?)... – rasmus Nov 20 '14 at 00:42
  • 1
    @rasmus Read the sources of older libraries in Emacs, e.g. Flymake, Hippie Expand, etc. Their code isn't good, by modern standards. Of course, there are good libraries in Emacs, too, but that's why a spoke about the *average* quality: There are many good pieces of Emacs Lisp code in Emacs, but you need to know where to look. –  Nov 20 '14 at 18:36
  • 1
    @rasmus As for the other claim, it's simply a natural consequence of the barriers Emacs' puts in front of external contributions (e.g. the procedure to send patches, and notably copyright assignments). Debbugs is just the bug tracker, and just because you send something to debbugs it doesn't mean that it actually ever ends up in Emacs itself. Also, many bugs are left open because Emacs already has too few developers for too many issues. –  Nov 20 '14 at 18:38
1

For basic idioms look into simple.el

mpontus
  • 409
  • 3
  • 8