• Stars
    star
    120
  • Rank 295,723 (Top 6 %)
  • Language
    Emacs Lisp
  • Created over 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

C++ completion for GNU Emacs

function-args

GNU Emacs package for showing an inline arguments hint for the C/C++ function at point

What and why

The traditional way of showing function arguments in Emacs is to show them in the minibuffer. This approach isn't optimal, since I have to traverse the whole screen just to see the hint. After that traverse the whole screen back to find the cursor.

Other environments such as Qt Creator and Eclipse implement the hint as a popup located exactly where the function call is. This is the behavior that function-args implements for Emacs.

Along the way, it fixes the problem of hints for overridden functions by offering to cycle though the available hints.

Cursor tracking, i.e. highlighting the current argument in bold and disposing the popup when the point has left the arguments list, is implemented for change hooks only at the moment. This means that you have to type a char in order for the current argument to update.

[quasi-]Related completion functionality

This package also extends c++-mode completion provided by CEDET.

This functionality is unrelated logically, but related programmatically: much of the same hacks on CEDET to get a better function arguments hint can be used to get better symbol completion as well.

Installation

Requirements

The baseline requirement is Emacs24. It's recommended if you want to quickly try the package.

You can go as low as Emacs23.2 (the first version where CEDET is bundled with Emacs) if you don't want to install CEDET on your own. This however isn't recommended since C++ completion is a CPU heavy task and newer libraries are better optimized.

You can get a better experience than the baseline Emacs24 by getting Emacs from bzr.

You might improve it by a bit more by keeping up with CEDET from bzr.

Easy start

It's easiest to install from MELPA. No further setup necessary to get the basic functions working: just M-x function-args-mode when you have a C/C++ file open.

After it becomes annoying to call function-args-mode for each file, use this to do it automatically:

(fa-config-default)

Or install from here

Clone this repository:

$ cd ~/.emacs.d/
$ git clone https://github.com/abo-abo/function-args

Add to .emacs:

