236 points · by User23 · 3y ago · 142 comments
I have made a starter kit at leverages many of the now built-in features of Emacs 29.1. You can get very far with regards to completion, project management, language, server, etc. just by tweaking a few defaults. I have put some of these nice tweaks together in a starter kit called “Emacs bedrock“: https://sr.ht/~ashton314/emacs-bedrock/
Let me know if you find it useful, or if you have any comments or suggestions. :-) I’m still working on incorporating some feedback I got earlier.
It's that lil' layer of configuration that's missing that makes the first clash with emacs sane. I like the structure. I also like the fact that there's a 'researcher' mixin. Would absolutely love to see your opinionated inclusion of org-roam, and general.el.
I recently dabbled into System Crafters' 'Emacs from Sratch' series [0], which is incredibly well thought-out. After 5 hours of following it, you kinda get feature parity between his config and this; but in Berock's case it's done more natively which is really, really neat. I only miss some basic config with general.el.
I feel super lucky to have started in Emacs when they finally added LSP and Treesitter support, and with System Crafters' help and yours!
[0] https://www.youtube.com/watch?v=74zOY-vgkyw&list=PLEoMzSkcN8...
I've also read the linked blog post about avy and forced myself to get familiar with it. Jumping all over the screen is great (I set it up jump across all visible frames in my tiling wm). I'm going to investigate consult et al next (already use vertico and orderless).
I’m so happy to hear you’ve found some helpful things from bedrock! Happy hacking!
Absolutely! What I like about them is how they each focus on doing one thing well, making use of built-in functionality so they all work well with the rest of Emacs. It makes a nice change from the bigger packages which are so featureful they become hard to understand.
I've had a better experience tweaking the configuration in Lua as well. I never tried neovim's starter frameworks (NVChad, LunarVim, etc) so I can't compare them to emacs's. I was never able to use well emacs's frameworks because either they were too convoluted ann hard to customize or kept crashing.
Also when opening or formatting large files (sometimes not so large) emacs would freeze for a very long time. Also, LSP was not around, or was in its infancy, so my experience with code completion and intellisense was very poor, but perhaps that has changed.
Finally, emacs's plugin called "Magit" is a godsend and I lack a similar tool ever since.
With all that said emacs was very special for me because it fueled my passion for open software and being able to control and customize the tools I use. I really hope it got better and keeps kicking!
Takes a little while to acclimate, but it's very useful once you're used to it.
- The ecosystem is sometimes difficult. There is always a lot going on in terms of various completion frameworks and spellchecking. It is cool, but often you choice will have some consequences down the line. You like eglot, as a simple and faster alternative? Fine. But it does not support DAP, now you have to pull heavy LSP, treemacs and other 30 packages.
- Treesitter is a chance missed, they've introduced alternative mods for it, with a separate names, which makes it necessary to rewrite the hooks and generally makes a huge mess for no good reason. I guess, the reasoning was like "we do not want to force an external dependency", but there is simply no good reason to regex parsing if you have treesitter and it will be the standard, I am quite sure. Some kind of config switch for a mode would be a better solution.
- It is notably slower than neovim. I cannot describe it, it is more of a "micro-stutter here, micro-stutter there" feeling. It is more visible if you intend to use it for everything or as an IDE replacement, as an advanced editor emacs has a fine performance.
- The UI is... I don't know, I can never predict where a buffer will appear. Emacs in general will pop up a lot of buffers. Sometimes you can close them with q, sometimes you will have to hide them. "Inconsistent" is the word which comes into my mind.
- Org is outstanding as a technical outliner, so-so as a GTD tool. Sync problems and lack of good mobile clients shows.
- Configuring and introspection are good. I still have no idea how to debug my neovim config, for example, it is a non-issue in elisp, you don't even need to restart it, just eval parts of you elisp code!
- Embark is also a very very cool idea.
- Modern completion frameworks are good, vertico, marginalia, orderless - they are easy to configure and very performant. I just like Telescope in neovim more, since it looks better and shows a bigger code preview.
- Evil is a very good vim-like layer, but also quite heavy and sometimes you will have to deal with emacs keybindings. They are not bad, though, it makes sense to learn at least the basics. Due to evil I will leave the keybindings out in general, you can have it either way in emacs. Evil is the best vim implementation outside of vim/neovim.
I've settled on neovim with fish shell, git in console and occasionally lazygit and it is fine. It is hard to describe, but a focused, fast and composing editor is very pleasant to use. I also find neovim more aesthetically pleasant, although it is really just a personal perspective. But what is certainly is, is being simpler. Maybe it is just a natural consequence of aging, but I recognize a lot of value in simple tools: A lever espresso machine instead of a microcontroller-ridden monstrosity with a tablet attached, go instead of rust, console tooling instead of an IDE. Neovim just fits in.
It was not the optimal solution, agreed. The reason was actually that a significant technical complexity was found while trying to adapt the existing modes. The syntax table vs. tree-sitter parse tree was simply too divergent for a mode to be just switched from one to the other. So the decision which I don't think anybody was completely happy with, but considered the only feasible way to move forward, to have new modes with tree-sitter.
You can see some discussion here: https://old.reddit.com/r/emacs/comments/15g9cna/why_is_emacs... and quick link to the mailing list thread: https://lists.gnu.org/archive/html/emacs-devel/2022-12/msg01...
I fixed that by redefining in my config split-window-preferred-function to my own function, which is responsible for the placement of new windows in a way that makes sense to me (which is something that no other piece of software does actually).
In my workflow I embrace the chaos: commands/mode open windows as needed and I use winner-mode to restore my layout.
For example, if I have two side-by-side code windows open and I open magit with c-x g, it will create a new vertical split. Once I'm done with magit, I can use winner-undo once (or thrice depending on what magit ops I did) and it restores the original layout.
Some things in Emacs never change, no matter how many bells and whistles are in the latest version. :)
I just published my newly hand-rolled config https://github.com/adityaathalye/dotemacs
At some point if/when I upgrade to 29.1, I will be able to delete some lines such as the ones that install use-package. :)
I've found the configuration is surprisingly easy to read even tho I haven't seen lisp for 10 years. I think it's atrocious that many keybindings start with <C-x>, but it's easy to set it to another key (mine is <C-j> with capslock as <C>) so not a big deal.
My biggest complain so far is that the whole ecosystem is Unix-first. People say once they get used to Emacs they almost stay in it all day long. And even as an Emacs newbie I can confidently say these people all use Unix-like systems.
On Windows magit is really slow. Like much slower than any git GUI I've seen. And while eshell is usable, it feels rather primitive and not like a proper terminal. The default spellchecker option doesn't work on Windows either, but hunspell seems ok-ish (still a bit slow).
I understand that no one is oblige to write any software for my OS, but stil...
Edit:
The reason I don't use WSL: the last time I tried it, it was really slow when a windows process read from/wrote to a file living in linux file system, and vice versa. One obvious solution is to move as many file as possible to WSL, but I'm just not mentally ready to change my workflow that much.
Edit 2:
For people who like to try Emacs, I'd suggest to turn `which-key` on and install helpful-key. It's a software with the premise that you need to learn obscure key combinations.
> To improve the use of proprietary systems is a misguided goal. Our aim, rather, is to eliminate them. We include support for some proprietary systems in GNU Emacs in the hope that running Emacs on them will give users a taste of freedom and thus lead them to free themselves.
It doesn't. Stallman hand-waved the "taste of freedom" nostrum to avoid throwing away the man-years supporting emacs on Windows and Mac. The same stupid argument was made to justify the new Android port.
Emacs + evil mode has been my primary text editing environment for 7 years now.
Note that you can use things like `pcomplete` and `eshell-syntax-highlighting` to make eshell fairly smart. The fact that my shell can use corfu and the same completion, filtering, and ordering as the rest of my emacs is great.
Unfortunately, WSL's GUI support is extremely buggy on multimonitor setups (and maybe elsewhere), so you may have to restart your Emacs session often to get window management or even just clicking around to work right.
Xpra (or even a full X server, if you don't mind losing X clients on sleep) has been a lot better on the integration front.
Source: I benchmarked git on windows and decided it wasn't worth trying to fix it.
You are meant to press Ctrl with your right hand when you press C-x. Those who came up with these keybindings had this way of using in mind. If you remap it to C-j, it becomes inconvenient because you need to switch between left and right Ctrl in the middle of a chord (though, in some cases this is inevitable). Also, many keybindings are configured so that you can do both C-x (some key) and C-x C-(some key). That is you don't need to release Ctrl in the middle. But, if you change to C-j, then this becomes difficult to execute. Imagine pressing C-j C-m (or C-jm) for example.
Bottom line: not a good idea.
As for Windows: (I haven't used it roughly since Windows 7, and even then only in one work place that required it). How does the OS affect whether you close Emacs between sessions or not? Or is it still the case that you need to reboot Windows a lot?
Also: Magit wasn't always very slow on Windows (although both Git and Magit are and were always slower on Windows, but the magnitude varied at times). As someone who used Magit long before current maintainers took over: it evolved, but not always in the ways that I would like it to. The original Magit is quite a bit less organized (internally, in the way it's coded), but it's a lot simpler and in some ways more intuitive to use.
Modern Magit went through a cycle where they tried to do some performance optimizations, but then they added more features, and the performance gains were lost. Today, Magit is plagued with performance issues, and is a very complex (and a very unfriendly) program to debug: it's neigh impossible to get to the source of errors or trace the performance offenders. But, it's still better (at least on Linux) than anything else I tried by a large margin. So, I'm ranting about performance, but will keep using it anyways.
I've been using Emacs for several years now, and I think the real solution is to turn Caps Lock into another Ctrl.
The right Ctrl key is in a very uncomfortable position whether I press it with my pinky or with the base of my hand, so in practice I basically never use it. The left Ctrl key is not as bad, but it's still not comfortable if I need to press it often. Caps Lock, however, only requires a slight adjustment of my left pinky finger to press. Simultaneously pressing x with my left ring finger is slightly weird, but not uncomfortable. There are some other keys on the left side that don't really comfortably combine with left Ctrl or Caps Lock, but I don't run into them often enough for it to be a problem.
In the beginning of my exposure to Emacs I did rebind CapsLock, but that offered little relief. The true quality of life improvement comes from not pressing Ctrl+<anything> with the same hand. Anything that requires Meta or Ctrl -- automatically use both hands.
When I used a traditional keyboard I rebound ctrl to be next to space so I could easily hit it with my thumb so the layout was like:
[super][alt][ctrl][----space----][ctrl][alt][super]
But now I use a split keyboard(Kinesis Advantage) with ctrl/alt/super in thumb clusters that make hitting those modifiers really easy.Nothing's stopping you from doing it that way, but since Steele and Moon started writing EMACS in 1976 on the PDP-6 and the PDP-10 and probably used VT52 terminals to access those systems, you're probably expected to have a control key on the home row to the left of the caps lock. The VT52 does not have a control key on the right side of the keyboard. I've found that Emacs's ergonomics are greatly improved by swapping the caps lock and left control keys on modern, IBM Model M-inspired keyboard layouts.
Even if the 76's Emacs wasn't designed for it, most people with decades of Emacs experience would start salivating just from looking at this keyboard. I believe, that when anyone using Emacs is designing key bindings, be it today, ten or twenty years ago -- they think about something like Space Cadet.
I'm not sure what it means since I just pressed <C-j> <C-m> and I had zero issue about this. I stated in the first post that I use capslock as ctrl.
> How does the OS affect whether you close Emacs between sessions or not?
I didn't say that I close Emacs between sessions. I meant (I supposed) some Unix people use tools like vterm and magit so they don't even switch to another terminal app. I instead constantly switch between Emacs and Windows Terminal.
> Windows Terminal
Why not use shell from Emacs instead? Emacs has a bunch of terminal emulators. One of those ought to work decently on Windows...
If you do it the way you describe, you will set yourself up for a painful experience. Because Windows Terminal (most likely) doesn't have the editing capabilities of Emacs, and (most likely) it doesn't use the same navigation / editing scheme as Emacs, you will have to switch between the two and make mistakes in both of them. It's really annoying to work like that, and it causes people who chose Vi or Emacs to use or to configure other tools to work in the same way their preferred text editor does it. But, ideally, they'd just want the other tools to be embedded in their editor (because any customizations they make for the editor will automatically extend to those tools).
Having to deal with switches in how you write or navigate text is similar to having a crying baby nearby or a loud pub etc. Most people wouldn't willingly put themselves in that position.
https://magit.vc/manual/magit/Microsoft-Windows-Performance....
I wish I could use Linux but I work in the gaming industry ina company that solely creates windows games so it’s not really an option…
That said, magit is the star of the show.
(use-package go-mode :ensure t
:hook ((go-mode . (lambda () (setq tab-width 4)))))
And it works the emacs way, not trying to be something more "modern" (i.e. VS Code), which to me is so much nicer than all the lsp-ui nonsense that I was using before (no popups, docs show up in the minibuffer as it ought to).¹ https://emacsredux.com/blog/2023/07/30/emacs-29-1-released/
Love this in the context of native SQLite support.
It looks like it's in Text > Database in the "Emacs Lisp" manual, not the "Emacs" manual.
This is the best thing since idk. Thank you so much, folks!
I'm also not happy about the fact that I can no longer open large C++ files like https://github.com/ASDAlexander77/TypeScriptCompiler/blob/ma... in C++ mode without scrolling becoming so sluggish as to be unusable. I either have to disable C++ mode or open them in an older version.
It's good that emacs is getting some long needed attention, but I'm sad the latest version isn't as usable for me.
Regex-based syntax highlighting is usually the culprit in these cases. There’s probably a new RegEx inside c++ mode that burns too many cpu cycles.
You might want to try out the treesitter mode „c++—ts-mode“ that does the syntax highlighting based on a real static parser written in C: https://medium.com/really-learn-programming/setting-up-tree-...
Disclaimer: I’m not a C++ dev so I have never tried that.
The author made this story available to Medium members only. Sign up to read this one for free.
/sigh
I am still not a competent C++ programmer but this is how your basic tree sitter C++ mode is supposed too look with "C-h m":
Minor modes enabled in this buffer: Auto-Save Flycheck Flyspell
Font-Lock Yas
The major mode is C++// mode defined in c-ts-mode.el:
Major mode for editing C++, powered by tree-sitter.
This mode is independent from the classic cc-mode.el based
‘c++-mode’, so configuration variables of that mode, like
‘c-basic-offset’, don’t affect this mode.
To use tree-sitter C/C++ modes by default, evaluate
(add-to-list 'major-mode-remap-alist '(c-mode . c-ts-mode))
(add-to-list 'major-mode-remap-alist '(c++-mode . c++-ts-mode))
(add-to-list 'major-mode-remap-alist
'(c-or-c++-mode . c-or-c++-ts-mode))What typescript mode are you using? Emacs 29.1 comes with "typescript-ts-mode" providing parser based syntax highlighting and navigation. Traditionally, re-indentation is implemented using regex based syntax tables, too, so you might enhance your experience by switching over to that newer mode.
________________ M-x emacs-version
GNU Emacs 29.1 (build 1, x86_64-apple-darwin18.7.0,
NS appkit-1671.60 Version 10.14.6 (Build 18G9323)) of 2023-07-30
________________ M-x describe-mode (for C++)
Minor modes enabled in this buffer: Font-Lock Tree-Sitter-Hl Tree-Sitter
The major mode is C++//l mode defined in cc-mode.el:
Major mode for editing C++ code.
Using CC Mode version 5.35.2
________________ M-x describe-mode (for ts)
Minor modes enabled in this buffer: Font-Lock Tree-Sitter-Hl Tree-Sitter
The major mode is TypeScript mode defined in typescript-mode.el:
Major mode for editing typescript.
;;; typescript-mode.el --- Major mode for editing typescript
;; URL: http://github.com/ananthakumaran/typescript.el
;; Version: 0.4
;; Keywords: typescript languages
;; Package-Requires: ((emacs "24.3"))
________________ os
% uname -srm
Darwin 19.6.0 x86_64
% sw_vers
ProductName: Mac OS X
ProductVersion: 10.15.7
BuildVersion: 19H15> Minor modes enabled in this buffer: Font-Lock Tree-Sitter-Hl Tree-Sitter
> The major mode is TypeScript mode defined in typescript-mode.el:
> Major mode for editing typescript.
This actually indicates that you are in fact using some tree sitter extension for doing "font-locking". Do you happen to have installed "elisp-tree-sitter" in the past? Perhaps this setup has some bugs. Or your font-locking is still running regexes in your mix.
This is how typescript mode looks for me using Emacs 29.1's built-in tree sitter support:
Minor modes enabled in this buffer: Auto-Revert Auto-Save Company
Eldoc Flycheck Flyspell Font-Lock Lsp-Headerline-Breadcrumb
Lsp-Modeline-Workspace-Status Lsp-Ui-Doc Lsp-Ui Lsp-Ui-Sideline Yas
The major mode is TypeScript mode defined in typescript-ts-mode.el:
Major mode for editing TypeScript.
(I am also running "lsp-mode.el" so there are more minor modes running than perhaps in your case.)So, I would remove any tree sitter extension you may have installed in the past. Then to activate the new "typescript-ts-mode" you need to do the following:
1. Clone this repository: https://github.com/casouri/tree-sitter-module/
2. run "./build typescript" (you'll need build-essentials and a C++ compile but I gathered you are programming in C++, so)
3. Copy the resulting shared library "dist/libtree-sitter-typescript.so" into "~/.emacs.d/tree-sitter/".
4. Open a random typescript file and try "M-x typescript-ts-mode" which should not give you any error but nice syntax highlighting.
5. Of course, you'll need some tweaking to make it your default. Basically, you'll have to add "'typescript-ts-mode" to your "'auto-mode-list".
You'll have to do the same for your C++ setup. U̶n̶f̶o̶r̶t̶u̶n̶a̶t̶e̶l̶y̶,̶ ̶t̶h̶e̶ ̶c̶o̶n̶v̶e̶n̶i̶e̶n̶c̶e̶ ̶"̶t̶r̶e̶e̶-̶s̶i̶t̶t̶e̶r̶-̶m̶o̶d̶u̶l̶e̶"̶ ̶b̶u̶i̶l̶d̶ ̶s̶c̶r̶i̶p̶t̶ ̶d̶o̶e̶s̶ ̶n̶o̶t̶ ̶s̶u̶p̶p̶o̶r̶t̶ ̶C̶+̶+̶ ̶o̶u̶t̶ ̶o̶f̶ ̶t̶h̶e̶ ̶b̶o̶x̶.̶ ̶B̶u̶t̶ ̶i̶t̶ ̶d̶o̶e̶s̶ ̶n̶o̶t̶ ̶l̶o̶o̶k̶ ̶c̶o̶m̶p̶l̶i̶c̶a̶t̶e̶d̶ ̶t̶o̶ ̶e̶x̶t̶e̶n̶d̶ ̶i̶t̶ ̶f̶o̶r̶ ̶y̶o̶u̶r̶ ̶p̶u̶r̶p̶o̶s̶e̶s̶.̶ Nonsense, it is supported: Just run "./build cpp". You also seem to need "./build c". This way, I was able to activate the new C++ treesitter mode.
If you do not want to go ahead and migrate to built-in treesitter yet -- as you see it's still a bit fiddly to setup as it is brand new -- I would tackle your C++ performance problem first by using Emacs' profiler:
1. M-x profiler-start (select "CPU")
2. Open your C++ file slowing your Emacs down.
3. M-x profiler-stop
4. M-x profiler-report
and see what it gives you. Perhaps post an issue with the Emacs maintainers and they can give a clue where your issue comes from. But usually something like this is caused by a run-a-way regex.
Good luck!
Also I feel like performance could be improved a lot, but that's probably an issue in my particular setup.
If someone has an efficient lsp-mode + typescript-mode + eslint checks, I'd be happy to see how you achieved that.
JSON is okay if you need a format that is human readable but how did the engineers at microsoft ever think that it was a good choice for interprocess communication?. Most of the work is wasted on decoding the json itself. We should not have to increase the interval between request and batch calls in order to make it usable.
I wanted to query the LSP server to tell whether the point was currently located within a string, but as far as I could tell, the LSP server couldn't be queried for the syntax type. You can ask for "selection suggestions", you can ask for "semantic tokens" within a specific range, but you cannot ask for the semantic token containing a single specific point.
Further details...
... from the same source as the top post: https://www.masteringemacs.org/article/speed-up-emacs-libjan...
... from lsp-mode: https://emacs-lsp.github.io/lsp-mode/page/performance/#json-...
that seems extremely unlikely, Treesitter is a vibe-based parser framework for syntax highlighting and indentation of single files, LSP is arbitrary language-specific processes doing full-project parsing and analysis and introspection.
Would you mind to share your setup?
I am using „lsp-mode.el“ on a Perl project with >100k LOC (including huge single modules) and never had a problem. I am using cperl-mode together with lsp-mode and Perl::LanguageServer and it works like charm. I also never had an issue with React or TypeScript but in those cases the projects were a lot smaller.
Perhaps you also got an issue with JSON parsing performance. Edit: From someone a couple of threads below: https://emacs-lsp.github.io/lsp-mode/page/performance/#json-...
it's very very cool that this late in the world of computers we ~suddenly get cross-editor analysis system (LSP) and cross-editor highlighting/indentation/rough parsing support.
I'm happy that TreeSitter is in Emacs Core rather than elisp, it'll run faster.
On the other hand, package upgrades are still blocking with Emacs‘ built-in package manager. I hear „straight.el“ is a good replacement capable capable of running async but it’s an advanced sub system.
Do you have some examples?
I’m just glad that you can still compile a minimal emacs without dbus.
This way I discovered a lot of helpful stuff.
Mickey doesn't do this for profit. There's a word in Japanese - "Ikigai" (you better google it, I'm typing this on my phone).
For Mickey Petersen, explaining Emacs is his ikigai.
If you're thinking of using Emacs for longer than two weeks, buy the book, you will never regret it.
I'm not the kind of person that can read a manual cover to cover, but I pick one up occasionally, open a random page and find something interesting/useful.