News for hackers. Stuff that matters.
Re:Emacs’s Builtin Elisp Cheat Sheet by rollcat on Wednesday July 06, 2022 @09:48AM (#32000830)
I have a love-hate relationship with Emacs.

The defaults are absolutely awful. The editor is pretty unusable without at least a hundred lines of ELisp: basic stuff like CUA, setting up fonts, disabling useless UI clutter, delete-selection-mode, rebinding a couple keys, setting up packages, explaining where to find coreutils on BSD systems, etc. And then you get to packages.

If you want to do anything remotely useful, you're gonna have to start installing random stuff from GNU ELPA, MELPA, etc. There's no package pinning or SemVer so you get what you get, packages sometimes break in mysterious ways. So you write more code to work around various broken stuff in packages.

I've gone through several iterations of throwing away my entire init.el and starting from scratch with just the bare minimum needed to get work done. At the current iteration, ELisp is still ~33% of all source code volume in my dotfiles repo[0]. I haven't pushed my latest effort to unbreak "jump to definition" (because apparently dumb-jump is deprecated??? and I need to use xref??? but it doesn't work???) so that'll likely go up.

I never wanted to write enough ELisp to justify calling it a program, but Emacs made me.

But then there is magit[1], which is so damn good, it makes every other VCS interface look like a sad joke. Which is problematic, because configuring Emacs itself is a bit of a sad joke. I want to just write code, not write code to make just writing code less of a pain. :(

[0]: https://github.com/rollcat/dotfiles

[1]: https://magit.vc

Re:Emacs’s Builtin Elisp Cheat Sheet by rvdca on Wednesday July 06, 2022 @10:22AM (#32001415)
Regarding your comment on package pinning, you can see straight.el (https://github.com/radian-software/straight.el)

Previous discussion on HN here : https://news.ycombinator.com/item?id=31833101

Re:Emacs’s Builtin Elisp Cheat Sheet by iLemming on Wednesday July 06, 2022 @04:59PM (#32006746)
The story is as old as Emacs itself. Many people (if not most) start using Emacs by treating it as "an editor". They think they have to configure it by tweaking settings and changing various options.

But Emacs is nothing but clay, an assortment of Lego pieces, building blocks, programmers' equivalent of IKEA furniture, DYI toolkit, etc.

It's not an editor, it's material for you to build your own editor.

> I never wanted to write enough ELisp

That's the mistake Emacs newcomers often make. If you truly want to master Emacs, there's no way around it - you have to accept Emacs Lisp. With all its flaws and incredible power.

If you hate Lisp because it's not like languages you learned and used before; it doesn't look like Python, Javascript or Ruby, then maybe you're missing something.

One needs to set aside their prejudice about parenthesis, learn structural editing commands, understand REPL-driven workflow, and then, once they are over that initial barrier, they may realize that all those [more popular] languages borrowed heavily from Lisp, and Lisp is an extremely nice programming language.

True craftsmen very often make their own tools. I am of course biased here, but in all honesty, every single professional I know, whom I can count as an Emacs power-user or even a master; Every single one of them is truly an incredible hacker.

ps.: "you" used here in the general sense, not targeted to the OC personally.

Re:Emacs’s Builtin Elisp Cheat Sheet by rollcat on Thursday July 07, 2022 @06:08PM (#32020187)
> That's the mistake Emacs newcomers often make.

I've only been using Emacs for 20ish years. (That's more than half of my life.)

At some point I even used Emacs to read my email and RSS, but the stability problems with a single process handling both that and coding led me to try crazy workarounds, like running two instances... Which created problems of its own... Which was all eventually solved by moving back to dedicated apps for mail and news.

> If you hate Lisp because it's not like languages you learned and used before; it doesn't look like Python, Javascript or Ruby, then maybe you're missing something.

I really like Scheme, have had a good time with Common Lisp, wrote my own Lisp dialects for fun; in fact ELisp as a language is not that bad, once you get used to dynamic scoping etc.

My problem is the fact that you have to write actual software to work around deficiencies in your tools. If Emacs was magically rewritten overnight, bug-for-bug, in Scheme, Python, Rust, whatever else, I don't think it would change anything. The problem isn't the language, the problem is the editor/framework/runtime isn't aging well; GuileEmacs or REmacs were/are trying to address the internals, but the problems are running deep across every layer, including incidents like RMS trying to veto emoji support.

All I ask is that an editor do ~80% of the stuff that ~80% of its users want it to do, out of the box, without hassle. VSCode gets it, Jetbrains gets it, heck Notepad gets it. You don't need to write extra code just to convince e.g. GEdit to not shit itself when /bin/ls comes from a BSD userland.

Again, I'd switch to VSCode right now, if it had anything even remotely as good as magit.

Re:Emacs’s Builtin Elisp Cheat Sheet by trenchgun on Thursday July 07, 2022 @03:36AM (#32010959)
>I am of course biased here, but in all honesty, every single professional I know, whom I can count as an Emacs power-user or even a master; Every single one of them is truly an incredible hacker.

Could be explained as selection bias, instead of a causal factor.

Re:Emacs’s Builtin Elisp Cheat Sheet by TacticalCoder on Wednesday July 06, 2022 @10:23AM (#32001449)
> The defaults are absolutely awful.

I find them awful too but many people are fine with these defaults.

> There's no package pinning or SemVer so you get what you get, packages sometimes break in mysterious ways. So you write more code to work around various broken stuff in packages.

There's however a way around it which you may like, seen your complaint... What I do, and it's not unheard of but definitely not the most common when it comes to Emacs, is that I load specific versions of packages. And I commit my entire Emacs setup in Git.

So when I upgrade packages (or install new ones) if anything goes wrong I can just checkout/restore a known fully working state.

There are trade offs when versioning your entire "emacs.d" directory but honestly I don't see many downsides. And I share that emacs.d between several user accounts / machines and any change I made are one "git pull" away.

When I start Emacs I don't check for packages / refresh package contents or anything like that: I only do that when I actually plan to upgrade packages (which I do maybe once every six months or so).

> I want to just write code, not write code to make just writing code less of a pain.

I'd say that's kinda a big selling point of Emacs though: you can write elisp code to make anything you do (not just writing code) less of a pain.

Re:Emacs’s Builtin Elisp Cheat Sheet by rollcat on Wednesday July 06, 2022 @12:51PM (#32003581)
> I'd say that's kinda a big selling point of Emacs though: you can write elisp code to make anything you do (not just writing code) less of a pain.

I agree in principle, but in practice, I find myself writing a lot of ELisp just to work around Emacs' shortcomings. E.g. on macOS, to support dark/light theme switching integrated with the rest of the system, I need an external program[0], a shell script to tell that program to call emacsclient, a LaunchAgent to keep it running, an unholy build of Emacs with all of the GNU-unapproved Cocoa integrations that some kind soul is maintaining, and only THEN a piece of ELisp (which is also calling out to AppleScript) to actually change the theme[1]. And as I wrote this, I realised half of this glue didn't even make it into version control.

[0]: https://github.com/cormacrelf/dark-notify

[1]: https://github.com/rollcat/dotfiles/blob/7f6a6d7/.emacs.d/in...

I've been using Emacs for about 20 years, and with every passing year I just wish there was *less* ELisp for me to think about. The actual useful customisations (like adding the +x bit on shell scripts) are few and far between, most of it is just glue and fixes.

Re:Emacs’s Builtin Elisp Cheat Sheet by morelisp on Wednesday July 06, 2022 @02:30PM (#32004913)
> a shell script to tell that program to call emacsclient, a LaunchAgent to keep it running, an unholy build of Emacs with all of the GNU-unapproved Cocoa integrations that some kind soul is maintaining, and only THEN a piece of ELisp (which is also calling out to AppleScript) to actually change the theme[1]

Why isn't your Emacs session running dark-notify itself, reading its output, and switching accordingly? That seems to remove the need for shell script running emacsclient, the launch agent, and the OSA integration. (But also, I thought ns-do-applescript was stock Emacs? At least I had some ELisp using it and I only ever used emacsformacosox.)

Re:Emacs’s Builtin Elisp Cheat Sheet by rollcat on Thursday July 07, 2022 @06:16PM (#32020266)
> Why isn't your Emacs session running dark-notify itself, reading its output, and switching accordingly?

Thanks for the hint. Maybe I would try that first, if it popped into my head when I was originally writing it; but at this point, it works, and I want less stuff in init.el.

Also I will likely reuse the dark-notify script to change the theme in Terminal.app as well, and Terminal.app doesn't have an ELisp runtime. (Also very weird that Apple's own software doesn't properly support this.)

> But also, I thought ns-do-applescript was stock Emacs?

I don't know. I've switched to macOS only a couple years ago, and the Emacs build I've initially used didn't have it.

Re:Emacs’s Builtin Elisp Cheat Sheet by richiebful1 on Wednesday July 06, 2022 @10:13AM (#32001265)
I've found using Doom Emacs to be a lot easier than handrolling an init file.

I understand the gripes though. Emacs really shines when you have a workflow that is poorly supported by mainstream tooling and you want to write your own. I don't know of any other editor that allows you to add keyboard shortcuts/commands/functionality that easily.

Re:Emacs’s Builtin Elisp Cheat Sheet by rollcat on Wednesday July 06, 2022 @12:30PM (#32003315)
I generally like both Doom and Spacemacs, but they are an additional, huge layer on top of an already complex and complicated editor/runtime/framework. They're great when they give you 99% of what you need, but pretty terrible once you have to start digging.

My dream config file is probably 10-20 lines of my actual preferences, not 40-60k lines on top of which I have to add another several hundred.

Re:Emacs’s Builtin Elisp Cheat Sheet by michaelsbradley on Wednesday July 06, 2022 @10:52AM (#32001882)
You might find prelude worth a look:

https://github.com/bbatsov/prelude#readme

Re:Emacs’s Builtin Elisp Cheat Sheet by beebmam on Wednesday July 06, 2022 @11:51AM (#32002742)
I've been using emacs for org-mode for notes for a decade with emacs defaults. Works wonderfully and is absurdly simple to use
Re:Emacs’s Builtin Elisp Cheat Sheet by abrax3141 on Wednesday July 06, 2022 @10:07AM (#32001160)
Exactly the difference between emacs and most of the software world is that for most of the software world your post would end at “The defaults are absolutely awful. The editor is pretty unusable.”
Re:Emacs’s Builtin Elisp Cheat Sheet by MonkeyClub on Wednesday July 06, 2022 @10:28AM (#32001520)
"Sane defaults" is a thing, but the sanity supporting the defaults changes every couple of decades.

E.g., re the GP's complaint about lack of CUA: CUA is an IBM effort to standardize a dozen shortcuts that are considered more or less universally useful.

But Emacs predates CUA by a couple of decades, and supports easy access to an insanely wider (two, three orders of magnitude) space of functionality.

If you want CUA, Notepad is 100% conformant.

Disclaimer: Yes I would adore a clean pure new Emacs, but given the dearth of Stallmans, the new Emacs would take even longer to not have CUA by default.

Re:Emacs’s Builtin Elisp Cheat Sheet by morelisp on Wednesday July 06, 2022 @01:50PM (#32004414)
Most people today would freak out given only CUA cut/copy/paste though. It's also too old.

Panta rhei - you can either pick a tool that comes with you, or deal with switching at each stop on the river.

Re:Emacs’s Builtin Elisp Cheat Sheet by abrax3141 on Wednesday July 06, 2022 @02:12PM (#32004699)
Without the kill ring I would have to kill myself :-)
Re:Emacs’s Builtin Elisp Cheat Sheet by robonerd on Wednesday July 06, 2022 @03:30PM (#32005668)
> But Emacs predates CUA by a couple of decades

Only a couple of years if you're taking GNU Emacs specifically. About one decade if you're talking about editor macros for TECO.

Re:Emacs’s Builtin Elisp Cheat Sheet by msla on Wednesday July 06, 2022 @10:41AM (#32001708)
I absolutely love the default Emacs keystrokes.
Re:Emacs’s Builtin Elisp Cheat Sheet by nanna on Wednesday July 06, 2022 @11:38AM (#32002556)
Me too! I've always been baffled by the hate. If you come from vim, just use evil, install Doom Emacs or whatever. End of the day it's all just arbitrary muscle memory so once you get used to it all other keybindings (bar perhap vim) seems absurd.
Re:Emacs’s Builtin Elisp Cheat Sheet by robonerd on Wednesday July 06, 2022 @03:35PM (#32005733)
Evil-mode is incredible, for me Emacs with evil is the best vi-derived editor in the world, beating neovim and vim by miles. But as an ex-Vim user and fairly recent Emacs convert I feel like a guest in a clubhouse full of old timers. It wouldn't be right for me to swagger around their domain, demanding they change things up to accommodate me. Evil mode is already a much warmer welcome than I'm entitled to, so what if it takes a line or two to configure? I'm very grateful to have what I have now, I don't need or want Emacs defaults changed.
Re:Emacs’s Builtin Elisp Cheat Sheet by vq on Wednesday July 06, 2022 @11:55AM (#32002802)
I do too.

I'm one of those weirdos that disable transient-mark-mode because I don't feel like it does the right thing for all situations where you use mark. Sometimes I want to use mark like a cheap bookmark and C-x C-x between mark and point, sometimes I use the rectangle commands and for those transient-mark-mode only makes things worse.

(I know the CUA mode has some fancy rectangle features, but that's not for me)

Re:Emacs’s Builtin Elisp Cheat Sheet by mickeyp on Wednesday July 06, 2022 @11:59AM (#32002860)
I wrote about marking and exchanging point and mark without activating TMM:

https://www.masteringemacs.org/article/fixing-mark-commands-...

Also, the CUA rectangle stuff's actually mainlined and can be used without CUA (`C-x SPC')

Re:Emacs’s Builtin Elisp Cheat Sheet by vq on Wednesday July 06, 2022 @01:53PM (#32004450)
I didn't know about C-x SPC, thanks for the tip!

I enjoyed your article but I think the solution for me is to leave TMM disabled, though it makes me curious about what else I've missed in the last decade(s). You just made a sale of your book.

Re:Emacs’s Builtin Elisp Cheat Sheet by mickeyp on Wednesday July 06, 2022 @04:09PM (#32006152)
Thanks :) Enjoy! Shoot me an email when you've read it. I'd love to hear about what you've learned.
Re:Emacs’s Builtin Elisp Cheat Sheet by mickeyp on Wednesday July 06, 2022 @12:01PM (#32002889)
Same. They're generally very good, and there's a lot of logic and fluidity to how movement and editing combine.
Re:Emacs’s Builtin Elisp Cheat Sheet by rollcat on Wednesday July 06, 2022 @01:02PM (#32003768)
Me too :) One of the reasons why I fell in love with macOS - every text editing widget in the whole OS is very consistently using the basic Emacs keys like C-a, C-e, C-k, C-y, C-t, etc. That also makes Xcode (and most other IDEs) much less awful right out of the box ;)
Re:Emacs’s Builtin Elisp Cheat Sheet by jasonm23 on Thursday July 07, 2022 @12:36PM (#32016168)
Doom emacs is excellent at getting you past that nonsense. Built around straight.el so semver, Sha, tag, branch pinning is fully covered.

If vim bindings aren't your bag that's not a problem either.

Worth a look.

(Source : Some old geezer who's been hand coding an emacs config since the 90s, Doom has allowed me to throw a lot of it away.)

Re:Emacs’s Builtin Elisp Cheat Sheet by rawoke083600 on Wednesday July 06, 2022 @11:13AM (#32002211)
Try Doom Emacs :)
Re:Emacs’s Builtin Elisp Cheat Sheet by robonerd on Wednesday July 06, 2022 @03:24PM (#32005577)
> basic stuff like CUA

I don't care for the defaults either, but I also don't care for CUA, so if you had your way the defaults would be just as objectionable to me as they are now. Since you can't make everybody happy, I think the best way forward is to continue the status quo, so at least you won't be forcing configuration on users who were previously fine with the default.

Re:Emacs’s Builtin Elisp Cheat Sheet by medo-bear on Wednesday July 06, 2022 @03:48PM (#32005890)
i too dislike CUA. if you use the terminal CUA usually does not work and insteas we get CUA-ish hacks. emacs bindings are usually readily available on the other hand
Re:Emacs’s Builtin Elisp Cheat Sheet by taeric on Wednesday July 06, 2022 @03:41PM (#32005818)
You have me intrigued. What do you like/use?
Re:Emacs’s Builtin Elisp Cheat Sheet by robonerd on Wednesday July 06, 2022 @06:54PM (#32007903)
evil-mode

In other applications I mostly avoid the ctrl-v/ctrl-c and use X's highlighting and middleclicking system instead. When those aren't available, I actually prefer context menu copy/paste entries to the CUA shortcuts.