|
|
Subscribe / Log in / New account

Mastering Emacs

By Jake Edge
August 30, 2023

A series of rabbit holes, some of which led to unshaved yaks, recently landed me on a book called Mastering Emacs. Given that I have been using Emacs "professionally" for more than 16 years—and first looked into it a good ways into the previous century—I should probably be pretty well-versed in that editor-cum-operating-system. Sadly, for a variety of reasons, that is not really true, but the book and some concerted effort have been helping me down a path toward Emacs-ian enlightenment. Mastering Emacs may also help others who are struggling in the frothy sea that makes up Emacs documentation.

The backstory of how I got here is kind of goofy—some days rabbit holes look like so much fun ... and they definitely can be, but the lost "productivity" may be problematic. In any case, a Hacker News item on "Elixir for cynical curmudgeons" caught my eye a few weeks back since I certainly qualify. After reading that and poking at Elixir (and Erlang) documentation some, I remembered that I always wanted to understand Lisp macros better—or at all, in truth. That led me back to a project that I started (and promptly drifted away from) after a talk at linux.conf.au about the history of Lisp that I really enjoyed.

That project was, naturally, a Lisp interpreter. It is written in Python and is, at best, 5% complete—and likely not to go too much further. But I dusted it off, made it work for some more Lisp constructs, and suddenly realized that I did not know enough Lisp to even be setting off on such a journey. That should be a solvable problem, so I sought out some more Lisp wisdom and came across "A Road to Common Lisp". It seemed like it contained sensible advice, some of which I started to follow, but then ran into some annoyances using Lisp from the command line. That, inevitably, led to SLIME.

Of course, given that SLIME is also known as the "Superior Lisp Interaction Mode for Emacs", that leads to Emacs, which is an editor I use in anger on a daily basis. It is not, however, my editor of choice; I have been using vi (and its variants) since the early 1980s and it is the editor I reach for—except for work-related tasks. A day-one surprise when I started full-time at LWN in 2007 was that Emacs was closely intertwined with the site operations (article editing, in particular). That led to a crash course in just-enough-Emacs to get by, which has mostly served—for good or ill—since.

In truth, I am not a "power user" of any editor; I suspect that I could still function perfectly well in the Berkeley Unix version of vi that I learned on, lo these many years ago. I may well have only scratched the surface of its capabilities as I am not averse to brute-force solutions to editing problems. But, over the years, I have picked up a few more Emacs "tricks" and been impressed with all that it can do. It has always intrigued me that it can be transmogrified using Lisp, as well.

There are, evidently, add-ons for Vim that fill the same niche as SLIME, so I could have taken that path, but Emacs seemed like the right choice. I can be stubborn in weird ways, such as by ignoring Evil mode, which provides a vi-like experience for Emacs. What little I remembered from my first toe-dip into the Emacs waters—using the GNU Emacs manual with the yellow cover in the mid-1980s—stuck with me (mostly just Control-x Control-c, or C-x C-c, to exit), so I was determined to forge ahead on that path in my 2007 crash course and, of course, since.

The book

So, once I started messing with SLIME, I came to realize that I was lacking the knowledge of some major underpinnings of Emacs. I had encountered Mastering Emacs before, considered buying it, and got distracted before doing so. The Mastering Emacs web site is an excellent resource in its own right and one that I had visited along the way. Right around the time I started my SLIME investigation, a Hacker News post about the book showed up; when I saw that the book was on sale in the comments on the post, I took the plunge and bought it.

Other than "lost" time, I have not even remotely regretted the purchase. Mickey Petersen has done an excellent job with the book and it is well worth its full price ($49.99) in my opinion. I am still working my way all the way through it—and will undoubtedly refer back to it regularly. It comes in both PDF and EPUB formats; there is no "dead tree" version. Petersen detailed the process of writing the book (in Emacs, naturally) on his site; he hired a professional editor to help him, which was a nice touch. The articles on his site are well-written, though, so perhaps his editor did not have all that much work to do.

It is an opinionated book, and rightly so. A dry recounting of the options and possibilities within Emacs would be far less useful. Which is not to say that such a manual does not have its place—and one of those places is inside Emacs itself, of course. But Petersen is providing a sort of guided tour of Emacs, describing pieces of the editor in a way that makes sense for a narrative, rather than a reference. Along the way, he clearly indicates what his opinions are, why he has them, and how that changes his Emacs environment. There is no expectation of rigid adherence to his suggestions, however; some of them I have adopted, others not, and I have made a few customizations of my own. None of that interferes with the rest of the book in any way.

The organization may seem a bit strange at first, but it has grown on me. Beyond the introductory material, he starts with the philosophy of Emacs, which is an important underpinning. Understanding that "Emacs is a tinkerer's editor" is fundamental to working with it. He notes that much of that tinkering will require learning some Emacs Lisp (elisp), which intimidates and chases away some potential users, sadly.

The book has a nice justification for "why Lisp?" that resonated strongly with me. It makes sense that a language where there is no distinction between code and data would be the basis for an editor (and so much more) that is Emacs and its ecosystem. Obviously my interest in delving further into Lisp made it easy to buy into the justification; others may not find it so compelling.

