Tahir Hassan
Tahir Hassan

Reputation: 5817

Code Completion in Emacs

I am trying to use Emacs, because it seems a little bit nicer than Notepad++.

I am trying to use the code completion feature (a.k.a intellisense), but don't know how to do it.

First, I type in M-x, then eval-expression, then in the minibuffer, I want to type in

(print (font-family-list))

So I type in (print (font-f and then press TAB, I get a window with the content:

Click <mouse-2> on a completion to select it.
In this buffer, type RET to select the completion near point.

Possible completions are:
font-face-attributes
font-family-list

I can use my mouse to click on the second option (font-family-list). But how do I select the option using only my keyboard? What are the shortcut keys?

Upvotes: 3

Views: 1420

Answers (3)

Tahir Hassan
Tahir Hassan

Reputation: 5817

I was really asking the same question as:

In Emacs, how do I select the completion list with the keyboard?

From the Completion Commands doc and the above answer, I realised that I need to be executing switch-to-completions function. Because M-v wasn't working for me, I ended up binding Shift-Tab to switch to the completions window while in the minibuffer:

(define-key minibuffer-local-map  (kbd "<S-tab>") 'switch-to-completions)

EDIT: M-v (or Alt-v) is working for me on a fresh install - however since using cua-mode, it stopped working.

I was about to install minibuffer-complete-cycle but then when I was reading the description, it says that if completion-cycle-threshold variable is set to a an integer, say 3, then if there are 3 or fewer completion options, then TAB will cycle through them. We can still use M-v with it.

Though reading its description, minibuffer-complete-cycle seems a bit more polished.

Upvotes: 0

Ehvince
Ehvince

Reputation: 18375

You can have a better completion system, but not in the mini-buffer that you call with eval-expression or M-:.

I suggest you call the interactive inferior elisp shell with M-x ielm. Now you can enable the completion of company-mode which brings something like this:

company-mode completion in shell-mode

Install company, which is in melpa:

package-install RET company RET

and call it when you want:

M-x company-mode

You'll notice it works in a shell and in other languages :)

Upvotes: 2

dmg
dmg

Reputation: 4491

In these situations, completion is done via TAB. Completion will add any unique characters until there is a collision (in your case, it added the letter "a"). At this point you need to type the next character that differentiates it. If you type mTAB Emacs will select font-family-list.

Upvotes: 2

Related Questions