Bad Emacs defaults
idiomdrottning.org
idiomdrottning.org
Specifically, 'one indent is four spaces, two indents is one tab, repeat', which caused utter carnage for newbies editing YAML files since literal tabs aren't valid YAML.
Back in the day, I built consensus to switch the perl https://p3rl.org/Catalyst framework over to defaulting to an apache style config in the scaffold generator specifically because about 75% of our "confused newbie" questions on IRC at the time were people whose emacs config had broken their YAML config file.
Of course we're -ahem- a few years on from that now, and people generally have already had at least one pitched battle with YAML before installing/adopting another thing that uses it, but still, oh gods but that was frustrating for a while.
If your language has a convention, then likely Emacs implements it. If not, you can send a patch to fix it.
Also with homeassistant I was "forced" to write a lot of yaml by hand and also never had real issues. Maybe its because emacs handles writing yaml fine. Anyways. I like yaml.
Their emacs configs didn't.
Hopefully most distros' default emacs installs do the right thing these days but it's not something I've checked because these days pretty much everybody already has a setup that works for YAML because of how prevalent it is.
(I like YAML for just-about-human-editable data structures but then people try to text template it rather than actually treating it as data and then I want to cry)
But as a default for any mode that cycle is ... nuts. Though I'm sure there must have been some reason for it.
The standard tab width (in most software, not just emacs) is 8. Basically nobody wants that much indentation, so your options are:
(1) Don't use tabs at all. Just use spaces. If space efficiency is a requirement, that eliminates this option.
(2) Use tabs only and change the tab width to match your desired indentation level. This is a simpler method. The downside is other people need to change their tab width to match yours. They may not want to, or their software may not support it. You have to decide whether you want to deal with that.
(3) Mix tabs and spaces. This is more complicated, but most software will display the files as expected without any tweaking.
TLDR: Tabs save disk space, but tabs are too wide, and changing tab width is a hassle, so mixed tabs/spaces is a compromise.
EDIT: Both the Linux and BSD kernel coding style specify tabs for indentation, and a tab width of 8. The Linux guide says it best: "In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep. Heed that warning."
And, yet, that becomes so much religious dogma that people will shoot themselves in the foot.
I fixed a lot of network locking code way back when. I made sure that I had a validation framework to go along with it. It was a gigantic state machine, because that's what locking and protocol are.
But, you know, that thing had single exit point and 4-5 indent levels and extended past 80 characters because it was a goddamn state machine, had states and variables lifted directly from the specification state machine, and tested as a state machine with the validation suite.
But, hey, the kernel devs just had to rewrite it to match 2 indents and 80 character lines. So, they did.
And took 9 months until they passed the validation suite again. They didn't add a single feature. They didn't fix a single bug. But, hey, they dedented it real good.
What finally did the deed was that one of the senior devs finally got fed up, went back to my original code, wrote a Perl script (that's how regular my code was) to rewrite every state block into a function with extremely short, unintelligibly cryptic names and args in order to remove two levels of indent and make sure the function calls would fit in 80 characters.
The final kicker: someone genuinely found a real bug about 5 weeks afterward. They tried to fix it in the "better" code with less indents. They couldn't figure out which state was the problem because they mangled all the names. I went into my old code, fixed it, added a test to the suite and reran the refactoring script--and that's how the bug got fixed.
We're not developing on punch cards and VT100s anymore people--quit being stupid.
(Side note: the main issue that bit the devs is that people who are dogmatic about 2 tabs-80 characters tend to rely on early return to avoid fully-fleshed if-then-else which cause deeper chains. This does not work for state machines. There is no early return--every state should leave at exactly the point when you advance from the old state to the new state at the atomic swap. So, you can do what the senior dev did and cryptify everything, or you can just leave the damn state machine alone and accept 4 indents and 132 characters.)
Did you read the Emacs source much? They compensate by having functions span thousands of lines
...wait, what, why? Indentation is not meant for alignment, you should not do something like, say...
myAwesomeVariable: CoolType = frobnicate(moop,
mork,
mindy);
...it doesn't even look good, if you must have them aligned, do... myAwesomeVariable: CoolType = frobnicate(
moop,
mork,
mindy
);
...tabstop doesn't matter, you put your tabstop to 2 and it works, I get a fancy ultrawide monitor and put my tabstop to 8 and it still just works. The only problem is that you can't build a Christmas tree: x = 7;
da = 42;
foo = 666;
boop = 1812;
In other words, nothing of value is lost.In 2023, we've made that mistake enough that there's a consensus not to do it. But when these defaults were chosen, there was wider variation in styles. (There wasn't even a consensus on how to format braces in C.) Expecting people to never do that would have been a pretty opinionated default.
Also, you touch on another issue: terminal width and wrapping lines. Back then you couldn't just tell people to make their window wider. Their response might be, "At 80 columns, it's already the full width of my screen." Or going back further, "What's a window?"
So "apparently under some distro configs in some circumstances it does that" is pretty much all I bothered to find out, because the config data structures people were mostly expressing worked fine with a less touchy format. (and this was only the -default- format configured by the scaffold, if you handed the config system a YAML file it was still happy to load it)
Today I learned why sometimes my YAML files seemed inexplicably to end up with tabs in them.
For example, I would argue that MOST modern text editors treat a tab as approximately 4 spaces, not 8 spaces.
Exactly how said "some configurations" came to be I never figured out, it may have been a particular set of distro defaults.
;; Basically, I was laboring under the impression that
;; `sentence-end-double-space' was telling Emacs the /right/ way to do
;; end-of-sentence spacing, but really it's just letting it know how sentences
;; work. So setting it to nil lets you do sentence-level stuff, even on people
;; who are /wrong/. So great.
I assume they were mostly kidding and this was only meant to be funny, but I learned the 2 spaces thing in college and then didn’t discover until a couple years ago that it had fallen out of fashion decades earlier, even before I went to college. IIRC the reason for the 2 spaces rule is because you need it in print, for non-fixed-width fonts, where the space character is really narrow. I think I even read that there never was a 2-space rule for fixed-width fonts? (*Edit just to say I think I (mis)remembered this story completely backward, and the corrections below are accurate. Print had different sized spaces already, typewriters need 2 to match.)Anyway. I loved emacs back in the day, and for a long time, but over many many years my .emacs file bloated up to like a megabyte. (That might* be a slight exaggeration, but I’m not sure.) I can’t maintain it anymore. I probably have a very very enormous list of bad emacs defaults.
But yeah, it's weird the effects of backwards compatibility... so many things decided 40 years ago, which we can't change because it would break someone's configuration.
[1] https://link.springer.com/article/10.3758/s13414-018-1527-6
i.e. if point is at the beginning of "This is Mr. Smith's hat. It is green." I want next-sentence to advance to "It", rather than "Smith".
I also gave in and started top-posting in email messages.
Then I realized that the 1st sentence was missing the extra space after the 2nd period, and then M-e jumped to the end of the first sentence.
In vim, hitting ) in normal mode stopped after each period.
Yeah, my comment rendered as HTML, which stripped the double-space from the original text I entered.
Using double-space means that the source document is unambiguous, thus you preserve options for whatever renders the text—keep the double-space, strip it, convert it to Unicode, etc.
EDIT apparently not
Edit: it would need context awareness too, which somewhat rules out espanso, otherwise space indentation will be difficult. abbrevs at least can be defined per mode, but ideally it would be based off the face (so it could work in comments or strings).
But it's still an extra keystroke. And I worry that I'd cause problems editing non-UTF-8 documents if I retrained my fingers to use it at the end of every sentence and then didn't remember to switch back to the ASCII way of doing things.
I definitely recommend doing some form of "dotfile bankruptcy" every 20 years or so :-)
(I also ended up doing a crude "load-file-literate" so that now most of my elisp is actually markdown, inspired by https://github.com/skx/dotfiles )
The wider form of whitespace is not easy to get out of regular text editors and word processing software, so some people choose to emulate it by entering two regular word separators. (This is too wide, though, if we are being precise.)
I didn't quite realize that was the reason for the double space until these comments, though, as we were simply taught that it was required to put 2 spaces after a period.
The comma, btw, was slightly wider.
Since it took me a minute to track down, here's the short of it so that I don't accidentally nerd-snipe anyone:
http://web.archive.org/web/20110820004307/https://www.funtri...
emacs-bankruptcy court is now in session. mr. dahart would you like to say something/anything before we begin ?
It's also more robust in case of errors. Emacs can write new data to a temp file, confirm it succeeded then rename working to backup and new to working. You never have a situation where the working or backup file ends up half written.
I'll also note that folks have been going back and forth about ^H & DEL at least since the 80s.
Hopefully, at some stage, make-backup-files will be set to nil. It is annoying to log into any server, launch Emacs and discover you have generated lots of litter. I think at this stage backup files should be opt in, not opt out.
If you place your emacs config in ~/.config/emacs it's pretty close to ideal.
But yes, remote backups... Happily, they are now controlled by tramp-backup-directory-alist, so you can have your cake and eat it:
(setq tramp-backup-directory-alist (("." . "~/.emacs.d/.local/cache/backup/")))Granted, hugo is handling this particularly gracelessly, but it's not the only thing that gets confused and upset by the dangling symlinks that point nowhere.
Yeah, it breaks other various compilers like ghc too.
I fix it with:
(use-package no-littering
:demand t
:config
(no-littering-theme-backups)
)
https://github.com/emacscollective/no-litteringOther than that: author has some very unique problems (changing fonts so often that they need to adjust how Emacs window fills the screen). Most people change fonts... never. A small fraction -- once or twice, at the time they install and configure the system. The author might be the only person in the world with that problem, but acts as if everyone does the same, and needs a solution.
Author doesn't understand why file backups are done they way they are done and advises to make them less reliable.
Putting all backups in the same directory will be inconvenient for files named in the same way.
C-h is one of the first keys anyone learns about Emacs and it's used all over the place in various combinations. Turning this functionality off in favor of a command that already has a key for it is just stupid.
Sentences need two spaces between them to distinguish them from acronyms, abbreviations and other uses of punctuation (like in proper names of products or references to pieces of code). This is the easiest way to deal with this problem. If you don't write two spaces at the end of a sentence, the editor will not be able to reliably determine where the sentence ends, and will screw up your formatting every now and then.
> command that already has a key for it is just stupid
backspace is one of the most inconvenient keys, so there is nothing stupid about replacing it with a much more convenient alternative (though the Ctrl default of Emacs is another bad default)
And he's changing the font size, not font
> Putting all backups in the same directory will be inconvenient for files named in the same way.
if only it were somehow possible to create subfolders or slighly change the names and store links in the backup...
Even when I used a more traditional "straight" keyboard I didn't have problems with it... Also, it's usually bigger than character and digit keys, so, really, it's not that hard to press it...
> so there is nothing stupid
I literally wrote what is stupid about it. Please take a minute to read the post you are replying to.
> if only it were somehow possible to create subfolders or slighly change the names and store links in the backup...
This is irrelevant. What if you rename the directory where you worked with files that need backups? Even worse, what if you switched two directories. Or deleted and created afresh... There are plenty of cases where renaming of backups will be very confusing / will do something you didn't intend and for zero gain.
You literally wrote what is stupid with two factors, I wrote why it's not emphasizing the 2nd, so? The frequency of use alone isn't enough, backspace is used even more frequently, so it's more important, hence, again, not stupid to swap
> for zero gain
The gain is mentioned right at the top of the post, so that's not zero
My response was relevant to the issue your raised with file names, your new what ifs are what's not relevant to that exchange
I didn't really have problems with this even though I too use a tiling manager (StumpWM).
Yes.
C-<wheel-up> at that spot runs the command mouse-wheel-text-scale
(found in global-map), which is an interactive native-
compiled Lisp
function in ‘mwheel.el’.
It is bound to C-<wheel-down>, C-<wheel-up>, C-<mouse-5> and
C-<mouse-4>.
(mouse-wheel-text-scale EVENT)
Adjust font size of the default face according to EVENT.
See also ‘text-scale-adjust’.
>the need me to zoom in / outI just prefer it, if I have little text, for it to be big. Why waste it on whitespace?
If you copy from unsaved file, you are risking to lose both the file you are baking up and the backup.
I don't know enough about filesystems to be sure, but I feel like there are more opportunities for stuff to fail with the move-and-copy technique. E.g. when moving the file it could end up existing twice (if creating the new link happens before removing the old one) or being lost (if removing the old link happens before creating the new one).
If you just copy the file, the copying can fail and you don't have a backup. But if the original is still fine then you never notice a problem with the backup, so this option is preferable (as I understand it).
> Most people would want to avoid hard links to editable files anyways.
Why would you want to avoid this? I though it would be something that Linux can easily handle.
1. Atomicity of Rename Operations: On many file systems, the process of renaming a file is atomic. This means that the operation either completes in full or doesn’t take effect at all. This makes it safer in cases where there might be interruptions, such as power losses. If the rename (which creates the backup in Emacs’s default behavior) is interrupted, you’re left with the original file intact.
2. Concern about Move-and-Copy Technique: Your point about the possibility of the file ending up existing twice or being lost is valid in theory. However, in practice, the renaming operation ensures that such intermediate states are avoided. A rename isn’t quite the same as creating a new link before removing an old one. Instead, it’s a reassignment of the file’s metadata, which is generally a reliable operation.
3. Drawbacks of Just Copying: While just copying the file might seem simpler, it can have issues. If there’s an interruption while writing the new copy, you can end up with a corrupted backup. With Emacs’s approach, since the original is renamed (and thus preserved in its entirety), you’re always assured of having at least one uncorrupted version.
4. Avoiding Hard Links to Editable Files: As for the avoidance of hard links for editable files, there are a few reasons:
Ambiguity: Editing a file that’s hard-linked elsewhere can lead to confusion since changes reflect in all linked locations. This can be unexpected for those unaware of the link.
Data Integrity: If there’s corruption in one location, it affects all hard-linked locations.
Backup Issues: Some backup systems might not handle hard links as expected, leading to either duplicate data or missed backups.
Linux does handle hard links well, but their usage needs careful consideration, especially when editing is involved. They’re great for static data that doesn’t change but can be problematic for editable files.
I hope this clarifies things!
4. That's an argument for raising awareness via better tools, not for avoiding the useful links
Think about what happens when your power comes back and you start editing that file again. Which is the correct version of the file? How can you tell? Suppose the backup file is newer than the original file, and 99% of the size. Is it a partial copy, or did the user delete some lines and then save?
Now consider what Emacs does by default when `backup-by-copying` is nil and the user asks Emacs to save a file:
1. Emacs deletes the existing backup file (atomic),
2. renames the existing file so that it becomes the backup (atomic),
3. writes the buffer content into a new file with a temporary name (not atomic),
4. calls fsync(2) to ensure that all written data has actually hit the disk¹,
5. finally renames the temporary file so that it has the user’s desired filename (atomic).
If the power goes off anywhere in the middle of that process, then no corruption will occur. The state on disk will be easily observable; it will either be a missing backup file but the original still exists untouched, or it will be a backup file but no original, or it will be a backup file plus a temporary file that might be incomplete, or it will be a backup file plus the new file.In all of these cases the editor can recover automatically without ever losing anything that was already saved on disk. Sure, in most of those cases we lose the _new_ data that wasn’t yet saved, but after all the power did go out in the middle of trying to save that very data. We’re not magicians here; this is the best we can do.
Of course, in practice the power doesn’t go out all that often and users habitually save the document after every few words, right? So backing up by copying is safe enough that most users who prefer it never lose any data. Probably. At least as far as they know; sometimes this type of corruption goes unnoticed, or gets chalked up to other factors such as inebriation or forgetfulness.
¹ We’ll ignore the fact that some operating systems have an fsync(2) that lies. See also <https://danluu.com/file-consistency/>.
By observing the status of a flag "wasBackupSuccessful", which wouldn't be set to true if there is a power loss after the file was copied (this flag could be set as an atomic rename operation on the copied backup file so that you could tell via the observable file system behavior whether the copy succeeded)
But it is now clear what you meant, thanks for the explanation!
Replace show-trailing-whitespace with automatically-deleting-whitespace, though.
(defun x/delete-whitespace ()
(unless (or (string= major-mode 'diff-mode)
(string= major-mode 'hexl-mode))
(delete-trailing-whitespace)))
(add-hook 'before-save-hook 'x/delete-whitespace)They have basically no css on that site. You should be seeing the default font of your browser. However, if you are browsing in dark mode you should see these colors and a text-shadow:
@media (prefers-color-scheme: dark) {body, a, a:visited {
color: #feec7c; background-color: #1e0708;
text-shadow: 0 0 3px #fde02d, 0 0 12px #b74312;}}
Maybe that shadow is the blurriness you are experiencing. Unfortunately I can't check, I don't even know how to switch my browser to dark mode.(Of course, $employer enforces whitespace style globally with a linter so the files here can't end up in a state where ws-butler is meaningful. Not sure what I prefer.)
I would expect that emacs being emacs it's trivial to configure such lines to be left alone when relevant, but it's worth remembering that the edge case exists.
```
code
```
of course as first characters of lines. It appears indented here on HN.I didn't know about the triple tilde.
(setq-default show-trailing-whitespace t)
(defun delete-trailing-whitespace-hook()
(add-hook 'before-save-hook 'delete-trailing-whitespace))
(add-hook 'ruby-mode-hook 'delete-trailing-whitespace-hook)
(add-hook 'python-mode-hook 'delete-trailing-whitespace-hook)
(add-hook 'lisp-mode-hook 'delete-trailing-whitespace-hook)> An extremely minimal Emacs starter kit uses just one external package by default, and only GNU-ELPA packages on an opt-in basis. Intended to be copied once and then modified as the user grows in knowledge and power.
(setq auto-save-file-name-transforms '((".*" "~/.emacs.d/autosave/" t)))
(setq backup-directory-alist '(("" . "~/.emacs.d/backup")))Edit: not just hard to read, but physically painful. I noped out of reading TFA because it’s not worth using my limited eye strain budget for the day.
- For the long-tail of software you can just ship it without worrying about the defaults or future backwards compatibility concerns because it won't hurt that many
- For popular software though the early defaults that work great for that era (and maybe a hundred people) will annoy all the tens of thousands of future users
It was like an editing PVP game where these would be fixed in near real-time by others in the document we were working on :-)
Yes the web text today removes these today but I still prefer reading text in the old RFC document style where it's not only fixed width fonts, but also right and left column justified. In emacs this can be done by selecting a region and doing a C-u ESC q
:-)
But at some point the emacs folks decided that in a X11 window, Ctrl-Z should be bound to the same kind of idea: it minimizes the window! So you're happily typing along and hit C-x <something> and... your window just disappears because you missed and hit the adjacent key. Terrible default, have had it disabled for decades.
;; Highlight end of buffer
(setq-default indicate-empty-lines t)
is my most important one, when i open a file i need to know where it ends, vim has his by default i am not even sure if you can disable it in vimThese two things are incompatible with using cut-and paste in Windows, not to mind some other OS. One reason I switched to vi was I found vi worked better in mixed workflow where I sometimes used an IDE like IntelliJ IDEA, used a lot of web applications, and did a lot of cut and paste, which “just works” with vi assuming you go into insert mode when pasting.
Also at the time I was doing a lot of sysadmining where I would have to use somebody else’s account where there might be no emacs and certainly not my customizations or be working on a broken machine where the package manager might well be screwed up so installing emacs is not easy, besides the stakeholders on that machine have gotten along fine without emacs so why install some package just for me?
I'm a fan of using packages that hook into Emacs defaults. Like providing data for xref for example.
Nonetheless, I do like mg!
au!
set noai
set sm
set cp
setf none
set nocindent
set nosmartindent
filetype off
inoremap <Left> <NOP>
inoremap <Right> <NOP>
inoremap <Up> <NOP>
inoremap <Down> <NOP>
noremap <F1> <NOP>
inoremap <F1> <NOP>
cabbr h you_typed_colon_h_again_you_idiot
nnoremap q <NOP>
autocmd FileChangedShell \* echon ""
set directory=/tmp
set mouse=
set ttymouse=
# try uncommenting this if angry fruit salad still ensues:
# syn off (setf dired-kill-when-opening-new-dired-buffer t)
To make dired not open a new buffer every time you navigate to a directory.Do you use tabs and have "workspaces" where each may have a dired buffer?
Which is not an unreasonable topic for an article though as it happens I disagree with almost all of them.
Emacs is a perfect case of “YMMV — and you can adjust it”.
I've come to the conclusion that Emacs is a black hole, and people who profess their love for it in 2023 are likely exhibiting some form of the sunk cost fallacy. Life is too short to spend all your time configuring it.
That said, I don't think you can draw too many conclusions about Emacs from how difficult it is to turn Doom into your own bespoke setup. It abstracts a huge amount, drastically changes default behaviours, and basically needs an entire new ecosystem of Doom compatible packages, of varying quality, to make it work. I often advise that even if people plan to go Doom or Spacemacs, they should spend a week or two trying out vanilla Emacs with their own customisations applied as they go.
Not only do people tend to warn up to them, but even if they still choose to go down the Doom/Spacemacs/Whatever route, they have a better understanding of what's being abstracted away, and how to sometimes glue things back together when something breaks.
Therefore, I dropped Doom Emacs and am very happy with my new clean Emacs config.
Critisizing sophisticated tools though, that's like saying we should go back to drafting tables rather than use autocad because the learning curve is steep. Once you learn the tool it accelerates everything you do.