Terms

The "Important Conventions" section provides something of an impedance-matching layer between Emacs terms and those that are used elsewhere. Terms like "window", "frame", "mark", "point", "buffer", "kill", "yank", and so on have specific meanings in Emacs; some of them are confusing because they conflict with current usage. In many cases, Emacs started using these terms before the other uses came about, but it was not popular—or visible—enough to "enforce" its prior art.

That section also describes the buffer interface, its modeline, and mini-buffer. Buffers are the basic unit of interaction in Emacs, which can be displayed in windows, that are contained in frames. These days, of course, a window has a much different meaning, which generally corresponds to an Emacs frame. Buffers can have one major and multiple minor modes as well. Wrapping one's head around all of these terms is important, but the book has not even started talking about how to install or start up Emacs at this point.

It gets there, of course, and suggests that readers run the latest Emacs available, which is (or was) Emacs 28; since then, Emacs 29.1 was released. Petersen has a lengthy article that annotates the Emacs NEWS file for the release with the features that he found interesting. That is presumably partly in preparation for an updated version of Mastering Emacs before too long. Updates to the book are free for those who have purchased it.

One might guess that next up might be editing text, but that part does not actually come until a little ways beyond the midpoint of the 300+ page book. Before you get there, there are lengthy descriptions of the key sequences used by Emacs, which is certainly an area that those who are new to the editor will need to grasp. One of the most strongly worded opinions that Petersen offers is to remap the Caps Lock key as Control; in fact, he suggests disabling the left-hand-side Control key entirely. So far, I have been unable to take that last step, as there are decades of muscle memory to overcome. Eventually, remapping that key to Meta (the other major Emacs modifier key) has some appeal, but may prove to be insanity.

The extensive customize interface (M-x customize) is described in some detail; it allows changing an unbelievably vast array of options. Those changes can be just for the session or can be saved in the startup file (normally ~/.emacs.d/init.el these days, apparently, though ~/.emacs still works) so that they become permanent. The customize interface is one of the few that I have encountered in Emacs with buttons and other controls that make using the mouse, rather than the keyboard, seem like the right way to go.

Searching the internet for "how to do X in Emacs" will quickly lead to lots of different places with suggestions and ideas of varying quality. They will often require evaluating elisp code, which is easy enough to do, but it is a little unclear to me how well that all meshes with a running Emacs session. Petersen quickly describes M-x eval-region (and eval-buffer), but recommends putting code in the startup file and restarting Emacs if something goes wrong, which sounds a little worrisome. Petersen's article on elisp evaluation covers the options more extensively than the book does.

So far, I have not really encountered any major, inexplicable weirdness from evaluating code, so maybe I am overthinking things. I certainly don't want to be restarting Emacs with any frequency; once buffers/windows/frames are set up the way I like them, it is irritating to have to redo all of that. Maybe there is some package out there to save and restore the state; in truth, I would be shocked if there wasn't. But that's something for another day.

Help, movement, and editing

Petersen covers the extensive help system in Emacs, which is something that he says he uses quite frequently. I can only concur that knowing how to find out what a key does, what the keybinding for a command is (if any), what a command does, and so much more is incredibly empowering. The Emacs manual is available, as is the info documentation for many parts of the GNU system, man pages, and so on. I intend to figure out the EPUB reader so I can refer back to the book while wrestling with Emacs in the future.

But, wait, there's more. The "theory of movement" is the next major section, which covers things like loading and saving files (or finding files and saving buffers in Emacs-speak), switching between buffers, listing all of the buffers, killing (closing) buffers, and so on. He strongly suggests switching the C-x C-b buffer listing command to use M-x ibuffer instead. He also thinks that the C-x b command for switching buffers could have a much better auto-complete function, so he recommends using IDO mode (or FIDO mode in Emacs 27+) instead.

There are, of course, a myriad of ways to move the point (cursor) in Emacs: by character, line, word, s-expression, page, paragraph, forward, backward, and probably upside-down too. The mouse can be used (at least in a GUI-window Emacs), as can the arrow keys. The latter has been my downfall, to a certain extent, though Petersen is characteristically sanguine about "cheating" that way; it is something I would like to train myself out of, but not to the point of disabling (or rebinding) those keys.

And, finally, we reach the editing chapter (skipping over plenty to get there). One of the things it stresses is that "killing" text is the main way to get rid of it from a buffer, but that killing is quite distinct from the concept of deleting text as it is in most editors. Except for the single-character delete commands (forward and backward), pretty much all of the other ways to remove text do so by killing it and moving it to the kill ring. As might be guessed, the kill ring stores these kills so that they can be yanked (pasted) elsewhere into the buffer—or into some other buffer entirely.

As with the other parts of the book, Petersen describes the real-world use of the features and tries to point the reader in the right direction to get the most out of them. For example, one could use the region-marking commands to select a region (between the mark and point, in Emacs terms) containing three words, then kill it, but it is much faster to simply do three M-d commands to kill by words; consecutive kills append to the same kill-buffer entry, so the effect is exactly the same. It is tidbits like that, which are scattered throughout the book, that make it so useful.

