randomphrase / company-c-headers

Auto-completion for C/C++ headers using Company
GNU General Public License v2.0
76 stars 9 forks source link

How can I customize "company-c-headers-modes" ? #18

Closed yuzumx closed 7 years ago

yuzumx commented 7 years ago

I what to start your mode on .c and .cpp file. but the emacs crash when I changed the company-c-headers-modes my code :

(setq 'company-c-headers-modes
      `((c-mode     . ,(rx ".h" ".c" line-end))
        (c++-mode   . ,(rx (or (: line-start (one-or-more (in "A-Za-z0-9_")))
                               (or ".h" ".hpp" ".hxx" ".hh"))
                           line-end))
        (objc-mode  . ,(rx ".h" ".objc" line-end)))

What's I wrong ?

randomphrase commented 7 years ago

What do you mean emacs crashes? What's the error?

Also I really don't think you want to add .c to the list of header files. The point of this variable is to define which files are headers for the given major mode. So don't add .c to this list unless you routinely #include them.

randomphrase commented 7 years ago

Also you might not understand how rx works. This builds a regular expression using a relatively intuitive syntax. In this case ".h" followed by ".c" means exactly that: a file name ending in .h.c. I sincerely doubt that's what you want.

yuzumx commented 7 years ago

SO..... Well, I am bad. My intention is to let the mode in the ". C" file automatically trigger.Because now I have to manually use M-x company-c-headers to trigger auto-complete the header files name.

yuzumx commented 7 years ago

The emacs-crash message: (mx-c-cpp.el is my configuration file about this mode and other C language modes, I'm sure there is no error before adding the problem code.)

eval-buffer: End of file during parsing: /home/tlmf/.emacs.d/lisp/mx-c-cpp.el

Code for your mode (Doesn't contain the wrong period) :

(when (maybe-require-package 'company-c-headers)
  (after-load 'company
    (add-hook 'c-mode-common-hook
              (lambda () (mx/local-push-company-backend 'company-c-headers)))))

I added the code in the issue after that, and then went wrong.

The contents of the function mx/local-push-company-backend:

  (defun mx/local-push-company-backend (backend)
    "Add BACKEND to a buffer-local version of `company-backends'."
    (set (make-local-variable 'company-backends)
         (append (list backend) company-backends))))