reddit / emacs

Help me get c++ tab completion working :)

[deleted] · 2022-04-21 17:34
I really like how default elisp tab completion works. if you set `(setq tab-always-indent 'complete)`, pressing tab in elisp buffer first correctly indents, and then if indented it "tries to complete the thing at point" basically autocompletes, by calling `completion-at-point`. i have eglot and clang installed, and i expect the same behavior in c++ buffer, but pressing tab, only calls `c-indent-line-or-region`. doing M-x `completion-at-point` or C-M-i works, but its far less convenient that just using tab key. I'm aware that there are other packages that do implement compilation for you, but i try to use built in stuff as much as possible.
repelliuss · 2022-04-21 23:28
(with-eval-after-load 'cc-mode (defun c-indent-then-complete () (interactive) (if (= 0 (c-indent-line-or-region)) (completion-at-point))) (dolist (map (list c-mode-map c++-mode-map)) (define-key map (kbd "<tab>") #'c-indent-then-complete))) This should do what you want. You may want to check if `tab-always-indent` is set to `'complete` somewhere according to your style. There is also `c-tab-always-indent` but it doesn't take `'complete` and I don't know why it is duplicated.
[deleted] · 2022-04-22 08:46
>ty <3