(add-to-list 'load-path "~/.emacs.d/function-args")
(require 'function-args)
(fa-config-default)

Additional setup (optional)

Put c++-mode as default for *.h files (improves parsing):

(add-to-list 'auto-mode-alist '("\\.h\\'" . c++-mode))

Enable case-insensitive searching:

(set-default 'semantic-case-fold t)

If your includes aren't located in default dirs e.g. /usr/include/ etc, then you have to do something like this:

(semantic-add-system-include "~/Software/deal.II/include/" 'c++-mode)
(semantic-add-system-include "/usr/local/boost_1_54_0/" 'c++-mode)

You can add this to improve the parse of macro-heavy code:

(require 'semantic/bovine/c)
(add-to-list 'semantic-lex-c-preprocessor-symbol-file
    "/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h")

Main functions

fa-show

Show an overlay hint with current function arguments like so:

screenshot

The point position is tracked and the current hint argument is updated accordingly. After you've called it with M-i, you can cycle the overloaded functions with M-n/M-h. You can dismiss the hint with M-u or by editing anywhere outside the function arguments.

fa-jump

While the overlay hint is active, jump to the current function. The default shortcut is M-j. If the overlay isn't active, call whatever was bound to M-j before (usually it's c-indent-new-comment-line).

moo-complete

It's essentially a c++-specific version of semantic-ia-complete-symbol. It behaves better, because it accounts more for function overloading and inheritance. Also it's prettier (type parts are fontified) and faster (helm is used for completion). You can invoke it with M-o by default.

screenshot

This screenshot demonstrates the compatibility between fa-show and moo-complete, as well as the matching power of helm:

screenshot

moo-propose-virtual

Lists the virtual members of current class' parents. The selected candidate will be inserted at point.

screenshot

moo-propose-override

Lists all member functions of current class' parents. The selected candidate will be inserted at point.

screenshot

moo-jump-local

Offers to jump to any tag in current buffer. This function works for all modes supported by CEDET. It has a specialization for C++ that flattens namespaces. screenshot

Bugs

Reporting

If you wish to report a bug, please try to reproduce it first with the newest Emacs like so:

$ emacs -q -l ./function-args.el ~/test.cc

bzr CEDET

The latest version of CEDET can sometimes give more completion candidates. I recommend to install it if you're having problems with the CEDET that comes with Emacs.

Semantic refresh

If you're getting a completion only sometimes under the same conditions, try M-x semantic-force-refresh.

moo-complete offers extra (false) candidates

This comes into play when looking for a first level completion, i.e. not prefixed with ::, . or ->. Extra candidates are merged with correct candidates to give more completion candidates. This is to alleviate the problem of no completion candidates when parser becomes confused, i.e. it's better to have a few false candidates in one case, than none in another case.

This isn't a severe bug, it rarely comes up depending on the naming style and the compiler finds it really quick.

In any case, there's always semantic-ia-complete-symbol if you want a different behavior.

More Repositories

1

swiper

Ivy - a generic completion frontend for Emacs, Swiper - isearch with an overview, and more. Oh, man!
Emacs Lisp
2,284
star
2

hydra

make Emacs bindings that stick around
Emacs Lisp
1,818
star
3

avy

Jump to things in Emacs tree-style
Emacs Lisp
1,704
star
4

lispy

Short and sweet LISP editing
Emacs Lisp
1,195
star
5

org-download

Drag and drop images to Emacs org-mode
Emacs Lisp
1,055
star
6

ace-window

Quickly switch windows in Emacs
Emacs Lisp
968
star
7

oremacs

My Emacs config
Emacs Lisp
296
star
8

auto-yasnippet

quickly create disposable yasnippets
Emacs Lisp
243
star
9

pamparam

Simple and fast flashcards for Emacs
Emacs Lisp
228
star
10

ace-link

Quickly follow links in Emacs
Emacs Lisp
210
star
11

lpy

Minimal Python IDE for GNU Emacs
Emacs Lisp
185
star
12

define-word

Display the definition of word at point in Emacs
Emacs Lisp
154
star
13

tiny

Quickly generate linear ranges in Emacs
Emacs Lisp
143
star
14

worf

vi-like bindings for org-mode
Emacs Lisp
132
star
15

orca

ORg CApture
Emacs Lisp
104
star
16

swiper-helm

Helm version of swiper
Emacs Lisp
79
star
17

helm-make

Select a Makefile target with helm.
Emacs Lisp
62
star
18

plain-org-wiki

Simple jump-to-org-files in a directory package
Emacs Lisp
53
star
19

make-it-so

Transform files with Makefile recipes
Emacs Lisp
47
star
20

org-fu

My org-capture and org-protocol setup
Emacs Lisp
37
star
21

cook

Makefile -> Cookbook.py
Python
36
star
22

whicher

Audit and install the programs that your Emacs config depends on
Emacs Lisp
23
star
23

eclipse-theme

Eclipse theme for Emacs
Emacs Lisp
21
star
24

orly

Additional Org-mode link types and completion for them
Emacs Lisp
18
star
25

helm-j-cheatsheet

Quick J reference for Emacs
Emacs Lisp
17
star
26

zoutline

Emacs library for outlines
Emacs Lisp
16
star
27

gtk-pomodoro-indicator

A simple pomodoro indicator for Unity/GTK tray
Python
16
star
28

elf-mode

Show symbol list when opening a binary file in Emacs
Emacs Lisp
13
star
29

matlab-mode

My fork of matlab-mode
Emacs Lisp
13
star
30

short-lambda

Clojure-style anonymous function literal for Elisp
Emacs Lisp
12
star
31

centimacro

Assign multiple macros as global key bindings in Emacs
Emacs Lisp
12
star
32

xlx

XML <-> LISP converter
Common Lisp
11
star
33

eltex

Write LaTeX in Emacs Lisp
Emacs Lisp
10
star
34

headlong

reckless completion for Emacs
Emacs Lisp
10
star
35

semimap

.Xmodmap that uses semicolon as a modifier
8
star
36

dired-guess

Associate file extensions with programs that can open them for dired
Emacs Lisp
8
star
37

cc-chainsaw

A few tricks to make c++-mode go
Emacs Lisp
7
star
38

ukrainian-holidays

Ukrainian holidays for Emacs calendar
Emacs Lisp
7
star
39

org-mode

http://orgmode.org/org-mode.git
Emacs Lisp
6
star
40

profile-dotemacs

My mirror of http://www.randomsample.de/profile-dotemacs.el
Emacs Lisp
6
star
41

abel

abbrevs for Elisp
Emacs Lisp
5
star
42

touchpad

Toggle touchpad on/off
Python
5
star
43

cedet

My mirror of CEDET (http://cedet.sourceforge.net/).
Emacs Lisp
5
star
44

abo-abo.github.io

HTML
4
star
45

ido-occasional

Use ido where you choose
Emacs Lisp
4
star
46

netherlands-holidays

Netherlands holidays for Emacs calendar
Emacs Lisp
4
star
47

latex-wrap

Wrap selection with a LaTeX environment
Emacs Lisp
4
star
48

simple-benchmark

My notes comparing several PL on a simple benchmark
C++
4
star
49

ciao

Emacs Lisp
4
star
50

xkb-indicator

GTK indicator that allows to run setxkbmap via a keybinding
Python
2
star
51

malk

a simple multi-collection completion demo
Emacs Lisp
1
star
52

soap

Smart Operator a posteriori
Emacs Lisp
1
star