help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Emacs *-mode add-hook functions (not working>)


From: 3246251196ryan
Subject: Re: Emacs *-mode add-hook functions (not working>)
Date: Fri, 7 Nov 2014 09:21:49 -0800 (PST)
User-agent: G2/1.0

On Friday, 7 November 2014 15:00:15 UTC, Eli Zaretskii  wrote:
> > Date: Fri, 7 Nov 2014 06:18:40 -0800 (PST)
> > From: 3246251196ryan@gmail.com
> > 
> > In order to use CEDET with Windows I need to tell semantic to append 
> > include files to search through to "the" list. In order to do this, I run a 
> > function on C++ mode. For example:
> > 
> > ===
> > (add-hook 'c++-mode-hook 'rjd-my-semantic-load-includes)
> > ===
> > 
> > ^^^^^ This is fine. When I load up a .cpp file the function is called and 
> > all the necessary headers are included and CEDET parses them.
> > 
> > However, a few lines down I have this line:
> > 
> > ===
> > (add-hook 'c-mode-hook 'rjd-my-semantic-load-includes)
> > ===
> > 
> > At work we do not adhere to calling C++ include files with the .hpp file 
> > extension. Our header files are .h - thus, emacs considers this to be a C 
> > style.
> 
> You could use c-mode-common-hook, then you wouldn't need 2 hooks.
> 
> > When I open a .h file however I know the hook function has not been called 
> > (and I can prove it if  you wish unless you are just happy to accept this).
> > 
> > What am I doing wrong with these hook functions?
> 
> I don't know.  It works for me: visiting a .h file invokes a
> c-mode-hook function.  I think the answer is in your other
> customizations.  IOW, try this in "emacs -Q", and if it works then,
> bisect your ~/.emacs to find the culprit.

Thank you for  your help but even with c-mode-common* the issue still remains. 
Once I run "M-x c-mode" everything is fine.

=================MY EMACS=========================
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;; MODES ;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; MODE: CEDET
(load-file "~/.emacs.d/cedet/cedet-devel-load.el") ;; This is the latest dev' 
version ~~ 26th Sept 2014
;; Add further minor-modes to be enabled by semantic-mode.
;; See doc-string of `semantic-default-submodes' for other things
;; you can use here.
(add-to-list 'semantic-default-submodes 'global-semantic-idle-summary-mode t)
(add-to-list 'semantic-default-submodes 'global-semantic-idle-completions-mode 
t)
(add-to-list 'semantic-default-submodes 'global-cedet-m3-minor-mode t)
(semantic-mode 1)
(global-ede-mode 1)
(global-semantic-decoration-mode)

 ;; Deal with STL includes without .ext (C*-mode)
(add-to-list 'magic-fallback-mode-alist '("^// " . c++-mode))
(add-to-list 'magic-fallback-mode-alist '("^#include" . c++-mode))
(add-to-list 'magic-fallback-mode-alist '("^// " . c-mode))
(add-to-list 'magic-fallback-mode-alist '("^#include" . c-mode))

;; MODE: auto-complete (1.3.1)
;(add-to-list 'load-path "~/.emacs.d/autocomplete-mode")
;(require 'auto-complete-config)
;(add-to-list 'ac-dictionary-directories "~/.emacs.d/autocomplete-mode/ac-dict")
;(ac-config-default)

;; MODE: Global location of *.el (used for majority of "plugins")
(setq load-path (append load-path (list "~/.emacs.d")))

;; MODE: Load my version of compile.el (even though I have tried to 
byte-compile-file
;;   it thinking it would pick up the new rjd function straight away! (TODO see 
why!)
(load-file 
"~/Downloads/emacs-24.3-bin-i386/emacs-24.3/lisp/progmodes/compile.el")

;; MODE: My function for CEDET when EMACS opens C++ files
(defun rjd-my-semantic-load-includes ()
  "Have semantic CEDET try and understand which include paths to use"
  (if (string-match "RTEGen" buffer-file-name)
      (progn
        (setq my-base-dir (concat "d:/"                                         
   ; d:/
                                  "Work/"                                       
   ; Work/
                                  "RTE/"                                        
   ; RTE/
                                  (nth 3 (split-string default-directory "/")) 
"/" ; [[branch]]/
                                  "RTEGen/" ))                                  
   ; RTEGen/
        (semantic-add-system-include (concat my-base-dir "A/"))
        (semantic-add-system-include (concat my-base-dir "C/"))
        (semantic-add-system-include (concat my-base-dir "DLLs/S/"))          
        (semantic-add-system-include (concat my-base-dir "E/"))
        (semantic-add-system-include (concat my-base-dir "Er/"))       
        (semantic-add-system-include (concat my-base-dir "F/"))  
        (semantic-add-system-include (concat my-base-dir "I/"))
        (semantic-add-system-include (concat my-base-dir "Sh/"))              
        (semantic-add-system-include (concat my-base-dir "M/"))              
        (semantic-add-system-include (concat my-base-dir "TypesDB/"))
        (semantic-add-system-include (concat my-base-dir "RTEModel/"))
        (semantic-add-system-include
         "c:/Program Files (x86)/Microsoft Visual Studio 10.0/VC/include"))
    (progn 
      (semantic-add-system-include "c:/MinGW/msys/1.0/include/c++/3.4.4")))
  
  ;; Either way, include these!
  (semantic-add-system-include "d:/d/Ext/boost_1_46_1")
  (semantic-add-system-include 
"d:/d/Ext/xerces-c-3.1.1-x86-windows-vc-10.0/include"))


;; MODE: I want to run said function whenever I load a C++ file (related to 
above MODE)
(add-hook 'c-mode-common-hook 'rjd-my-semantic-load-includes)
;; MODE: I want to run said function whenever I load a C++ file (related to 
above MODE)
;(add-hook 'c++-mode-hook 'rjd-my-semantic-load-includes)
;; MODE: We also have c files
;(add-hook 'c-mode-hook 'rjd-my-semantic-load-includes)
================== END MY EMACS =================================


reply via email to

[Prev in Thread] Current Thread [Next in Thread]