Remembering said tidbits, commands, key sequences, and so on is an entirely separate problem, of course. I have had an emacs-cheat file, lovingly maintained with vi until recently, since the crash-course days. It has grown by leaps and bounds over the last couple of weeks. I find myself referring to it frequently (from inside Emacs, of course), but there seems to be hope that I am actually committing some of what I have learned to muscle memory. Time will tell.

So far, I have read through two-thirds of the book, while skimming and cherry-picking through the rest. Perhaps my newfound enthusiasm for Emacs (Lisp, ...) is coloring my judgment but I have found the book to be well-nigh amazing. I have some minor quibbles in spots; for example, the whole-line-or-region package that he recommends can be installed easily enough, at least if you add the MELPA repository as he also suggested, but he never mentions that you need to enable the package in init.el (or wherever).

Meanwhile, it would seem that MELPA is where the majority of Emacs packages live today, so why isn't it added by default? That is not Petersen's fault, of course; I should probably take it up with my distribution or with the Emacs project itself. (Ah, as it turns out, Richard Stallman objects to MELPA, so I guess I should bug my distribution—or just ignore the problem and move along.)

Even in the parts of the book that I have read, I have skipped over topics in this review: the undo ring, package manager, searching, tabs, and more. Beware that reading the book can be something of a time sink, as can attempting to apply what has been learned. I find myself pausing more often than I used to, but also generally moving around more efficiently in Emacs; so far, it is hard to see a net win there, but the signs are hopeful. My emacs-cheat file (always visible in another frame or window) is organized in a way that matches how my brain (allegedly) works, so something personalized along those lines may make sense for others.

I did not set out to write an article when I stumbled down this rabbit-hole-strewn path, but, as I got into the book, it seemed like something readers might want to learn about. For now, my goal is to see if I can wean myself away from vi, mostly as a test; I certainly have nothing against that editor and will use it again. For example, I have not even tried Emacs in a terminal, or over SSH, which may necessitate a return to my editing roots, at least temporarily. In the meantime, I am enjoying my exploration of Emacs (and Lisp)—learning new things is always fun.



to post comments

Mastering Emacs

