1. 37

I’ve seen a lot of stories posted about setting up vim. I’ve used vim for quite a long time now and I’ve seen a lot of vimrcs in my time, but I almost never see how people setup emacs. I’ve taken a new interest in lisp lately and I was curious how people setup emacs.

Anyone wiling to share their setup? Maybe some tips for an emacs newbie?

  1.  

  2. 28

    Resist the urge to get to deep into someone else’s configuration files: you are likely to pull in too much and confuse yourself. At least that’s what happens to me :)

    Start with your .emacs and I’d suggest really getting into use-package. As you start to need to bring in Emacs modes, you can add use-package stanzas for the modes you are bringing.

    As an example, this invocation will go grab the latest PlantUML mode and install it (the :ensure-t) and set up initialization info.

      :ensure t
      :init
      (setq plantuml-jar-path "~/plantuml.jar"
            plantuml-default-exec-mode 'jar)
      (add-to-list 'auto-mode-alist '("\\.plantuml\\'" . plantuml-mode)))
    

    use-package is really a killer way to build your Emacs config up.

    1. 9

      You’ll find as many opinions as people on this, but I’ve found use-package encourage a form of cargo cult configuration among newcomers. I personally fell into the trap of having a huge init file and knowing nothing about how it worked, because it was all implemented through the nice, declarative, high-level use-package.

      Only when I took a step back and ported it to vanilla Emacs did I start to understand. Ran that for a year or two, and recently went back to use-package, confident in knowing what low-level steps it compiles to.

      (Oh, and by the way, use-package has a keyword for setting up auto mode based on file name, so you don’t have to set that up manually!)

      1. 3

        For newcomers? Maybe, but use-package really cleans up the init.el or if you’re a weirdo like me org mode files compiled into->init.el.

        Note I’ve used .emacs/.emacs.d/init.el route for a long time before I found use-package, having done it the hard way i’ve no real desire to go back to raw elisp with all the setq/add-to-alist stuff.

        1. 1

          It does abstract incredibly nicely over common patterns, but as a new user it’s hard to get a grasp on how it does this, which means it’s great while it works well but really difficult to diagnose when it does not. Unless, of course, one has done this manually before, in which case it is obvious what happens under the bonnet.

      2. 5

        I agree with this approach, and I’ve set up a very minimal self-bootstrapping config for using use-package with quelpa and quelpa-use-package. This gives you a couple benefits:

        • All your packages are defined and configured in your init.el using use-package, and the use-package forms are also what install the packages.
        • The entire thing can install itself and all the packages you use just by writing the config file and starting Emacs.
        • Thanks to quelpa and quelpa-stable-p, you can install from MELPA Stable by default, but still install packages that aren’t available on MELPA Stable when necessary. This is really hard to achieve with the normal Emacs package interface.

        This is what it looks like to set up a package from MELPA Stable with this setup:

        (use-package fsbot-data-browser :quelpa)
        

        And this is what it looks like to set up a package using regular MELPA:

        (use-package gruvbox-theme :quelpa (:stable nil))
        

        You can also install things that aren’t on MELPA at all using the same setup:

        (use-package ac-php :quelpa
          (:stable nil :fetcher github :repo "xcwen/ac-php"
           :files ("ac-php.el" "company-php.el")))
        

        I’ve written a blog post about it, and the GitHub repo with the config file and a description of how to use it is at https://github.com/Benaiah/quelpa-use-package-bootstrap-config.

      3. 17

        I use DOOM Emacs, after a lot of deliberation. I’d used a vanilla Emacs config for the good course of 4 years before realizing that DOOM did everything I was already doing, and doing it faster.

        My config is literate, and tangled automatically by DOOM’s doom command-line utility. You can find the entire config here if you’re interested.

        Also, if you’re planning on using any form of language server via LSP mode, I’d recommend building the Emacs 27 pre-release: its native JSON parser makes it far faster.

        1. 10

          I also migrated from my own bespoke literate Emacs configuration to doom. It’s feature rich and fast. It feels like I switched from Linux from Scratch to a regular distribution.

          1. 8

            I too did the great migration from vanilla Emacs to Doom recently, and wrote about it: https://blog.jethro.dev/posts/migrating_to_doom_emacs/

            I don’t really miss my old config, but haven’t fully gotten used to the keybindings in Doom.

            1. 5

              +1 to DOOM. I switched from Vim to Emacs in maybe ‘15 for the Clojure support (CIDER is a must-have) and maintained my own config because I didn’t see anything attractive I wanted to adopt at the time. I recently decided that my homebrewed config was far too slow and a pain to maintain and made the switch to DOOM which has been almost entirely win. I’ve ported a few bits here and there forwards, but overall with evil-mode turned off I find even stock base DOOM excellent.

              1. 3

                Ok, DOOM is fast, but your config could be just as fast. I mean, I managed to pull of those those startup times and loadings (with margin of error of few or tens of mili seconds which are tolerable).

                People just don’t read documentation of use-package. (or aren’t using it at all which is even worse) I made my config lazy in mathematical sense, don’t load anything unless I start using it. Rest are minor tweakings and tricks but you get the idea. With a bit of work your config could be just as fast. If you must have vim configs than it’s fine, I’ll choose DOOM over spacemacs any time of the day.

                1. 3

                  Yeah I’m another doom emacs convert. I started off working with a literate emacs config. It was painfully slow no matter what I did. Doom starts almost as fast as vim, even faster once the daemon is running.

                2. 12

                  Just use it. As you find demand for something, google it, ask around, try different things and eventually you will have the thing that you wanted (whether you write it yourself or install as a package). I just don’t recommend going for out of the box things like Spacemacs or other people’s configurations (it’s ok to look at parts of it, but the point of emacs is that everyone can use it differently).

                  1. 3

                    totally agree. I tried to use centaur and doom. But, it was too much too soon. Now I have a small config that I have been adding to, and it works great and works just like I want it to. Just googling what you want usually does the trick for whatever you are looking for next.

                    1. 2

                      I used to try to do things on my own, and then switched to Spacemacs and it was like jumping ahead 30 years in time.

                    2. 11

                      spacemacs is a great way to get started if you’re a vim user. I’ve been using it for a long time and I’m very happy with it

                      1. 4

                        It’s also a great way to get started if you’re not a vim user. It supports standard keybindings too, and these days the develop branch asks you which you want on install.

                      2. 8

                        My advice is to use the default configuration, install the modes you need (if they’re not there by default) and only change things if something in particular bothers you, or if you’re doing the same thing repeatedly and there’s no shortcut or built-in function for it. Learn to use the help system (C-h …), the customize system (M-x customize) and the package manager (M-x package-list-packages). Search the Emacs Wiki or Ergo Emacs for help on extensions and how to use ELisp and different modes.

                        Using another person’s customization misses the point. The great thing about Emacs is that it’s easy to customize for yourself, to suit your own needs and your own environment.

                        1. 9

                          Learn to use the help system (C-h …),

                          Critical advice and so easy to forget! Glad you mentioned it. Emacs has fantastic built-in help.

                        2. 8

                          Lots of good advice here already, but I haven’t seen straight.el mentioned yet. It’s a package manager focused on reproducible builds, and it produces a version lockfile that you can check in.

                          It’s a godsend if you need to set up a new machine and just have everything work; Emacs’s builtin package manager doesn’t support version pinning particularly well. It also integrates seamlessly with use-package.

                          Otherwise I agree with the general advice to start barebones and add stuff as you need or want it. You’ll definitely appreciate evil (Vim keybindings) coming from Vim, though.

                          1. 7

                            I asked a similar question a few years back when I wanted to reboot my Emacs setup. Someone advised me to check out Spacemacs and I did. I’ve been using it for a few years now, and I like it. It’s a “distribution” of Emacs that comes with a number of packages (“layers”) that are easy to enable (and have documentation!) and a consistent nemonic for accessing functionality. As a Vim user you may be interested in the VI emulation mode, which is the Spacemacs default. I use it in Emacs mode, myself.

                            1. 4

                              I’ve played with Spacemacs off and on and always have run into issues with input lag and with it being a leaky abstraction. I’m not surprised or too bothered by it being a leaky abstraction, since I can google (as a verb, not a proper noun) and I have decent knowledge of Emacs Lisp, but the stutters and random lag are very annoying (far worse than any Electron app I’ve used, including Atom, which isn’t wonderfully optimized). What do you do to get around that? I’m still using Neovim because it feels like a very sharp tool compared to any big Emacs configuration.

                            2. 6

                              I have a massive nix expression that builds an integrated emacs with everything I accreted over the years: https://git.sr.ht/~jack/nix-overlay/tree/master/jack-emacs

                              This is because I went all-in on nix. I don’t regret it, but you can probably do just fine with (use-package foo :ensure t) to pull in everything you need.

                              The best way to get into emacs is to start with stock emacs, and as you find the things that slow you down, pull in tools that solve those problems. I have accreted a lot of useful stuff over the past 16 years, and see no need to switch editors in the future.

                              My emacs config went through three eras:

                              1. First, I was manually installing all the packages I used into a dir that I could copy between computers. This worked until 2013 or so, when updating packages got too hard.
                              2. (use-package) did me well for multiple years.
                              3. I nixified it all in 2019. The major payoff is not having to worry about whether or not the necessary tools are present on my computer. They’re pulled in by the nix expression.
                              1. 4

                                I’ve declared .emacs bankruptcy three times so far. According to my git log, the most recent one was in 2014, and things are looking god so far. So I guess it’s not that bad. The first one was in 2008 or so, and I’d been using Emacs for about eight years by then, but I’d only been capable of writing useful elisp for about two or three of these.

                                My current emacs config is actually very straightforward and built with as little customization in mind as possible, which is deliberate, because it’s clear to me that I won’t be able to let go of Emacs too soon. Consequently, I don’t want to spend more than an hour a year caring for this thing.

                                Here’s the big picture.

                                ~/.emacs.d/init.el does a couple of globally-relevant things, like setting up the load path, inhibiting the startup screen and there’s the inevitable custom-set-variable blob because I’m lazy. Other than that, it just requires a bunch of stuff under ~/.emacs.d/elisp, which is where all the (non-melpa) goodies are.

                                These goodies include a bunch of stuff written by myself + configuration files. I have one config file per “relevant thing”, such as:

                                $ ls -1 elisp/config*
                                elisp/config-appearance.el
                                elisp/config-c-mode.el
                                elisp/config-company.el
                                elisp/config-gud.el
                                elisp/config-html-mode.el
                                elisp/config-kbd-shortcuts.el
                                elisp/config-load-save-hooks.el
                                elisp/config-mediawiki.el
                                elisp/config-packages.el
                                elisp/config-slime.el
                                elisp/config-ui.el
                                elisp/config-xcscope.el
                                

                                I try to prune it periodically – there are various things that I don’t use anymore (e.g. config-mediawiki.el up there will probably be thrown away at the next spring cleaning).

                                There are a lot things that I don’t use regularly enough, like go-mode and whatnot, which I deliberately try not to customize at all. This way the maintenance burden is pretty light – I love Emacs and I love Lisp but I don’t have the kind of free time that I had twenty years ago. If I’m not gonna use something more than a few weeks a year, I’d rather just learn the defaults than spend additional effort maintaining configuration for it. I only change keybindings if they clash with global keybindings of my own.

                                I have mixed feelings about things like spacemacs. I tried it twice, most recently one or two years ago, I think? Maybe I’m not in the target audience, or I overestimated my experience with Emacs, but honestly I didn’t really like it. It’s pretty heavy and, at least back then, changing anything non-obvious seemed to have a pretty big chance of breaking something in ways that aren’t obvious even for me. I’m not really sure why this would be useful for a new user except as a demo of what emacs can do.

                                I don’t think I have any super special secret tips for Emacs newbies, but some of the things that helped me in the beginning included:

                                • Using Emacs like any other editor, and customizing it as I felt the need. Especially back when I didn’t know too much Lisp, I used Emacs pretty much like UltraEdit with weird shortcuts and a somewhat unwieldy configuration interface. (UltraEdit, my second-favourite editor in the whole wide world, wasn’t available for Linux back then). There’s very little point in spending time tweaking features you’re not going to use.
                                • Reading the manual, forums and whatnot (that used to be mailing lists/newsgroups but times have changed…). Nowadays there’s Sacha Chua’s Emacs news series: https://sachachua.com/blog/ which I read semi-regularly. I use maybe 0.01% of those things, but I make a note of them, and when I need them, I know they’re there. The great thing about using fourty year-old software is that it can definitely do things you never even thought you’d need.
                                • Learning Emacs Lisp. It’s a great interactive text processing engine and a few minutes of hacking can save you hours of manual churn. And, on a more personal note: I probably wouldn’t have seen things twenty years ago when being l33t was super important but IMHO, unless you really like some specific feature of Emacs, there’s not much point to using it if you don’t do some scripting of your own. Pretty much any feature you can think of (save maybe for things like org-mode, which I don’t really use so I wouldn’t know…) is implemented in other editors as well. Scripting things is a lot more effort in most of them, but if you’re not gonna do that anyway, why care about it :-)? The Emacs community seems to be somewhat divided on this matter. I can see where the “other” camp is coming from, I guess it’s a matter of priorities and what you want to spend time on at the end of the day.

                                Edit: needless to say, if you wanna know anything, just ask :-)

                                1. 3

                                  Some thoughts:

                                  • Do the builtin tutorial.
                                  • Don’t cargo cult others’ configs.
                                  • Do look into use-package, and use it to install packages/modes you need.
                                  • Be aware of and use the various describe-* functions (e.g. M-x describe-mode but many many things can be described).
                                  • Have fun!
                                  1. 3

                                    I use a pretty stock doom-emacs with only a few additional packages

                                    Unlike vim I find emacs to be much harder to simply copy others configs. Probably due to have insanely configurable emacs is, but at least it gets me to stick close to stock (with doom as “stock”).

                                    1. 3

                                      I’d definitely like to echo the general sentiment here that you should just make your own config from scratch, but absolutely use use-package. I haven’t completely converted everything over to use-package, but I really should some day. You should err on the side of package minimalism until you’re really frustrated with something in base emacs. I also do recommend evil-mode if you’re coming from vim. evil-mode is absolutely incredible, and it’s better than vim in some regards.

                                      That being said, here’s my config and some highlights:

                                      https://github.com/wraithm/emacs.d

                                      • My theme solarized-dark (there seems to be fewer color schemes that look nice in emacs, solarized isn’t my favorite, but it’s the best one that works in emacs)
                                      • flycheck is pretty good for most projects
                                      • eshell is pretty cool. You should check it out.
                                      • ibuffer for buffer management
                                      • ivy-mode, this is a fuzzy completion framework, and you’ll see why it’s nice after you use emacs for a while. I like it more than helm. Helm is too heavy, imho.
                                      • compilation mode, this is an under-used feature of emacs. I see lots of people using emacs switch to terminals to do compilation. You should set up a compile command and just let emacs do it for you. M-x first-error takes you to the first error in the output of your compile command.
                                      • Company mode is a completion framework. I don’t really use many of the language specific company modes, but it’s nice for just basic completion support in a buffer.
                                      • emacsclient is really neat. I run emacs as a server, and then I connect to it with a GUI emacsclient and also terminal emacsclient. I even aliased vim to emacsclient in my shell config… Hard to defeat muscle memory.
                                      1. 3

                                        For the first few years, I mostly used M-x customize and changed things when they were pissing me off, and then I didn’t need to do too much with the config itself.

                                        Later on, I got irritated with how slow Emacs was at starting up and then I threw away my config and rebuilt it with use-package and I’m satisfied with that for the most part.

                                        I have the same config on different machines, and I got some mileage out of this trick:

                                        (load-file (concat "~/.emacs.d/hosts/" (system-name) ".el"))
                                        

                                        This way, I have a ~/.emacs.d/hosts/foo.el file for each host with host-specific stuff in it.

                                        It can be worth reading other people’s configs to see hidden configuration options that you’ll want, like disabling the bell or making yes-or-no-p into y-or-n-p. There are a lot of useful packages for Emacs; you might want to look at smex, magit, company, flycheck, spaceline/powerline for starters.

                                        1. 3

                                          I would search github for ‘dotfiles’ repos and/or for .emacs. There is a lot.

                                          1. 3

                                            I’ve got a list of threads like this bookmarked.

                                            There are a bunch of different ways to go about it. I’ve been playing with doom-emacs lately, but I’ve also got a fairly well-maintained custom config as well.

                                            My personal config is reasonably modular and fairly easy to follow: https://github.com/belak/dotfiles/tree/master/emacs.d

                                            My doom config is very new and evolving: https://github.com/belak/dotfiles/tree/master/doom.

                                            A very common pattern is using use-package, as it really cleans up your config into easier to manage blocks.

                                            I’m happy to clarify if you have any questions. Thankfully the built-in help is fantastic and people in the Emacs IRC channel/emacs-doom discord server have been very helpful as well.

                                            1. 3

                                              A few points:

                                              • I had a few nice things being said about my configuration, so it might help you too.
                                              • Opposed to what some here are saying, I think reading other configuration is quite helpful, especially if they are written in a literate style (I have listed a few in 1.3 Inspirations for writing this configuration). This way you get to “meet” interesting variables, hook or other options that one would usually miss. The only qualification would be that one should need to have some basic lisp understanding.
                                              • Remember the keybindings “C-h v” (to look up a variable) and “C-h f” (to look up a function), and that way you’ll quickly learn a lot about Emacs.
                                              • Generally, try to stick close to vanilla and feel no shame in using the Customize subsystem (M-x customize). I still think this is better than going for Emacs distributions.
                                              1. 3

                                                There’s a huge variation in people’s emacs configs. You can use those that people post publicly as a guide, but my advice is to start using Emacs and add to your configuration gradually.

                                                Some public ones you may like: https://github.com/jwiegley/dot-emacs https://github.com/munen/emacs.d https://sites.google.com/site/steveyegge2/my-dot-emacs-file

                                                One of the first things you’ll want to do is to be able to install manage packages from Melpa. Follow the instructions here: https://melpa.org/#/getting-started

                                                Then just fix things that annoy you. For example, I like my buffer to fill the whole display, so I disable some things at startup:

                                                (defun lose-superfluous-stuff()
                                                  "remove stuff I don't like, like scroll bars and tool bars"
                                                  (interactive)
                                                  (if (fboundp 'scroll-bar-mode) (scroll-bar-mode -1))
                                                  (if (fboundp 'tool-bar-mode) (tool-bar-mode -1))
                                                  (if (fboundp 'menu-bar-mode) (menu-bar-mode -1)))
                                                

                                                I very rarely change default keys, but some people completely customize the layout. If you like Vim you may want to use Viper mode.

                                                This one is a must if you don’t like beeping in the middle of the night:

                                                ; turn the annoying beep off 
                                                (setq visible-bell t)
                                                

                                                If you’re on Mac this is a handy tip. You can use mdfind instead of the linux locate command. Makes it easy to search for things on your system…

                                                ;; set locate to use mdfind
                                                (when (eq system-type 'darwin)
                                                    (setq locate-command "mdfind"))
                                                

                                                Most of the rest of my config file is decades old and commented out. Things like programming language configuration, binary paths, colour themes. Pretty much everything like that I don’t bother with anymore, I simply use Doom Emacs. I wouldn’t recommend it unless you’re already familiar with Emacs though.

                                                1. 3

                                                  Here is my Emacs setup. I blogged about this fresh. https://muratbuffalo.blogspot.com/2020/03/my-emacs-setup.html

                                                  I use kjhealy’s starter-kit

                                                  1. 2

                                                    I’ve used it for about 13 years now, yikes.

                                                    • I started with an empty .emacs and customized for my hands, keyboard, and laptop. I’ve standardized on a single ergonomic keyboard, my keybindings are designed for less stress on my hands.

                                                    • I have the emacs file set up to properly manage osx/windows/linux, even, mostly, terminal linux. This lets me have a single point of contact for serious editing in any environment I use.

                                                    • I slowly have added libraries, packages, and functions over time. I need to do a real overhaul of my .emacs and see whats out there that I can use. Maybe this summer.

                                                    • I compile my emacs for my machine, generally. This just makes me happy.

                                                    1. 2

                                                      For anybody looking for a vanilla kit with low entry keybindings configurations, checkout Magnar’s .emacs.d repo. That’s what I currently use with some custom configuration per language and task for my setup.

                                                      1. 2
                                                        1. Everyone saying “use use-package” is correct. Add only the packages you are learning as you start to learn them and you will be fine.

                                                        2. Keep your emacs config under version control. I use a git repo.

                                                        3. Use the Emacs key bindings. You quickly get used to not hearing the screeching brake sound of context switches as your productivity increases.

                                                        4. The very start of my .emacs file, before setting up use-package, is:

                                                          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
                                                          ;; Early setup to avoid any momentary flashes
                                                          ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

                                                          ;; Remove window decorations

                                                          (if (fboundp ’scroll-bar-mode) (scroll-bar-mode -1))
                                                          (if (fboundp ’tool-bar-mode) (tool-bar-mode -1))
                                                          (if (fboundp ’menu-bar-mode) (menu-bar-mode -1))

                                                          ;; Don’t show the splash screen
                                                          (setq inhibit-startup-message t)

                                                        1. 3

                                                          (setq inhibit-startup-message t)

                                                          Ah, but why not take it up a step and, for example, start up with your configuration?

                                                          (setq initial-buffer-choice "~/.emacs.d/init.el")
                                                          
                                                        2. 2

                                                          As someone who has used emacs a minimal amount (I did use it for Org-mode and magit for a few months), I’d definitely recommend starting with a minimal setup, and/or learning the undo command (I forget what it was, but I remember it was key for me to get going).

                                                          For me, I used melpa, Evil, org-mode and magit, and that was pretty much it on top of stock emacs.

                                                          1. 2

                                                            I’m a little late to the party, and there’s an overwhelming response to this post (which is great to see!), but I figure I’ll share my thoughts - keeping it short and sweet.

                                                            Personally, I’ve built my config up slowly over the years with quite a lot of additional functionality.
                                                            The way I keep this sane:

                                                            1. Use use-package - as many others have suggested here
                                                            2. Make your configuration literate. A common approach, and the one that I use, is to write it in org mode and tangle it when starting up (see my init.el and readme.org below)
                                                            3. This is perhaps a point that others might not have made, and one that I feel is vital: in your literate configuration, above the package expression, explain what the thing is, why you have it, and elaborate on any additional config you’ve got set there. Not only does this help other people stumbling across your configuration understand what they’re looking it, it also helps you reason about the worth of that config.

                                                            Here’s my configuration: https://github.com/cmacrae/.emacs.d

                                                            1. 2

                                                              I’m still interested in getting into Emacs if someone can show me how to consistently have the <Tab> key work like Vim (i.e. reliably insert some number of spaces, and never delete spaces). Regardless of which mode or minor mode or whatever I’m in. It really feels like a hodge-podge how Emacs modes each make their own decisions about keybindings. Too clever for my taste.

                                                              1. 2

                                                                Looks like you’re having problems with major modes overriding parts of the global keymap. If you want a custom set of key binds that consistently override the global keys and mode-specific keys, one solution might be to create a minor mode with an associated keymap, because they override major modes.

                                                                (This is heavy in terminology, so feel free to ask for clarifications.)

                                                                1. 2

                                                                  Thanks for the hint. Here’s what I cooked up so far:

                                                                  $ cat .emacs
                                                                  (define-minor-mode tabs ""
                                                                    :init-value t
                                                                    :keymap
                                                                      (let ((keymap (make-sparse-keymap)))
                                                                        (define-key keymap [tab] (insert-tab))
                                                                        keymap))
                                                                  

                                                                  But, no dice. M-x tabs seems to toggle the ‘tabs’ minor mode. But it doesn’t actually seem to have any effect. Hitting <Tab> still indents.

                                                                  Do you see anything obvious I’m messing up? Thank you.

                                                                  Edit: I eventually hit upon the strategem of googling for bits from my answer. And this page seems to suggest I have the right solution :thinking_face:

                                                                  1. 2

                                                                    If you want the minor mode to be global, consider adding a :global tto the definition. From the docstring:

                                                                    :global GLOBAL

                                                                    If non-nil specifies that the minor mode is not meant to be buffer-local, so don’t make the variable MODE buffer-local. By default, the mode is buffer-local.

                                                                    1. 2

                                                                      Thanks, I tried that as well. Here’s my current version:

                                                                      (define-minor-mode tabs ""
                                                                        :global t
                                                                        :init-value t
                                                                        :keymap
                                                                          (let ((keymap (make-sparse-keymap)))
                                                                            (define-key keymap [tab] 'insert-tab)
                                                                            keymap))
                                                                      

                                                                      I also tried that page’s solution as-is:

                                                                      (defvar just-tab-keymap (make-sparse-keymap) "Keymap for just-tab-mode")
                                                                      (define-minor-mode just-tab-mode
                                                                        "Just want the TAB key to be a TAB"
                                                                        :global t :lighter " TAB" :init-value 0 :keymap just-tab-keymap
                                                                        (define-key just-tab-keymap (kbd "TAB") 'indent-for-tab-command))
                                                                      

                                                                      No luck. I’m on Mac OS.

                                                                      1. 2

                                                                        It is basically the same (except for the function being used), the only major difference is that you are using a map as a value, while they are re-defining the key every time the mode is set or unset.

                                                                        What exactly isn’t working? What are you expecting? Perhaps check if the key is correctly bound with C-h k.

                                                                        Edit: How does this look like:

                                                                        (defun insert-simple-tab ()
                                                                          "Reliably insert some number of spaces."
                                                                          (interactive)
                                                                          (let ((indent-tabs-mode nil))
                                                                            (insert-tab)))
                                                                        
                                                                        (defvar simple-tabs-mode-map
                                                                          (let ((m (make-sparse-keymap)))
                                                                            (define-key m (kbd "<tab>") #'insert-simple-tab)
                                                                            m))
                                                                        
                                                                        (define-minor-mode simple-tabs-mode
                                                                          "Minor mode to globally bind `insert-simple-tab' to tab."
                                                                          :global t)
                                                                        

                                                                        It seems to do what you want, but that being said, the behaviour is quite weird, and will shadow some of emacs features bound to tab (such as in org-mode or magit). I guess is comes down to what you’re used to (I would hate to use an editor with a different tab behaviour, but again just because I’m used to it), but fighting the editor like this is something one should always reconsider – not that Emacs doesn’t make it possible – just that it might not be worth it.

                                                                        1. 2

                                                                          Yeah, I hear you about going with the grain of the editor. At this point it’s just a curiosity why it’s not working for me on my laptop. Here are the steps to reproduce:

                                                                          $ cat .emacs
                                                                          (defun insert-simple-tab ()
                                                                            "Reliably insert some number of spaces."
                                                                            (interactive)
                                                                            (let ((indent-tabs-mode nil))
                                                                              (insert-tab)))
                                                                          
                                                                          (defvar simple-tabs-mode-map
                                                                            (let ((m (make-sparse-keymap)))
                                                                              (define-key m (kbd "<tab>") #'insert-simple-tab)
                                                                              m))
                                                                          
                                                                          (define-minor-mode simple-tabs-mode
                                                                            "Minor mode to globally bind `insert-simple-tab' to tab."
                                                                            :global t)
                                                                          
                                                                          $ emacs -nw .zshrc
                                                                          

                                                                          At this point I position the cursor at the + below:

                                                                          fignore=(.swp .o .class .pyc .fasl
                                                                                   .cmi .c+o  # ocaml
                                                                                   .aux .bbl .blg .sty  # latex
                                                                                  )
                                                                          

                                                                          …and hit <Tab>. Expected result:

                                                                          fignore=(.swp .o .class .pyc .fasl
                                                                                   .cmi .c  +o  # ocaml
                                                                                   .aux .bbl .blg .sty  # latex
                                                                                  )
                                                                          

                                                                          What I observe (cursor still at the +):

                                                                          fignore=(.swp .o .class .pyc .fasl
                                                                              .cmi .c+o  # ocaml
                                                                                   .aux .bbl .blg .sty  # latex
                                                                                   )
                                                                          

                                                                          Does your suggestion do something different on your computer?

                                                                          1. 2

                                                                            I get

                                                                            fignore=(.swp .o .class .pyc .fasl
                                                                                     .cmi .c+       o  # ocaml
                                                                                     .aux .bbl .blg .sty  # latex
                                                                                    )
                                                                            

                                                                            which is what you wanted.

                                                                            Could it be that macs have tab bound in some other way? I know macs handle the meta key in some other way, but tab should still work?

                                                                            1. 2

                                                                              Thank you for trying it out! I’ll look around for some other Emacs distro for Mac.

                                                                            2. 2

                                                                              Might be that <tab> feeds to be TAB. Also worth reading about how Emacs handles special keys during input: https://www.gnu.org/software/emacs/manual/html_node/elisp/Translation-Keymaps.html

                                                                2. 2

                                                                  I use emacs with little configuration.

                                                                  First thing to know is you navigate a buffer mostly with search C-s and C-r. Then you can navigate files with C-b or C-f. At last there is bm extension. And marks.

                                                                  Also I extensively rely on silverlining-search mode-ag which allows to grep for file (or use M-x rgrep)

                                                                  Use C-g or ESC to escape the mini-buffer.

                                                                  My .emacs only contains specific bindings for the above.

                                                                  1. 2

                                                                    Then you can navigate files with C-b or C-f.

                                                                    Those two are backward-char and forward-char, do you perhaps mean C-x C-b and C-x C-f?

                                                                    1. 2

                                                                      yes you are correct.

                                                                  2. 2

                                                                    An emacs config will teach you the power of documentation.

                                                                    If you do not comment the why, motivation, etc, to some lines in your config, you won’t know when you can remove something decades down the line.

                                                                    I’d do the following:

                                                                    • play with emacs, along with it’s default keybindings for a while, hack up a personal config, however you’d’ like, but use as few packages as possible.

                                                                    • after a few months of that, try out the evil binding based distributions (DOOM, spacemacs).

                                                                    • decide whether or not to include evil mode in your emacs config.

                                                                    Your config will probably live for years - put it in version control.

                                                                    Personally, my emacs config is here.

                                                                    1. 2

                                                                      I started with Vanilla Emacs 20 years ago and have gradually built up a config by adding modes and packages I needed + working around annoyances.