1

I hope to add additional paths to ffap-c-path in c-mode/c++-mode, and I prefer the lazy load mechanism. There are two choices for me:

  • use add-hook for c-mode-hook/c++-mode-hook
  • eval-after-load

But as @sanityinc said in this page, it seems here the latter is better. So I add the code like below:

(eval-after-load 'cc-mode
'(progn
  (require 'ffap)
  (setq fap-c-path (append ffap-c-path '("/usr/lib/llvm-3.1/include")))
  )
)

However when I later opened a c source file and find that fap-c-path still the old value. According to the docs, I can use eval-after-load 'cc-mode or eval-after-load "cc-mode" if cc-mode is a library/feature; but neither works here. I take a look at the source code where cc-mode is defined, and find that it uses a cc-provide instead, is it the root cause?

BTW: I also tried the add-hook approach; the new path DOES append, but every time I open another c/c++ file, the code is executed once and finally ffap-c-path contains many duplicated paths.

Community
  • 1
  • 1
Hongxu Chen
  • 5,240
  • 2
  • 45
  • 85

2 Answers2

1

You probably want to use add-to-list instead:

(eval-after-load 'cc-mode
  '(progn
     (require 'ffap)
     (add-to-list 'ffap-c-path "/usr/lib/llvm-3.1/include")))

That way, you guarantee that duplicate values are not inserted.

Chris Barrett
  • 3,383
  • 17
  • 21
0

You mis-spelled ffap-c-path as fap-c-path.

You would also be better using add-to-list, which actually deals with duplicate entries, only adding a new list item if it wasn't already present.

phils
  • 71,335
  • 11
  • 153
  • 198