Posted Aug 30, 2023 20:40 UTC (Wed) by pwfxq (subscriber, #84695) [Link] (3 responses)

*Mumble* years ago I used Emacs when I was at university. It was clear that, even back then, it was a very powerful tool. The more I used it, the better I got at harnessing its power and the more efficient I became.

Then I left university and entered the corporate world of Windows & Microsoft and Emacs quickly became a distant memory.

With tools such as Emacs, the more time you invest in learning how to use them, the better they work for you.

Mastering Emacs

Posted Sep 4, 2023 23:42 UTC (Mon) by gerdesj (subscriber, #5446) [Link] (1 responses)

"and entered the corporate world of Windows & Microsoft"

My corporate world involves Arch on my laptop and desktop. Just because your customers follow the herd doesn't mean you have to too. I'm the MD (BTW!)

Mastering Emacs

Posted Sep 5, 2023 17:11 UTC (Tue) by vmanis (subscriber, #163384) [Link]

I'm long since retired now, but when I worked at $BIGCORP, my computer ran Windows, because that was what $BIGCORP's IT department understood. So I installed Cygwin, and my computing environment used primarily TeX, Emacs, and bash. I would think that WSL2 would make that even easier.

Mastering Emacs

Posted Sep 7, 2023 6:21 UTC (Thu) by coriordan (guest, #7544) [Link]

Various jobs have required me to use other tools for text but I install Emacs everywhere and I always have an Emacs window open to process text before pasting it back into whatever system I have to work in.

Mastering Emacs

Posted Aug 30, 2023 22:42 UTC (Wed) by IanKelling (subscriber, #89418) [Link] (18 responses)

I'm a bit annoyed that the philosophy of emacs came up without mentioning that the book is diametrically opposed in an important way: it is not freedom respecting. https://www.gnu.org/philosophy/free-doc.en.html. It would be nice if someone from LWN could let the author know that LWN has had success in liberating its articles after some time.

Anyways, emacs is great. I read the other day that some proprietary derivative of vs code is getting popular, and I thought, ya, emacs still has a bright future.

Mastering Emacs

Posted Aug 31, 2023 5:56 UTC (Thu) by rsidd (subscriber, #2582) [Link] (14 responses)

This book is not "documentation". That would be the emacs manual. This is an extra and optional effort from a third-party author, and he is free to charge just as any writer does. RMS nowhere claims that all books must be free. In fact, even his GFDL for documentation ran into trouble with Debian as "not free enough"!

Mastering Emacs

Posted Aug 31, 2023 14:32 UTC (Thu) by IanKelling (subscriber, #89418) [Link] (13 responses)

> This book is not "documentation".

I see no basis for that. It has broad overlap with what is in the emacs info manual.

> This is an extra and optional effort from a third-party author, and he is free to charge just as any writer does.

I never said he should not charge. I'm happy that he charges. Freedom respecting does not mean not charging.

> RMS nowhere claims that all books must be free.

Neither did I. I linked to an article explaining that documentation should be free. You've really lost the point here.

> In fact, even his GFDL for documentation ran into trouble with Debian as "not free enough"!

Again, unrelated to my comment.

Mastering Emacs

Posted Sep 1, 2023 1:21 UTC (Fri) by mjg59 (subscriber, #23239) [Link] (2 responses)

> Again, unrelated to my comment.

What *is* related to your comment is that the official emacs manual is released under a non-Free license, so complaining about other documentation also being non-Free is somewhat unreasonable.

Mastering Emacs

Posted Sep 1, 2023 13:17 UTC (Fri) by IanKelling (subscriber, #89418) [Link] (1 responses)

Even if you were right about it being nonfree, which you aren't, you are claiming a https://en.wikipedia.org/wiki/Whataboutism, which is completely wrong. Because some injustice exists does not make it invalid to complain about another injustice.

Mastering Emacs

Posted Sep 1, 2023 13:54 UTC (Fri) by pizza (subscriber, #46) [Link]

> Even if you were right about it being nonfree, which you aren't.

The emacs documentation, like many other GNU software documents, are provided under the GFDL, with invariant sections.

"invariant sections" cannot be altered or removed. This makes them non-free under Debian's guidelines.

So yes, someone pointing out that getting lectured about the "non-freeness" of a book about a major free software package whose own documentation (as written by the saint of Free Software himself, RMS) is explicitly (and intentionally) non-free is not a "whataboutism", it's pointing out "good enough for thee but not for me" hypocrisy.

After all, both the document and this book are non-free, just to different degrees.

Mastering Emacs

Posted Sep 1, 2023 12:00 UTC (Fri) by Wol (subscriber, #4433) [Link] (1 responses)

> > This book is not "documentation".

> I see no basis for that. It has broad overlap with what is in the emacs info manual.

From the comments I've seen, it most definitely is not documentation - it's actually useful!!! :-)

Documentation is the art of telling you what you already know as a reminder. As a general rule, giving a newbie the documentation and saying "teach yourself" is pretty much a guaranteed disaster.

Given the number of comments about how people have learned new stuff from this book, and how this book has greatly increased what they can do with Emacs, I'd say it most definitely is not documentation.

Cheers,
Wol

Mastering Emacs

Posted Sep 1, 2023 12:57 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

I sounds like the book covers all parts of this graph[1] *except* documentation (to differing degrees).

[1]https://documentation.divio.com/

Mastering Emacs

Posted Sep 2, 2023 2:09 UTC (Sat) by marcH (subscriber, #57642) [Link] (7 responses)

> I'm a bit annoyed that the philosophy of emacs came up without mentioning that the book is diametrically opposed in an important way: it is not freedom respecting. https://www.gnu.org/philosophy/free-doc.en.html.

What did you expect? I mean, in which fantasy world does every book about free software follow this commandment? Are you going to grace every book review with such incredibly naive trolling?

> I see no basis for that. It has broad overlap with what is in the emacs info manual.

Quoting the very start of the page you referenced:
> Documentation is an essential part of any software package; when an important free software package does not come with a free manual, that is a major gap.

Totally agree and this does not describe the Emacs situation.

> I never said he should not charge. I'm happy that he charges. Freedom respecting does not mean not charging.

If the book was available online then there's much less chance I would buy it and it's the same for many other readers. Pretending this economic reality does not exist is again incredibly naive or trolling or both.

Mastering Emacs

Posted Sep 3, 2023 3:46 UTC (Sun) by IanKelling (subscriber, #89418) [Link] (6 responses)

MarcH, who are you? All I see is your username which has the same letters as a month and I don't recognize. It is much easier to say someone's post is "incredibly naive trolling" using anonymous speech.

Mastering Emacs

Posted Sep 3, 2023 9:13 UTC (Sun) by Wol (subscriber, #4433) [Link] (2 responses)

Ian - are you a REGULAR reader of this site? MarcH has been around a lot longer than you.

And if he told you his name, would it leave you any the wiser? I doubt me telling me you my real name (for heavens sake, "Wol" is based on my real name) would leave you any the wiser as to who I am! People here know me by reputation - the only real way to know anyone. Someone's "real name" is just a meaningless label.

And anyway, you're completely missing the point. I'm with MarcH on this - as I understand it, FSF documentation usually contains invariant sections, and the GFDL with invariant sections is not a free licence.

And another point, as a lawyer I presume you're rich (compared to most people, at any rate). I'm lucky, I'm rich, I'm near retirement and my mortgage has near enough gone. But the fact I've still got a mortgage almost at retirement age says I'm not THAT rich. You may be able to afford to give your work away for free (bully for you!), but who are you to tell other people to give their work away for free!?!? That's theirs to gift, not you to demand!?!? (That demand is called attempted theft!)

Cheers,
Wol

Mastering Emacs

Posted Sep 3, 2023 9:39 UTC (Sun) by mjg59 (subscriber, #23239) [Link] (1 responses)

To the best of my knowledge Ian isn't a lawyer, but even if he were he's working for the FSF and, well, even lawyers working for relatively small non-profits are not making bank. Some lawyers do become unreasonably wealthy, but many spend their time working on things they believe in. There's plenty of room to talk about which freedoms should apply to which things without turning it into an argument about economics.

Mastering Emacs

Posted Sep 3, 2023 10:53 UTC (Sun) by Wol (subscriber, #4433) [Link]

Yup, there's economics and there's economics, but, to quote the bible "Take the mote out of your own eye before complaining about the spec in someone else's", and "God loves a cheerful giver".

You shouldn't be complaining about the unFreeness of charging for the book, and ignoring the unFreeness of invariant sections in the manual.

And you shouldn't be trying to give away *other peoples'* work.

Cheers,
Wol

Mastering Emacs

Posted Sep 3, 2023 14:54 UTC (Sun) by marcH (subscriber, #57642) [Link] (1 responses)

I don't know you either and I doubt everyone here does. Somehow this does not stop you from spamming every other LWN article with unsolicited, always annoying and frequently pointless free software commandments. That everyone knows. Breaking news: truly free software has not conquered the world as it should have! Thanks for the Nth million reminder; we had forgotten that again! /s

The comments can be anonymous here. If that's a problem for you then there's always the easiest of fix: go and preach somewhere else. Simply avoid the comments section. You can still read the articles; a lot of people do just that.

Mastering comportment

Posted Sep 3, 2023 15:41 UTC (Sun) by corbet (editor, #1) [Link]

Perhaps this is a good time for everybody involved here to take a break and calm down? I don't think this conversation needs to go any further.

Mastering Emacs

Posted Sep 4, 2023 10:22 UTC (Mon) by paulj (subscriber, #341) [Link]

given the capitalisation, I'd read it as "Marc H".

Mastering Emacs

Posted Aug 31, 2023 9:51 UTC (Thu) by epa (subscriber, #39769) [Link] (1 responses)

The LWN article isn't released under a free licence either, so if you are only interested in completely freedom-respecting documents you may be in the wrong place.

Mastering Emacs

Posted Aug 31, 2023 14:36 UTC (Thu) by IanKelling (subscriber, #89418) [Link]

From clicking around with a small sample, all the LWN articles I see older than a week or two say "This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license", and I assume this one probably will too.

Mastering Emacs

Posted Sep 3, 2023 3:56 UTC (Sun) by IanKelling (subscriber, #89418) [Link]

> some proprietary derivative of vs code

To criticize my own comment, this implies vs code is not proprietary. It is. So, the "proprietary derivative" is likely a derivative of vscodium or some other build of vs code with the proprietary software removed.

Mastering Emacs

Posted Aug 31, 2023 1:23 UTC (Thu) by karim (subscriber, #114) [Link]

Really? You had to have me add another book on my reading list?

Now I'm seriously considering unsubscribing from LWN :P

Mastering Emacs

Posted Aug 31, 2023 7:04 UTC (Thu) by hickinbottoms (subscriber, #14798) [Link]

Thoroughly enjoyed this, thanks.

I'd be interested in an occasional update in the same vein as our grumpy editor's journey into accounting packages -- it may not be a topic everyone is dealing with personally, but the description of the journey and its many meanderings is the real gold.

Mastering Emacs

Posted Aug 31, 2023 10:04 UTC (Thu) by njh (subscriber, #4425) [Link] (10 responses)

For example, I have not even tried Emacs in a terminal, or over SSH, [...]

Learn to TRAMP! In my experience it is a mistake to open a terminal window, SSH, and start an Emacs process on a remote system.

Run Emacs on your local machine. You can access any file on "remote.example.com" by doing C-x C-f on "/ssh:remote.example.com:/path/to/file". Emacs will pull a copy of the file over an SSH connection and allow you to edit it in the local instance of the editor. When you save it, it gets copied back over the SSH connection to the remote system. If the working directory for the current buffer is remote then you can even use M-x shell to start up an emacs *shell* buffer locally, talking to a shell process running on the remote system.

You get a much better interactive editing experience over slow links this way, and it means that you don't have to propergate all your tweaks/preferences to umpteen different remote ~/.emacs files - shave the yak once and use your optimised yak to edit everywhere!

Mastering Emacs

Posted Aug 31, 2023 10:52 UTC (Thu) by zaitseff (subscriber, #851) [Link] (2 responses)

At the risk of emulating Slashdot’s +1 feature, I heartily agree. I’ve been an Emacs user for almost quarter of a century, but only discovered TRAMP mode a year or so ago—and now I can’t live without it. And it’s not just SSH: I often do a chain of SSH to a jump box, SSH to an internal system, sudo to root, open a particular file in /etc—all from the C-x C-f Find File command. Try something like opening /ssh:user@jumpbox|ssh:nextuser@internalbox|sudo::/etc/motd

I myself purchased Peterson’s book about a year ago. There was enough there for even an old hand like mine to justify every cent spent. Well done, Mickey!

Mastering Emacs

Posted Aug 31, 2023 11:06 UTC (Thu) by zaitseff (subscriber, #851) [Link] (1 responses)

By the way, the other package I’ve come to love is Magit, which provides a wonderful interface to Git in a very Emacs-y way. Pretty much anything you can do on the git command line, you can do in Magit—and I really like being able to highlight specific lines in the diff output displayed by Magit and staging just those: cherry-picking on a line-by-line or even character-by-character basis as needed.

Mastering Emacs

Posted Sep 2, 2023 2:22 UTC (Sat) by marcH (subscriber, #57642) [Link]

Tramp rocks. Magit does too. I've been using both together a lot and while the combination amazingly does work, any significant latency makes the combination totally unusable. Barely usable when the network latency is under 30 ms (= in the same city) but anything further just forget it.

The Magit maintainer does not plan on trying to support this combination, which may be simply impossible anyway for high latencies https://github.com/magit/magit/issues/2985

As a pure coincidence I was discussing this topic today with someone who is running emacs -nw in "text mode" on the remote system(s) instead of tramp for this exact reason. He said https://github.com/spudlyo/clipetty + some terminfo-fu is part of the solution.

Mastering Emacs

Posted Aug 31, 2023 12:58 UTC (Thu) by wtarreau (subscriber, #51152) [Link] (4 responses)

Tramp is powerful and really convenient. The only thing I hate is its syntax. I'm constantly having a few buffers opened in tramp mode, despite this, I systematically google for the syntax after 10 failed attemps when I need to open a new one, as all I remember is "starts with a slash and almost looks like a URL but not exactly", and when I get the exact syntax I think "well, almost".

But I've used emacs quite a few times over SSH, mainly when not on my regular computer, using a distro providing so horrible default settings that it was easier to SSH and use a remote one. It's pretty good, the only thing is that you need to force yourself to use Esc instead of Meta, and depending on your terminal colors, syntax highlighting might be a bit difficult.

Regardless I tend to prefer Emacs for large projects: I open all my haproxy C files at once when I first boot my PC, and navigate through them till next reboot, as it's really convenient to have everything open, and it deals very well with FS changes (file revert), has good understanding of merge conflicts, so this combines pretty well with git, patch etc. For small file editing, system configs or remote edition I most often use vi, mostly the elvis flavor which is ultra-light, loads super fast, and is fairly complete for scripting/config editing (supports rectangle selection etc). And I'm using vim for e-mails (richer, colors to distinguish responses levels, automatic wrapping etc).

Thanks Jake for the book review, now it's tempting ;-)

Mastering Emacs

Posted Sep 1, 2023 9:03 UTC (Fri) by mbunkus (subscriber, #87248) [Link] (2 responses)

> the only thing is that you need to force yourself to use Esc instead of Meta

What OS are you ssh'ing from? 'cause that's not an issue I've ever had, and I'm using Emacs over ssh daily, several hours per day. I run it both inside tmux on the remote end & without tmux, both from Windows clients via putty & from Linux clients inside kitty/alacritty. I can and do use my Alt key for meta just fine.

Mastering Emacs

Posted Sep 3, 2023 11:13 UTC (Sun) by wtarreau (subscriber, #51152) [Link] (1 responses)

> What OS are you ssh'ing from?

Just tried again right now from this current laptop on ubuntu 22.04 from an xterm. I ssh into my main PC, start emacs to edit a Makefile. Pressing Alt-X inserts an "O" with an oblique bar on it, while doing Esc-x moves the prompt into the mini-buffer just after "M-x ". The rest (including Ctrl-space etc) works fine though.

If I change the terminal's config to enable "Meta sends Escape", of course it works, but that's cheating :-)
It's no big deal anyway.

Mastering Emacs

Posted Sep 3, 2023 12:52 UTC (Sun) by mbunkus (subscriber, #87248) [Link]

And that made me even more curious: what are the applications that you run over ssh where the distinction between Meta & Esc matters to your use of them?

Mastering Emacs

Posted Sep 2, 2023 1:54 UTC (Sat) by marcH (subscriber, #57642) [Link]

> Tramp is powerful and really convenient. The only thing I hate is its syntax. I'm constantly having a few buffers opened in tramp mode, despite this, I systematically google for the syntax after 10 failed attemps when I need to open a new one, as all I remember is "starts with a slash and almost looks like a URL but not exactly", and when I get the exact syntax I think "well, almost".

My best workaround for exactly this is recentf (recent files), which is very useful even without tramp.

Mastering Emacs

Posted Aug 31, 2023 16:22 UTC (Thu) by spacefrogg (subscriber, #119608) [Link]

I also agree. Let me issue one word of caution, though! Never, ever, use magit (which is THE git interface and a whole new revelation in itself) over TRAMP as root. It has the habit of overwriting files, which leads to replacing the /dev/null device file with a normal file.

Ask me how I know...

Mastering Emacs

Posted Aug 31, 2023 16:49 UTC (Thu) by gjost (subscriber, #60613) [Link]

Editing files in a VM using Emacs and TRAMP has been my preferred modality for a really long time. It's been *possible* to edit files on remote systems, but adding Tailscale makes it even easier.

Mastering Emacs

Posted Aug 31, 2023 13:22 UTC (Thu) by kpfleming (subscriber, #23250) [Link]

I'll echo the other commenters... thanks for this! As a person who has never succeeded in reading through the Emacs manual once, I'm keen to read something that is narrative and opinionated instead of reference material.

Also, for reference, I've been using Emacs since the days of green-screen terminals on Multics systems (yes, the early 80s), and to this day I do not use the GUI version. My Debian systems get the emacs-nox package, and that's plenty for me. Combining that with the Emacs user-level systemd service and 'emacsclient', I get a reliable and consistent working environment.

Mastering Emacs

Posted Aug 31, 2023 14:36 UTC (Thu) by bkw1a (subscriber, #4101) [Link] (2 responses)

I use emacs all day, every day, and have since the late 1980s. My fingers still don't know many of the emacs shortcuts, though. Instead, they know the key bindings from the VMS "edit" command (later supplanted by TPU).

When I first started using emacs, I was migrating away from VMS machines, onto DEC Ultrix and then Linux. I found an emacs package that would emulate the key bindings of the VMS editor, and I've used that (and its successors) ever since, even though it warns me now that "Package tpu-edt is obsolete!". If it ever breaks, I suppose I'll learn enough emacs lisp to fix it.

Mastering Emacs

Posted Sep 4, 2023 14:25 UTC (Mon) by rudi (subscriber, #4828) [Link] (1 responses)

In Emacs development, "obsolete" does not mean "will automatically vanish after 2 major versions" or anything like that. But sending a short message to emacs-devel telling the maintainers something like "I still find this library useful, please consider keeping it around, and thanks for keeping the whole of Emacs working so well!" will certainly help :-)

Mastering Emacs

Posted Sep 4, 2023 16:04 UTC (Mon) by mbunkus (subscriber, #87248) [Link]

I just had to adjust my bindings for Footnote-add-footnote to footnote-add-footnote as it seems to have been renamed in v29. I don't remember ever seeing a deprecation warning for the capitalized spelling prior to v29. Look, even the Emacs wiki contains the capitalized spelling: https://www.emacswiki.org/emacs/FootnoteMode

Of course this is trivial to fix. My point is that the envisioned, ideal handling of deprecations is somewhat marred by reality.

Mastering Emacs

Posted Aug 31, 2023 16:20 UTC (Thu) by ibukanov (subscriber, #3942) [Link]

Emacs is powerful, but if one's taste does not match Emacs defaults one may need to write hundreds of lines of Emacs Lisp dialect with obscure API when similar customisations in other editors or IDE are just few clicks in preferences and few drags of GUI elements on the screen. These days situation is improved as there are often packages that already provide such customisation. But then one still needs to spend time trying to figure out which packages does what.

Mastering Emacs

Posted Aug 31, 2023 16:33 UTC (Thu) by spacefrogg (subscriber, #119608) [Link]

I use emacs as my GUI via exwm for several years now and went to great lengths to integrate most of my business (e-mail, document writing, terminal usage) into emacs. I use doom-emacs (used spacemacs before that) and both packages are, again, a complete revelation in themselves. Their great contribution to (the emacs) society is that they unify the interface between tasks and make everything related to text exceptionally accessible. (Their project-wide search/multi-edit interfaces are unparalleled anywhere in the world. Although, credits go to the developers of the respective modules like vertico and embark etc.)

I am perfectly aware that this will not be usable to most people out there. But let me emphasize the single-most important gain I have from this:

I have the same text-processing interface in 90% of my work. And almost everything (including window management) works via a single interface. And I find, this incredibly liberates my mind to concentrate on the task at hand.

Mastering Emacs

Posted Sep 1, 2023 1:42 UTC (Fri) by IkeTo (subscriber, #2122) [Link]

When others have a chance to see me working with Emacs, the magic moment is usually when I create a keyboard macro and run it over a narrowed buffer. Things I do varies. It might be calculating the average of numbers in each line of text. Or reformat each CSV line in a way that is human readable. Or produce a SQL statement to modify the database according to that CSV so that I can pass the result into mysql. Or to find a pair of matching <div> and </div> in an HTML file and remove the tags repeatedly until there is no such pair. Whatever. Make a few tries defining a keyboard macro by doing what I need perfectly and in a repeatable way. Then run it 10 times by a repeat command. If it is not enough, run it 1000 times more. Dada... the work is done. Save me the time writing a full program needed only once.

Mastering Emacs (the book)

Posted Sep 1, 2023 19:38 UTC (Fri) by darwi (subscriber, #131202) [Link]

When I started programming on Linux, around 13 years ago now, I picked emacs as my editor, as vi's mode switching did not match my brain's flow patterns.  I started with the official tutorial, some other tutorials, and random elisp snippets on the web.  It was "good enough", as I've learned more and more commands over the years.  In the back of my head, I knew I need to delve in further, but I didn't.

Upon emacs 29 release, I saw Mickey's commentary on the official release notes, and the link to buy the book there.  Given the really high quality of _all_ the articles there (as also hinted at by Jake above), I knew it would be a good book.

I'm reading it sequentially and slowly, page by page, and collecting notes along the way to make sure I don't miss anything, and cross-referencing such notes with the EmacsWiki, which is another great refereence (I don't want to repeat the way I "learned" emacs, 13 years ago, this time.  I really wanted to understand emacs view of the world.)

Honestly, the book is just amazing.  You can see that the author is a great writer, as the narration style is quite gripping.  For a long time, information about emacs from its various help systems was a bit formidable because I've never really understand how emacs calls things.  The author's choice of focusing on the terminology first was just amazing: buffer, frame, window, point, mark, kill ring, key, prefix/complete keys, interactive functions, universal/prefix arguments, etc., etc., etc.  The whole point of the book is not actually to "teach" you, but to make you experienced enough on your own so that you're able to "teach yourself" in the emacs ecosystem.

This is epmphasized further in the first paragraph of Chapter 17, conclusion:

How do you master a text editor as diverse as Emacs?  The answer, surprisingly, is simple: by knowing how to ask it the right questions  ...  So, the only way to truly understand what happens in Emacs is to ask it — simple, but true.

It was really cool to find an LWN article reviewing the exact same book I'm currently reading :) Thanks Jake!

Mastering Emacs

Posted Sep 2, 2023 2:44 UTC (Sat) by marcH (subscriber, #57642) [Link]

> Understanding that "Emacs is a tinkerer's editor" is fundamental to working with it. He notes that much of that tinkering will require learning some Emacs Lisp (elisp), which intimidates and chases away some potential users, sadly.

Speaking of tinkering elisp: does the book have anything about debuggers?

I wanted to be a good citizen and once tried to use a couple debuggers to investigate an issue in tramp. Even if I could not fix it myself, the deeper the investigation and the better the bug report and the better chance the issue will get fixed.

When you're completely new to a code base, absolutely nothing beats a good debugger to jump immediately in the action and save tremendous amounts of time. In any language.

I'm a relatively seasoned Emacs users and my debugging experience was totally miserable. I kinda got what I wanted (a detailed, actionable bug report) but incredibly slowly and painfully. I followed various pages that seemed to converge so I'm wondering whether debugging elisp is possible at all.

Mastering Emacs

Posted Sep 3, 2023 12:28 UTC (Sun) by mhvk (subscriber, #86585) [Link]

The addition to emacs that I would most recommend (and that I use every day) is org-mode. Though I also really like undo-tree as a way to allow revisiting edits one made, including "wrong" directions one took.

Mastering Emacs

Posted Sep 4, 2023 3:49 UTC (Mon) by neilbrown (subscriber, #359) [Link] (1 responses)

> in fact, he suggests disabling the left-hand-side Control key entirely.

I wonder if he is right-handed...

Mastering Emacs

Posted Sep 4, 2023 13:23 UTC (Mon) by mathstuf (subscriber, #69389) [Link]

I'm right-handed and almost never use the right modifiers unless I'm one-handing anyways.

Mastering Emacs

Posted Sep 4, 2023 8:07 UTC (Mon) by jem (subscriber, #24231) [Link] (3 responses)

>One of the most strongly worded opinions that Petersen offers is to remap the Caps Lock key as Control; in fact, he suggests disabling the left-hand-side Control key entirely. So far, I have been unable to take that last step, as there are decades of muscle memory to overcome.

It was standard for display terminals before the IBM PC to have the control key to the left of the A key. Likewise on the microcomputers of the same era: the Apple II, the Atari ST, the Amiga, and more. Then the PC came and ruined my muscle memory.

Mastering Emacs

Posted Sep 4, 2023 10:27 UTC (Mon) by paulj (subscriber, #341) [Link] (2 responses)

Every Linux env. has a nice friendly GUI option to enable either the "remap caps-lock to ctrl" or "swap ctrl and caps-lock" options. Sorry, every environment except GNOME of course, where you have to go hunt for some "tweaks" app and install that. (Gratuitous OT flame bait: The GNOME haters aren't laughing now though, given the immense GNOME 3 has now seen with the wider, non-Linux-nerd market).

Even Windows, remap ctrl is a small registry tweak away. Much to the confusion of local IT admin if they have to do something with my laptop (sigh.. Windows is mandated... But these days, Windows can be used as a - somewhat shitty - kernel + display + Window Manager for a Linux container + X11 [and, apparently, soon Wayland]).

Mastering Emacs

Posted Sep 4, 2023 10:28 UTC (Mon) by paulj (subscriber, #341) [Link]

... immense ^success GNOME 3 has now ...

Mastering Emacs

Posted Oct 24, 2023 16:20 UTC (Tue) by daenzer (subscriber, #7050) [Link]

> But these days, Windows can be used as a - somewhat shitty - kernel + display + Window Manager for a Linux container + X11 [and, apparently, soon Wayland]

If you're talking about WSL, the WSL GUI support has been Wayland based from the start (using Weston as the compositor).

rabbit holes

Posted Sep 9, 2023 0:27 UTC (Sat) by jrincayc (guest, #29129) [Link]

I too have started down one rabbit hole, and ended up in another. I once started with a Python mini Lisp interpreter, ported it to Rust, then made a specification for a tiny version of Scheme ( https://github.com/jrincayc/r7rs-pico-spec ), and then rewrote the Rust version to match the specification ( https://github.com/jrincayc/rust_pr7rs/ )

(and I have been using Emacs for over a quarter century, and I still have plenty to learn)


Copyright © 2023, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds