Sarcasm / irony-mode

A C/C++ minor mode for Emacs powered by libclang
GNU General Public License v3.0
909 stars 99 forks source link

Problem with auto-completion #385

Open lrleon opened 7 years ago

lrleon commented 7 years ago

Salut Guillaume

Before all, thanks for your amazing "irony" packages. They have notably increased my speed coding.

I write you in order to comment that maybe the last version of irony or perhaps company-irony has a problem.

Two days ago, I downloaded and saw the melpa packages list and I selected to update the packages. Now, when I expect the auto-completion, I get the following error:

`Company: An error occurred in auto-begin
Invalid function: (cb callback)`

This is the content of my init.el file

(require 'yasnippet)
(yas-global-mode 1)

(require 'auto-complete-config)
(add-to-list 'ac-dictionary-directories "~/.emacs.d/ac-dict")
(ac-config-default)

(add-hook 'after-init-hook 'global-company-mode)

(global-set-key "\C-cl" 'flyspell-mode)
(global-set-key "\C-cg" 'auto-fill-mode)
(global-set-key "\C-cf" 'flyspell-prog-mode)

(setenv "LD_LIBRARY_PATH" "/usr/lib/llvm-4.0/lib/")

(add-hook 'c++-mode-hook 'irony-mode)
(add-hook 'c-mode-hook 'irony-mode)
(add-hook 'objc-mode-hook 'irony-mode)

;; replace the `completion-at-point' and `complete-symbol' bindings in
;; irony-mode's buffers by irony-mode's function
(defun my-irony-mode-hook ()
  (define-key irony-mode-map [remap completion-at-point]
    'irony-completion-at-point-async)
  (define-key irony-mode-map [remap complete-symbol]
    'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook)

(eval-after-load 'company
  '(add-to-list 'company-backends 'company-irony))

(require 'company-irony-c-headers)
;; Load with `irony-mode` as a grouped backend
(eval-after-load 'company
  '(add-to-list
    'company-backends '(company-irony-c-headers company-irony)))
(eval-after-load 'company
  '(add-to-list 'company-backends 'company-irony))
(eval-after-load 'flycheck
   '(add-hook 'flycheck-mode-hook #'flycheck-irony-setup))

;(add-hook 'c++-mode-hook 'flycheck-mode)
;(add-hook 'c-mode-hook 'flycheck-mode)

;; ==========================================
;; (optional) bind TAB for indent-or-complete
;; ==========================================
(defun irony--check-expansion ()
(save-excursion
  (if (looking-at "\\_>") t
    (backward-char 1)
    (if (looking-at "\\.") t
      (backward-char 1)
      (if (looking-at "->") t nil)))))
(defun irony--indent-or-complete ()
"Indent or Complete"
(interactive)
(cond ((and (not (use-region-p))
            (irony--check-expansion))
       (message "complete")
       (company-complete-common))
      (t
       (message "indent")
       (call-interactively 'c-indent-line-or-region))))
(defun irony-mode-keys ()
"Modify keymaps used by `irony-mode'."
(local-set-key (kbd "TAB") 'irony--indent-or-complete)
(local-set-key [tab] 'irony--indent-or-complete))
(add-hook 'c-mode-common-hook 'irony-mode-keys)

I don't really know what is happening, but it is notorious to say that until three days ago all my environment was working perfectly.

Best regards,

Leandro

Sarcasm commented 7 years ago

Hello,

Regarding your issue, I don't see what is causing it, it is not obvious to me.

Some comments about your configuration:

I'm surprised you need this line, it's probably not the right way to fix the issue you encountered.

(setenv "LD_LIBRARY_PATH" "/usr/lib/llvm-4.0/lib/")

I find it weird that you use both auto-complete, and company-mode. Are you sure you use auto-complete? If not you may want to remove the package and the configuration, because 2 completions backends can have some issues. It should be ok if both are configured to not run at the same time.

The following part of the configuration is no longer needed after the recent update of irony-mode:

;; replace the `completion-at-point' and `complete-symbol' bindings in
;; irony-mode's buffers by irony-mode's function
(defun my-irony-mode-hook ()
  (define-key irony-mode-map [remap completion-at-point]
    'irony-completion-at-point-async)
  (define-key irony-mode-map [remap complete-symbol]
    'irony-completion-at-point-async))
(add-hook 'irony-mode-hook 'my-irony-mode-hook)

I don't think company-irony-c-headers causes any issue but can you try to invoke company-irony directly, without the "merged" backend?

M-x company-irony RET

The following seems redundant:

(eval-after-load 'company
  '(add-to-list
    'company-backends '(company-irony-c-headers company-irony)))
(eval-after-load 'company
  '(add-to-list 'company-backends 'company-irony))

Do you want just company-irony, or both company-irony and company-irony-c-headers?

Regarding the last part, the section with the following title:

;; (optional) bind TAB for indent-or-complete

It does not look like it depends on irony but you could try to comment it as well.