6 ms·
I eagerly tried this out, and unfortunately it doesn't fix the biggest stumbling block for me: Emacs's tab behavior. Coming from Vim, I never. ever. want to hit
by akkartik 5y ago
I eagerly tried this out, and unfortunately it doesn't fix the biggest stumbling block for me: Emacs's tab behavior. Coming from Vim, I never. ever. want to hit Tab and see nothing happen. Regardless of how strongly my editor thinks it knows best, hitting Tab should insert some spaces. I'll even accept indenting the current line the first time I hit Tab. But if I hit Tab a second time, follow my other preferences and insert some character(s).
And in 5 years I can't for the life of me configure this! No solution transparently sets this default for all time. Every new fucking file type I try to edit needs me to go around in circles fixing this stupid behavior.
Sigh. Back to Vim, I guess. I don't understand why this doesn't come up more often in all the blog posts about transitioning to/from Emacs.
- tomcam 5y agoI too am interested in the Tab question
- lvass 5y agoHave you tried hooking self-insert-command to the modes you'd use it on? Like prog mode and fundamental. The only corner case I can think of is if you'd like to tab-insert in org-mode and also expand headings using tab. Edit: Try this: (defun indent-for-tab-command () (interactive) (insert-char #x20 4))
- alex_smart 5y ago>I don't understand why this doesn't come up more often in all the blog posts about transitioning to/from Emacs. Because most people who use Emacs like this behaviour. Also considering that this post promises a relatively vanilla editing experience, you shouldn't expect a solution to your particular problem. > And in 5 years I can't for the life of me configure this! It is not that hard to solve this. It is extremely easy to map any key in Emacs. You can just map Tab key to insert a tab if that is what you want. It will be like two lines of elisp. Edit: The reason most Emacs users don't find the tab behaviour a problem is: a, Emacs indents correctly more often than not and b, you can insert a literal tab character when you want using 'C-q Tab'.
- lvass 5y agoYou can't just blanket remap tab as it's overloaded for org-cycle, helm-select-action, expand in ido and so on.
- alex_smart 5y agoYou can remap it in global map, or prog-mode map, so it would keep the customized behaviour in other modes.
- akkartik 5y agoThank you! global-map did the trick for me, though I seem to have tried it a few years ago without success: https://news.ycombinator.com/item?id=29726398#29731027 https://news.ycombinator.com/item?id=29726398#29731027
- CyberShadow 5y agoFighting against idiomatic Emacs keybindings is an uphill battle, but the hill is not very steep. The recipe that works for me: 1. Bind the behavior you want in the global map. (global-set-key (kbd "<key-here>") #'the-action-you-want) 2. Any time you encounter a mode which overrides this key, press C-h k <key-here>. It will tell you the name of the map in which the key is bound (usually foo-mode-map). Then, add: (define-key foo-mode-map (kbd "<key-here>") nil). This will unmap the key from the mode's map, revealing the binding in the global map.
- akkartik 5y agoThank you! This is very actionable.
- deleted 5y ago[deleted]
- tabemacsthrow 5y agoYou want to create a minor mode (minor mode overrides major mode key bindings) and have the minor mode enabled globally. use-package has a bind-key* function that does this I think. Something like (check the syntax, I haven't tested it) (require 'bind-key) (bind-key* (kbd "tab") (lambda () (insert " "))) And you should probably construct the number of spaces from the tab-width variable.
- akkartik 5y agoThanks! I'll look into this in combination with https://nullprogram.com/blog/2013/02/06 https://nullprogram.com/blog/2013/02/06 the next time I try out Emacs.
- tabemacsthrow 5y agoNo, bind-key* should do this for you automatically. If you wanted to do it yourself you would make a minor-mode manually. There's also general-override-mode-map from the "general" package. edit: Looking at the code I don't think bind-key* creates a minor-mode but it still does what you want (and is probably the recommended way).
- akkartik 5y agoOh! Let me try that.
- akkartik 5y agoHere's what I have so far: * I installed Emacs 26.3 using `sudo apt install emacs` * I installed Melpa by following https://github.com/melpa/melpa/blob/master/README.md#usage https://github.com/melpa/melpa/blob/master/README.md#usage * I installed use-package using `M-x package-install use-package` Now I'm trying to make sense of your instructions while reading https://github.com/jwiegley/use-package#readme https://github.com/jwiegley/use-package#readme. I don't see a bind-key*, but I do see: - bind-key - bind-keymap - bind-keymap* Should I try one of those instead? They all seem to be in the context of a `(use-package ...)` declaration. Edit: Never mind, I do see it now at https://github.com/jwiegley/use-package/blob/master/bind-key.el https://github.com/jwiegley/use-package/blob/master/bind-key... Edit 2: I just tried it and it didn't work. Turns out I've tried this approach in the past: https://lobste.rs/s/whaez0/emacs_everywhere#c_l6ez9w https://lobste.rs/s/whaez0/emacs_everywhere#c_l6ez9w (edit 2 there, heh) Wait, the suggestion at the top of that comment now works for me on a few different file extensions! (setq-default tab-width 2) (setq-default indent-tabs-mode nil) ; to insert a tab anyway: C-q TAB (define-key global-map [tab] (lambda () (interactive) (insert-tab))) Thank you!