8

I've installed auto-complete-mode, and I'm using org-mode. When I hit TAB to auto-complete words, it instead tries to indent the line. Sometimes it indents the whole paragraph, sometimes it does nothing.

I tried customizing the variable (setq tab-always-indent 'complete) and changing it to nil, but now when I hit TAB, it just inserts tab spaces across the screen.

I know it's possible to successfully use org-mode with yasnippet and auto-complete both working correctly, because with Emacs Live it works out of the box.

Cœur
  • 37,241
  • 25
  • 195
  • 267
incandescentman
  • 6,168
  • 3
  • 46
  • 86

3 Answers3

11

Auto-complete uses the variable ac-modes to decide whether to enable auto-completion in a particular mode, by default org-mode is not present in this list. So to enable auto-completion in org-mode simply add it to the ac-modes something like this should work

(add-to-list 'ac-modes 'org-mode)

Also to complete using tab you will need to set ac-trigger-key to tab like so (link to the manual)

(ac-set-trigger-key "TAB")
  • Thanks. Unfortunately that doesn't work. Auto-complete-mode is on, displaying the `AC` in the mode line. I can trigger completion by doing `M-x auto-complete`, but TAB still has no effect. – incandescentman Feb 26 '14 at 15:00
  • What does `C-h k` `tab` give? Does it give something like `TAB (translated from ) runs the command ac-trigger-key-command,` –  Feb 26 '14 at 16:01
  • runs the command org-cycle, which is an interactive autoloaded Lisp function in `org.el'. – incandescentman Feb 26 '14 at 16:39
  • Oh right! How can I forget that `org-mode` takes the `tab` key, you can get auto-completion in `org-mode` by overriding `tab` key but I would advice NOT to do so since `tab` is very useful key in `org-mode`. You can bind auto-complete to some other key if you want. –  Feb 26 '14 at 16:43
  • Hmm, in Emacs Live (another curated Emacs package), TAB to auto-complete does work in org-mode. (And TAB to org-cycle also works, depending on whether you're on a headline or not.) – incandescentman Feb 26 '14 at 20:30
  • @PeterSalazar, just checked `emacs-live` it does prompt me for completion with `tab` rather it pops up completion immediately (i.e. without pressing `tab`). Maybe you have a function declared somewhere that is making `tab` work for you in org-mode. Just do `C-h k` `tab` (in your emacs-live), you will come to know the command run by `tab`, this will also provide a link to the function's source you can copy that to your init file. I will also try to post a function that will achieve what you want but I am not sure that is a good a idea. –  Feb 26 '14 at 21:24
  • Emacs Live: runs the command yas-expand, which is an alias for `yas-expand-from-trigger-key' in `yasnippet.el'. It is bound to , . (yas-expand &optional FIELD) Expand a snippet before point. If no snippet expansion is possible, call command `org-cycle'. Optional argument FIELD is for non-interactive use and is an object satisfying `yas--field-p' to restrict the expansion to. – incandescentman Feb 26 '14 at 22:47
  • Hi @PeterSalazar, I guess you are looking for the yasnippet package available, at https://github.com/capitaomorte/yasnippet. Emacs live is running the command from yasnippet it is not autocompleting –  Feb 27 '14 at 03:30
  • It is autocompleting. There are only a handful of snippets defined in the snippets package, but in Emacs Live org-mode, TAB autocompletes any word that already appears in the buffer. – incandescentman Feb 27 '14 at 18:55
  • `TAB` is not auto-completing for me (in emacs-live). I looked at emacs-live's auto-complete configuration they do not seem to be doing anything that will enable tab completion. Just try adding `(setq ac-auto-start 2)` and `(add-to-list 'ac-sources ac-source-words-in-buffer)` in your init file. –  Feb 28 '14 at 01:55
  • I just did a clean install of Emacs Live, and for me it works out of the box. Launch Emacs, then in that initial default scratch buffer, `M-x org-mode`. Then type the first two letters of one of the words in the welcome phrase, then `TAB`. For me it autocompletes. – incandescentman Mar 02 '14 at 22:33
  • @PeterSalazar after the menu appears, do `C-g` and then press `tab` again does it auto-complete? What you are seeing is a side-effect of `(setq ac-auto-start 2)` which start auto-completion as soon as you type 2 chars. –  Mar 03 '14 at 01:48
  • 1
    Well, on my emacs `(add-to-list 'ac-modes 'org-mode)` causes an error on startup, because the definition of `'ac-modes` is void, so no adding to that. – Zelphir Kaltstahl Jan 06 '18 at 21:24
1

For me the solution was to install org-ac from melpa-stable. This caused Emacs to show the completed word after the cursor, as if I had already typed it, but in a different color. Using Tab accepts that completion.

(Emacs: GNU Emacs 24.5.1)

Zelphir Kaltstahl
  • 5,722
  • 10
  • 57
  • 86
0

The only robust solution I found was to disable flyspell mode M-xflyspell-mode when I want to use auto-completion in org-mode: Emacs 26.1, GTK+ 3.22.30, Org mode version 9.1.14, Spacemacs 0.200.13. The suggestion (add-to-list 'ac-modes 'org-mode) did not work and I was unable to find ac-flyspell-workaround. Because completion in org-mode is more valuable to me than is flyspell mode, I turn off flyspell much of the time.

Reb.Cabin
  • 5,426
  • 3
  • 35
  • 64