1

Vim has a plugin called SuperTab that uses the tab key to complete words in the current buffer (roughly speaking).

For example, if a buffer's contents are:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

Then typing eval and then pressing tab will complete eval to evaluation, since the latter word is already in the buffer.


I am looking for a emacs equivalent. I know of hippie-expand, but I do not quite like its behavior; sometimes, instead of completing just a word, it will try to complete an entire line.

Searching on the emacs-wiki, I found smart-tab, which almost does what I want. The only rub is that, in the example above, it will complete eval to evaluation. instead of evaluation.


The question is the following:

  1. Is there a direct SuperTab equivalent for emacs that I haven't discovered?
  2. If not, is there a way to change smart-tab's behavior so that the extra period is not part of the completion?
  • I think you have already found it with smart-tab. I did not try it. But I think your only mistake was to use the scratch buffer for testing. Perhaps smart-tab completes symbols and the dot has the symbol category in lisp-evaluation mode (that one of scratch). Just use a normal text buffer. E.g., try M-x text-mode in the scratch buffer and afterwards try tab again. – Tobias Jan 19 '16 at 17:38
  • Ah I see. Turning the scratch buffer to text-mode solves the problem. Thanks! – Kevin Jan 19 '16 at 17:39
  • Please write that as an answer and accept it. So that this question displays as solved. Thanks in advance. – Tobias Jan 19 '16 at 17:54
3

I'm not familiar with SuperTab, and it probably doesn't have an exact equivalent anyway, but rather similar features. Going by your description, I'd say you're looking for dabbrev-expand, which is a built-in Emacs feature. The command is bound to M-/ by default. It completes the current word from a pool that isn't exactly words in the current buffer, but close: it first looks backward from the current position, and then if it finds nothing it looks forward, and if it still finds nothing, it looks in other buffers. M-/ completes the word in full; if you press is again, it gives you the next hit.

There's also C-M-/ (dabbrev-completion), which completes the unambiguous part of the word.

hippie-expand is a sort of dabbrev-expand on steroids: it tries to guess your mind, but doesn't always succeed. dabbrev-expand always sticks to a word (according to the syntax rules of the current buffer). If eval expands to evaluation., you must have tried it in a buffer where the syntax rules make . a symbol constituent, such as the *scratch* buffer as Tobias suggested (*scratch* uses Lisp syntax rules since its primary purpose is to let you type Lisp expressions that Emacs evaluates).

The smart-tab package invokes either dabbrev-expand or hippie-expand based on a configuration option. It doesn't provide a completion or expansion mechanism; what it does is to guess whether you mean to indent or to complete when you press Tab (whereas by default Emacs has completion and indentation on different keys).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.