5 ms·
Practical Emacs Lisp
- Supraperplex 11y ago"Each page is self contained." Allright, I guess it's an Emacs site then.
- brudgers 11y agoT'wer we speaking of Python not Emacs, the "one true way" idiom would be deemed virtuous.
- dfan 11y agoInexperienced Emacs Lisp programmers coming to this site for the first time should be aware that Xah Lee's code is generally not very idiomatic. He discusses it himself here: http://ergoemacs.org/misc/emacs_lisp_coding_style_language_idioms_controversy.html http://ergoemacs.org/misc/emacs_lisp_coding_style_language_i...
- kazinator 11y agoI'm an experienced Lisp programmer and most of it looks fine to me from a random sampling, as far as formatting goes. Sometimes a closing parenthesis is on a line by itself: (defun foo () ... ) (let ((x y) (z w) ) ...) Historically, it's not been unheard of that Lisp experts (even implementors) do this sort of thing. Exhibit A, randomly picked source file inside CLISP: http://sourceforge.net/p/clisp/clisp/ci/default/tree/src/clos-class0.lisp http://sourceforge.net/p/clisp/clisp/ci/default/tree/src/clo... Some of Xah's indentation is inconsistent: (function (one space) indent like data) (function (two space indent) like code)) Not too much stands out otherwise; the code is readable. I'd have to read deeper to see whether things that are usually done one way are done differently for no good reason. What I would consider "unidiomatic" would be, for instance: (if (not (null list)) ...) rather than (if list ...) (Any Lisp dialect requiring code such the former is labelled differently, namely "idiotic".)
- PuercoPop 11y agoI perused a couple of links. This code [0] is pretty much unidiomatic. Closing parens one per line and using setq all over the place. [0]: http://ergoemacs.org/emacs/elisp_grep_string_inside_tag.html http://ergoemacs.org/emacs/elisp_grep_string_inside_tag.html
- kazinator 11y agoThat is pretty atrocious. All the initializing setq's could just be init forms in the let. Now you might think that this is also unidiomatic: (setq totalCnt (1+ totalCnt)) Turns out, though, that Elisp doesn't have modify macros, except in the CL compatibility package. What Xah is doing is the same as the accepted SO answer for incrementing a local variable: http://stackoverflow.com/questions/6858894/how-to-increment-local-variables-in-elisp http://stackoverflow.com/questions/6858894/how-to-increment-...
- PuercoPop 11y agoFirst I forgot to add I Xah Lee's ergo emacs was a valuable resource when learning Emacs. AFAIR it succintly explained emacs base abstractions. On the setq, I what I meant was iterating through setqs and while (and I seem to recall even catch/throw) as agumonkey mentioned. Then again, 'in my mind', idiomatic elisp uses cl-lib :D. so (cl-incf total-count) would be better. snakeCase is unidiomatic as well.
- agumonkey 11y agoUsing lisp to while/set... sigh. This is old age emacs lisp. We need more dash.el. Unfortunately we'd need a more stream/functional buffer API ? I was thinking of porting scheme regexp SRFI because it felt a better fit than re-search-*.
- PuercoPop 11y agoAs far as dash.el goes, I find lispm's critique of dash.el pretty convincing[0]. However a more profilic emacs coder fried of mine is undeterred and keeps using modern emacs lisp. I think much of the community does as well. [0]: https://www.reddit.com/r/lisp/comments/29ufoc/it_is_not_hard_to_read_lisp_code/cioznk5 https://www.reddit.com/r/lisp/comments/29ufoc/it_is_not_hard... About Scheme's regexp SRFI, have you seen rx.el? Not quite but I like it myself.
- deleted 11y ago[deleted]
- brudgers 11y agoI'd say that inexperienced Lisp programmers are likely to be classed as inexperienced based on far deeper issues than formatting. The sort of things that keep code from running correctly or at all. YMMV.
- iak8god 11y agoCan you recommend a tutorial that uses idiomatic Emacs Lisp and covers both "why" and "how" of Emacs Lisp at a level appropriate for someone who's used CL and Emacs a lot but has never noticed that he needs ELisp?
- blue1 11y agoI've also used CL and Emacs a lot; only very recently I've read both GNU Emacs Lisp manuals (introduction and reference). I think as a CL user in a couple of hours you can get an idea of what you can do, and more or less how.
- catern 11y agoThe manuals built in to Emacs are good, check M-x info.
- current_call 11y agowhy should we, spend the time to educate each other about formatting, and spend the thousands hours semi-manually do so perhaps with help of paredit, when we could have it to automatically and transparently? This is sort of funny coming from a guy who isn't using the shift key properly. Language conventions make communication easy. It's why $_ should be used. It's why "ain't" isn't a word and the subject comes before the verb.
- numbnuts 11y agoOP's link covers more topics but I prefer Steve Yegge's emergency elisp for quick and dirty things. http://steve-yegge.blogspot.com/2008/01/emergency-elisp.html http://steve-yegge.blogspot.com/2008/01/emergency-elisp.html
- deleted 11y ago[deleted]
- lispm 11y agoXah Lee can't program a line of Lisp on his own. Most of that code is collected from elsewhere. There are much better resources to learn Emacs Lisp from.
- eric_the_read 11y agoWhat are some good ones? I'd love to have something to suggest to the elisp-curious.
- catern 11y agoAn Introduction to Programming in Emacs Lisp is good, and is available both from inside emacs in M-x info, and on the web at https://www.gnu.org/software/emacs/manual/eintr.html https://www.gnu.org/software/emacs/manual/eintr.html
- packetslave 11y agoseems like an unnecessary personal attack
- lispm 11y agoIt's just the truth. I've seen him posting code for a long time. He has posted lots of bad advice, because he does not understand much Lisp programming and makes claims about all kinds of random stuff.
- sooheon 11y agoAs someone who comes across his writings once in a while I wish you would counter his bad advice with your good advice, rather than simply write that its bad.
- lispm 11y agoThat's a fulltime job. comp.lang.lisp did that several years. Just take from this discussion that his Lisp style is non-idiomatic and he writes in some primitive crappy imperative style. See my other example in this discussion.
- catern 11y agoI much prefer "An Introduction to Programming in Emacs Lisp", which is available both from inside emacs in M-x info, and on the web at https://www.gnu.org/software/emacs/manual/eintr.html https://www.gnu.org/software/emacs/manual/eintr.html