Auto-completion while working on an incomplete expression shows available fields, methods, arguments, etc.
Basic Field and Identifier Access
The key to triggering the auto-completion in emacs is the Tab key. You will get a list of suggestions from the compiler. To select something from the list of suggestions, we recommend you to use C-n and C-p, but the down and up arrow keys can be used as well.
Function Template Editing
To speed up entering input parameters when calling functions, function template editing can be used. First, apply auto-complete to the function name, then enter the first parameter and press the Tab key to enter the second parameter and etc until you have entered all required parameters.
Fast Method Override
The CM auto-complete mechanism will help you override methods. To override a method, start typing the name of the method you want to override and press the Tab key to trigger autocomplete. An autocomplete list will appear and give you the list of the possible methods that can be overridden. By pressing the Enter key on the method proposal will generate the template of that method.
/** * Base. */ private class Base { /** * Constructor. */ private constructor() {} /** * OverrideMe1. */ extend private int overrideMe1(int a) { return a; } /** * OverrideMe2. */ extend private str overrideMe2(int a, bool b=true, double c=0) { return ""; } } /** * Sub. */ private class Sub extends Base { }
Navigation From Completion Menu
Commands for navigation from the completion menu:
- C-h: Show function documentation(Add (setq company-quickhelp-delay 0.5) last in your .emacs to automatically pop up documentation)
- M-i: Jump to the function definition the same window(as usual, C-M-i to get back)
- M-o: Jump to the function definition in another window(as usual, C-M-i to get back)
More details below:
Command summary: ;; AC/ac - Auto complete ;; TAB ac - cm complete current expression or indent if auto complete is not applicable (cm-ac-complete-or-indent) ;; TAB ac template - move to next template field (orange) ;; ;; AC/ac - Auto complete menu active ;; C-h ac menu - show interface and comment of currently selected line ;; Alt-o ac menu - display source of currently selected line in other window ;; C-o ac menu - same as alt-o ;; Alt-i ac menu - jump to source of currently selected line ;; c-n ac menu - next menu line ;; c-p ac menu - previous menu line ;; c-g ac menu - close
Basic Operation field access:
Overriding methods:
Basic control:
(defvar cm-ac-enable t "enable cm auto complete on TAB") (defvar cm-ac-menu-lines 20 "enable cm auto complete on TAB")
In your .emacs:
(set-variable 'load-path (append load-path (list nil (substitute-in-file-name "$CM_UNIX_HOME/emacs")))) (load-library "cm") (load-library "cm-hide") (setq cm-ac-menu-lines 10)
or to disable auto complete
(setq cm-ac-enable nil)
Colors:
(custom-set-faces '(company-tooltip ((t (:background "white" :foreground "black")))) '(company-tooltip-selection ((t (:background "gray90" :foreground "black")))) '(company-tooltip-annotation ((t (:foreground "dark red")))) '(company-tooltip-selection ((t (:background "gray90" :foreground "black")))) '(company-tooltip-common ((t (:background "gray70" :foreground "white")))) '(company-tooltip-common-selection ((t (:background "gray60" :foreground "white")))) '(company-tooltip-preview ((t (:foreground "black")))) '(company-tooltip-preview-common ((t (:foreground "gray30"))))
Additional ideas (fine grained control over company-mode):
(defun cm-ac-default-setup (menu-lines) "default cm auto complete setup" (company-mode 1) (setq company-idle-delay nil) (setq company-minimum-prefix-length 10000) (company-quickhelp-mode 1) (setq company-quickhelp-delay nil) (cm-ac-setup-colors) ;; c-mode map (define-key c-mode-map (kbd "TAB") 'cm-ac-indent-and-complete) ;; (message "kkk=%S" (kbd "C-[")) (define-key c-mode-map (kbd "C-TAB") 'cm-ac-keep-keyword) ;; company-menu (define-key company-active-map (kbd "M-i") #'cm-ac-jump-to-location) (define-key company-active-map (kbd "M-o") #'cm-ac-open-location-other-window) (define-key company-active-map (kbd "C-o") #'cm-ac-open-location-other-window) (define-key company-active-map (kbd "C-h") #'company-quickhelp-manual-begin) (define-key company-active-map (kbd "C-n") #'company-select-next) (define-key company-active-map (kbd "C-p") #'company-select-previous) ;; (define-key company-active-map (kbd "ESC") #'company-abort) ;; hmm overrides posibility to use M-i .. sux! ;; company template editing ;; (define-key c-mode-map (kbd "SPC") #'cm-ac-template-edit-space) -- not used -- now automatic at insert ;; (define-key c-mode-map (kbd ",") #'cm-ac-template-edit-comma) -- not used -- now automatic at insert (setq company-quickhelp-delay 0.8) ;; automatic and fast but not interfering with quick menu-selection ;; (setq company-quickhelp-delay nil) ;; manual - press C-h for quickhelp (setq company-tooltip-limit menu-lines) (setq company-backends '(cm-ac-company-backend)) ;; (setq company-tooltip-align-annotations 't) ; align annotations to the right tooltip border ;; (setq company-idle-delay .3) ; decrease delay before autocompletion popup shows ;; (setq company-minimum-prefix-length 3) ;; (define-key company-active-map (kbd "ESC-j") #'cm-ac-jump-to-location) )
Comments
0 comments
Please sign in to leave a comment.