[HN Gopher] My Emacs Lisp book is finished
       ___________________________________________________________________
        
       My Emacs Lisp book is finished
        
       Author : greenSunglass
       Score  : 381 points
       Date   : 2021-11-09 04:49 UTC (18 hours ago)
        
 (HTM) web link (mbork.pl)
 (TXT) w3m dump (mbork.pl)
        
       | mrspeaker wrote:
       | I think this book would be perfect for me - I have been using
       | Emacs for quite a while, but never mastered elisp: I could never
       | figure out how to structure things properly.
       | 
       | Looking at the book landing page, I think I would have passed on
       | it because the Table of Contents make it look a bit like the book
       | is just covering _specific_ tasks (about rearranging sentences)
       | rather than general tasks, like using best practices for creating
       | packages.
       | 
       | It would be good to include the paragraph from your blog in the
       | book landing page:                   In the first chapter, it
       | tells you basically how to find Elisp functions doing things you
       | need.         In the second, longest chapter, it walks you
       | through writing a complete, useful package, showcasing lots of
       | Elisp features and good practices.         In the third, last
       | chapter, it hints at a few more advanced techniques - functional
       | programming, lexical scoping and regular expressions.
       | 
       | This made me a lot more excited about the contents!
        
         | ljm wrote:
         | I would love a dead tree version too. I've never managed to get
         | on well with ebooks and PDFs.
        
         | bjarneh wrote:
         | > I have been using Emacs for quite a while, but never mastered
         | elisp
         | 
         | You are not alone in that boat :-)
        
           | rvdginste wrote:
           | As a developer, I find it a bit embarassing that I started
           | using Emacs in 2000, that at some point I even read my email
           | with it, and that I never took the time to really learn
           | emacs-lisp. Still, some day I will. This book might help me.
           | :)
        
             | bloopernova wrote:
             | I'm just a devops person, not a coder by any stretch of the
             | imagination, but I found that maintaining my .init.el in
             | git helped me to learn enough elisp to be useful/dangerous.
             | 
             | I really dig that it's a full on language used for the
             | configuration files. It just makes so much _sense_ to do it
             | that way. (I also like VSCode 's json prefs)
             | 
             | Also I love sharing snippets of my .init.el:
             | 40   | ;; Taken from https://karl-voit.at/2017/02/11/my-
             | system-is-foobar/       41   | ;; Check if system is
             | Darwin/macOS       42   | (defun my-system-type-is-darwin
             | ()       43   |   "Return non-nil if system is darwin-based
             | (Mac OS X)."       44   |   (string-equal system-type
             | "darwin")       45   |   )       ...       65   |        66
             | | (when (my-system-type-is-darwin)       67   |   ;;
             | EXAMPLE: (global-set-key (kbd "C-z") 'shell)       68   |
             | ;; https://www.gnu.org/software/emacs/manual/html_node/emac
             | s/Init-Rebinding.html#Init-Rebinding       69   |
             | (global-set-key (kbd "s-/") 'comment-or-uncomment-region-
             | or-line)       70   |   (global-set-key (kbd
             | "s-<backspace>") '(lambda () (interactive) (kill-line 0)))
             | 71   |   )
        
               | jolux wrote:
               | system-type is actually a symbol, so you can do (eq
               | system-type 'darwin) for the same effect. here's my macOS
               | section: https://github.com/bklebe/.emacs.d/blob/b0ca2550
               | 32d1240942ff...
        
               | bloopernova wrote:
               | Nice! I'll definitely take a close look at that.
        
               | TacticalCoder wrote:
               | > I found that maintaining my .init.el in git helped me
               | to learn enough elisp to be useful/dangerous.
               | 
               | The snippets you gave of your _init.el_ are really basic
               | but I do agree with you: working on _init.el_ (and using
               | Git to revert SNAFUs) helped me learn enough elisp to be
               | dangerous too.
               | 
               | The elisp I write is certainly not idiomatic but it gets
               | the job done. I have some functions I wrote more than a
               | decade ago and they still "Just Work [TM]"!
        
               | [deleted]
        
             | bjarneh wrote:
             | > Still, some day I will
             | 
             | I said I'd lean Spanish some_day(r) as well, according to
             | duolingo that was 9 years ago :-)
        
               | rvdginste wrote:
               | Uh... well, it would be even more embarassing to admit
               | how long I've been telling myself that I'd start learning
               | emacs-lisp in earnest... so I won't. :)
        
       | ashton314 wrote:
       | This is very exciting and I will definitely be looking into this
       | when I have a little more time! I've tried writing my own Emacs
       | packages before, and I have never felt like I knew what I was
       | doing. A guided tutorial like this is filling an important hole
       | in the Emacs documentation I feel.
       | 
       | Also, I love the Brandon Sanderson quote. Absolutely excellent
       | epic fantasy.
        
       | deworms wrote:
       | Elisp is a really poor language compared to almost anything else,
       | more work should be done to allow Emacs to be configured in other
       | languages.
        
         | nonameisfinetoo wrote:
         | Dude, I think you might have a problem
        
         | shidima wrote:
         | Maybe if you would elaborate on why you think that, you would
         | not be down voted so much. Having said that, if you don't like
         | it maybe you should find an editor that suits you more?
        
           | Koshkin wrote:
           | To be fair, the parent is not talking about the editor but
           | rather its configuration language. Indeed, there have been
           | attempts to replace elisp with other languages, such as
           | Scheme (guile) and Common Lisp.
        
             | mindcrime wrote:
             | There is apparently a Guile enabled version of Emacs
             | available.
             | 
             | https://www.emacswiki.org/emacs/GuileEmacs
             | 
             | https://www.emacswiki.org/emacs/GuileEmacsBuild
        
         | klibertp wrote:
         | > Elisp is a really poor language compared to almost anything
         | else
         | 
         | What makes Elisp a "poor language" in your opinion?
         | 
         | Elisp is actually a really good language. Especially compared
         | to other languages used for scripting, like Lua or JS. In some
         | areas Elisp is _significantly more advanced_ than either:
         | pattern matching (pcase, dash), object orientation
         | (multimethods, multiple inheritance), iteration (loop), data
         | types (Lua has 3, JS a bit more, while Elisp gives you lists
         | (pairs, proplists, assoc lists, trees), vectors, maps, unicode
         | strings with optional metadata, queues, rings, and more. While
         | the lack of reader macros is unfortunate, the macro system
         | along with hooks and advice allow for writing libraries that
         | integrate seamlessly into the environment, and ones that
         | cleanly hide a lot of complexity (ie. use-package).
         | Additionally, Elisp performance is not very bad (though of
         | course worse than JITed languages) and it got AOT native
         | compiler recently, which should help improve upon it.
         | 
         | Namespaces are the only lacking feature at this point. I mean,
         | there are lots of places where Elisp could and should be
         | improved, but it's in quite good shape already. Definitely not
         | "really poor", especially compared to the other scripting
         | languages.
        
         | bloopernova wrote:
         | Can you give some reasons why you dislike Elisp?
         | 
         | What language would you re-write Emacs configurations in?
        
           | mcguire wrote:
           | I believe your second question needs to be rephrased as "What
           | language would you re-write Emacs in?"
           | 
           | I don't remember what the core to elisp fraction is, but it's
           | not that big.
        
             | Jtsummers wrote:
             | Emacs is written in C and Emacs Lisp. I'm not able to
             | download the source right now, but from some googling the C
             | portion is around 20-25%. So 75-80% lisp. That's a rather
             | substantial amount of code that would need to be rewritten,
             | not to mention that probably does not include all the lisp
             | code that's not included in the core distribution. Tons of
             | packages out there that would need to be rewritten.
        
         | NeutralForest wrote:
         | Emacs and Elisp are too intertwined at this point. This
         | interview https://www.youtube.com/watch?v=LKegZI9vWUU of the
         | creator of Doom Emacs talks about this exact problem.
        
       | 098799 wrote:
       | Thanks for the submission. I was hoping it would be finished and
       | didn't want to purchase an incomplete book, so it's helpful.
        
       | taeric wrote:
       | I've been happily reading the updates as they were released. Fell
       | behind on the last one, actually. Very fun book that I think
       | shines for showing some fun of using emacs. Highly recommended!
        
       | okletsb wrote:
       | Your website is not responsive
        
       | rnkn wrote:
       | But did you write it in Emacs, using Texinfo? ;)
        
         | marviio wrote:
         | I would bet it was written in orgmode.
        
           | sokoloff wrote:
           | Intro of the book confirms: "It is written in Org-mode, first
           | made by Carsten Dominik and then developed by many other
           | people. Diego Zamboni wrote the Org exporter to convert Org-
           | mode syntax to Markua, expected by Leanpub."
        
             | codetrotter wrote:
             | For anyone else curious about Markua:
             | https://leanpub.com/markua/read
        
       | Abhinav2000 wrote:
       | Eh is the book GPL though :-/ Can somebody confirm
        
       | signa11 wrote:
       | i have used "Writing GNU Emacs Extensions" available here:
       | https://www.oreilly.com/library/view/writing-gnu-emacs/97814...
       | from a long time past for elisp programming.
       | 
       | mentioning it here in the hope that it is is useful to others as
       | well...
        
         | xrd wrote:
         | I've still got my physical copy and will never get rid of it.
        
         | rvdginste wrote:
         | Since that book is over 20 years old, is it still relevant and
         | useful?
        
           | jhbadger wrote:
           | Pretty much, yes. I'm sure there's a few things that have
           | changed, and a newer book is welcome, but Emacs hasn't really
           | changed much in 30 years.
        
             | ragnese wrote:
             | I don't know my Emacs timeline very well, but I'd be
             | nervous about lexical scope and the more recent cooperative
             | async features of Emacs (lisp) not being represented in a
             | 20 year old book.
             | 
             | EDIT: Yeah, Emacs 24 had support for lexical scope, and
             | that was in 2012. You'd be doing a disservice to yourself,
             | IMO, to write dynamically scoped Elisp today, unless you
             | had a specific reason. And if you don't even KNOW that
             | lexical scoping is an option, it would be unfortunate.
        
               | draven wrote:
               | I checked the book's TOC and was surprised to see that
               | lexical scoping was introduced in the last chapter.
               | 
               | https://github.com/alphapapa/emacs-package-dev-
               | handbook#lexi... says using lexical scoping is a best
               | practice.
        
           | klibertp wrote:
           | Yes.
           | 
           | Emacs takes backwards compatibility seriously. Not kernel-
           | level seriously, but seriously.
           | 
           | Moreover, a book written 20 years ago was still written more
           | than 20 years after initial Emacs release. By then, a lot of
           | best practices were already discovered and they remain common
           | in Elisp code to this day.
           | 
           | There _was_ a lot of development in that time and many things
           | became easier to do, but the basics of writing Elisp programs
           | didn 't change.
           | 
           | IMO the book is especially worth a read if you want to change
           | your perspective: it does a really good job at showing that
           | Emacs is, in essence, a runtime environment and a development
           | platform akin to web browsers, with a huge stdlib of
           | libraries and applications, and focused on mostly-text
           | display. Next time you find yourself reaching for ncurses,
           | stop and go for Elisp instead. You'll get the (optional) GUI
           | and sane defaults for free, along with rich text editing
           | functionality where needed.
        
             | rvdginste wrote:
             | Ok, thanks, good to know.
        
       | saint_angels wrote:
       | as author calls it "intermediate-level book", what would be a
       | more suitable resource for an elisp beginner?
        
         | gauchojs wrote:
         | I'm on mobile but check the sample, the author mentions an
         | introductory resource.
        
         | phyrex wrote:
         | https://www.gnu.org/software/emacs/manual/html_node/eintr/in...
        
           | saint_angels wrote:
           | thanks! I thought whole gnu manual is a dry reference, but
           | linked intro looks exactly what I was looking for! https://ww
           | w.gnu.org/software/emacs/manual/html_node/eintr/Wh...
        
         | praptak wrote:
         | "Emergency Elisp" by Steve Yegge.
        
       | kangaroopouch wrote:
       | Great to see resources being created for Emacs.
       | 
       | How does this compare to
       | https://www.gnu.org/software/emacs/manual/html_node/elisp/in... ?
       | That's a great manual and available in Info format (popular
       | amongst Emacs users).
        
         | kangaroopouch wrote:
         | Ah it sits between the intro (
         | https://www.gnu.org/software/emacs/manual/html_mono/eintr.ht...
         | ) and the reference manual.
        
       | xrd wrote:
       | I enjoyed reading the O'Reilly "Writing Emacs Extensions" book
       | years ago. I just never got into the mode of using Elisp on a
       | daily basis and it's faded from memory.
       | 
       | I'm excited about this book. And, I really wish there was a book
       | that showed how a developer using a more modern language like
       | JavaScript could use it to customize Emacs.
       | 
       | This is why VSCode is winning, because it embraces modern
       | languages in a really powerful way. When I install a new Emacs
       | into a new debian machine, i still struggle to get package
       | installation working. But I'm getting really worried about the
       | direction Microsoft is taking with VSCode and wish I could be as
       | productive in Emacs. Opening up that environment to modern
       | developers who could tweak their own tools would be amazing and
       | revolutionary.
        
         | grogenaut wrote:
         | Try neovim to see what this approach might look like, yes it's
         | vi not emacs, but they allow python and rust plugins and have a
         | plugin framework now. It's killed sublime for me. And I used to
         | use emacs over vi.
         | 
         | Personally I'd like emacs a lot more if it's plugins system
         | just worked like vscodes does and as you said let me use
         | languages I'm familiar with.
        
           | fayten wrote:
           | Unfortunately it looks like it's a dead project, but
           | https://github.com/kiwanami/emacs-epc builds out an RPC
           | framework for emacs. This would theoretically allow you to
           | use any language you want. The repo shows node.js, python,
           | and ruby integration.
        
         | PaulDavisThe1st wrote:
         | > This is why VSCode is winning, because it embraces modern
         | languages in a really powerful way.
         | 
         | This notion that Javascript is superior to (e.g. elisp) because
         | JS is new and elisp is "old" is really irritating. The reasons
         | JS exists has absolutely zero to do with any issues with elisp
         | or lisp or C or haskell or any other programming language. The
         | fact that you know it and do not know elisp is a real thing,
         | but it says nothing about the qualities and properties of
         | either language.
        
           | JoelMcCracken wrote:
           | its such an absurd idea. look at the top contributors for
           | VSCode, and how many of them are employed at Microsoft:
           | 
           | https://github.com/microsoft/vscode/graphs/contributors
           | 
           | How can you possible separate vscode "winning because of
           | javascript" and "it has development budget X times the budget
           | of Emacs"
        
           | edgyquant wrote:
           | No one said it was superior, but more people know it.
        
             | PaulDavisThe1st wrote:
             | The claim was the VSCode is "winning" because it "embraces
             | modern languages". To me that implies at least some kind of
             | superiority.
        
               | edgyquant wrote:
               | No, it doesn't, it implies that it uses a language which
               | is widespread and most everyone knows. Languages
               | themselves being superior tends to be an opinion.
        
               | PaulDavisThe1st wrote:
               | > "Most everyone knows".
               | 
               | Pardon my age or something. but if you're a software
               | developer who doesn't work on web-dev, you probably do
               | not know JS, certainly not enough to code much in it.
               | 
               | Maybe "most everyone" leaves enough room to describe all
               | the people who do embedded and native development - I
               | don't know the actual numbers.
               | 
               | But the sentence didn't say: "VSCode is winning because
               | its extension language widespread and most everyone knows
               | it". It said "modern languages". Haskell is a modern
               | language. Rust is a modern language. Lua is a modern
               | language. If VSCode (somehow) used them as its extension
               | language, would it still be winning? Clearly, no.
        
               | xrd wrote:
               | I should have said "modern and more popular languages."
               | For the record, I like elisp/lisp, I just don't use them
               | at my day job and have a hard time customizing emacs with
               | them. Emacs is still my favorite editor, but for my day
               | job, I can get much more done in VSCode because it
               | "embraces" (whatever that means) JS much better than
               | Emacs. I wish it wasn't so, and I'm worried about it long
               | term.
        
       | NeutralForest wrote:
       | Cool, always glad to see more Emacs stuff out there.
        
       | rStar wrote:
       | I felt like Superman the first time I hacked some emacs lisp. One
       | of the most enjoyable programming experiences of my life. Thanks
       | for this book.
        
       | truly wrote:
       | Congratulations!
       | 
       | As a curiosity, how did you set the page width?
       | 
       | I find it a bit wide, making it difficult to read.
        
         | bloopernova wrote:
         | Sokolof's comment elsewhere in this thread: Intro of the book
         | confirms: "It is written in Org-mode, first made by Carsten
         | Dominik and then developed by many other people. Diego Zamboni
         | wrote the Org exporter to convert Org-mode syntax to Markua,
         | expected by Leanpub."
         | 
         | So the page width probably was set by Leanpub themselves during
         | typesetting. I am assuming that the Markua language is
         | converted to LaTeX, with the page size/layout being set in that
         | language.
        
       ___________________________________________________________________
       (page generated 2021-11-09 23:02 UTC)