unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Emacs *-mode add-hook functions (not working>)
@ 2014-11-07 14:18 3246251196ryan
  2014-11-07 14:59 ` Eli Zaretskii
       [not found] ` <mailman.13128.1415372413.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: 3246251196ryan @ 2014-11-07 14:18 UTC (permalink / raw)
  To: help-gnu-emacs

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. 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?

===

The simply way to get around this is to - having loaded up a .h file - do "M-x c-mode" and then the hook function runs and everything is fine. But why do I need to do this? The mode in the bottom of the emacs screen doesn't change even after doing M-x c-mode, it is always (C/1 Abbrev).

Cheers.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs *-mode add-hook functions (not working>)
  2014-11-07 14:18 Emacs *-mode add-hook functions (not working>) 3246251196ryan
@ 2014-11-07 14:59 ` Eli Zaretskii
  2014-11-07 17:58   ` Stefan Monnier
       [not found]   ` <mailman.13162.1415383171.1147.help-gnu-emacs@gnu.org>
       [not found] ` <mailman.13128.1415372413.1147.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 9+ messages in thread
From: Eli Zaretskii @ 2014-11-07 14:59 UTC (permalink / raw)
  To: help-gnu-emacs

> 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.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs *-mode add-hook functions (not working>)
       [not found] ` <mailman.13128.1415372413.1147.help-gnu-emacs@gnu.org>
@ 2014-11-07 17:21   ` 3246251196ryan
  0 siblings, 0 replies; 9+ messages in thread
From: 3246251196ryan @ 2014-11-07 17:21 UTC (permalink / raw)
  To: help-gnu-emacs

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 =================================


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs *-mode add-hook functions (not working>)
  2014-11-07 14:59 ` Eli Zaretskii
@ 2014-11-07 17:58   ` Stefan Monnier
       [not found]   ` <mailman.13162.1415383171.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Stefan Monnier @ 2014-11-07 17:58 UTC (permalink / raw)
  To: help-gnu-emacs

> You could use c-mode-common-hook, then you wouldn't need 2 hooks.

Note that this will apply to all cc-modes, e.g. php-mode, csharp-mode,
awk-mode.


        Stefan




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs *-mode add-hook functions (not working>)
       [not found]   ` <mailman.13162.1415383171.1147.help-gnu-emacs@gnu.org>
@ 2014-11-09 23:15     ` 3246251196ryan
  2014-11-10 15:49       ` 3246251196ryan
  0 siblings, 1 reply; 9+ messages in thread
From: 3246251196ryan @ 2014-11-09 23:15 UTC (permalink / raw)
  To: help-gnu-emacs

I will test out whether or not the hook function gets called tomorrow. 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs *-mode add-hook functions (not working>)
  2014-11-09 23:15     ` 3246251196ryan
@ 2014-11-10 15:49       ` 3246251196ryan
  2014-11-10 17:37         ` 3246251196ryan
  0 siblings, 1 reply; 9+ messages in thread
From: 3246251196ryan @ 2014-11-10 15:49 UTC (permalink / raw)
  To: help-gnu-emacs

On Sunday, 9 November 2014 23:15:06 UTC, 3246251...@gmail.com  wrote:
> I will test out whether or not the hook function gets called tomorrow.

Okay, the hook function is actually working which is strange. So the problem remains:


That I must firstly open a C++ file in order to get CEDET to parse the headers. Once I do that I there is no problem opening up a .h file, it works. However, if I start emacs and firstly open a .h file I am forced to do M-x c-mode - but once that is done everything is fine thereafter.  

Just trying to figure out why this is the case.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs *-mode add-hook functions (not working>)
  2014-11-10 15:49       ` 3246251196ryan
@ 2014-11-10 17:37         ` 3246251196ryan
  2014-11-10 18:39           ` Drew Adams
       [not found]           ` <mailman.13379.1415644798.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 9+ messages in thread
From: 3246251196ryan @ 2014-11-10 17:37 UTC (permalink / raw)
  To: help-gnu-emacs

On Monday, 10 November 2014 15:49:34 UTC, 3246251...@gmail.com  wrote:
> On Sunday, 9 November 2014 23:15:06 UTC, 3246251...@gmail.com  wrote:
> > I will test out whether or not the hook function gets called tomorrow.
> 
> Okay, the hook function is actually working which is strange. So the problem remains:
> 
> 
> That I must firstly open a C++ file in order to get CEDET to parse the headers. Once I do that I there is no problem opening up a .h file, it works. However, if I start emacs and firstly open a .h file I am forced to do M-x c-mode - but once that is done everything is fine thereafter.  
> 
> Just trying to figure out why this is the case.

To mark this as SOLVED:

I have got this working by including a simple clause in the function called on hook.

(if (string= "c-mode" major-mode)
  (progn
    (c++-mode))) ;; Switch C mode to C++ mode (because we use .h!)

Now things just work. I also forgot failed to realise how useful it is to switch to C++-mode when looking at a C++ .h file: the emacs colouring is all correct when in C++-mode, eg:

static void MyStatFunc(); 

the keyword were not being read correctly, so void would be the colour of the method name etc.

All good now with this hack, but still wondering why I needed to do M-x c-mode again in the first place to get things to run.


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: Emacs *-mode add-hook functions (not working>)
  2014-11-10 17:37         ` 3246251196ryan
@ 2014-11-10 18:39           ` Drew Adams
       [not found]           ` <mailman.13379.1415644798.1147.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2014-11-10 18:39 UTC (permalink / raw)
  To: 3246251196ryan, help-gnu-emacs

> (if (string= "c-mode" major-mode)

I haven't followed this thread at all.  But since `major-mode'
has a symbol value, you can just use (eq 'c-mode major-mode)
here.  (And maybe you really want (derived-mode-p 'c-mode)
instead - dunno.)



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Emacs *-mode add-hook functions (not working>)
       [not found]           ` <mailman.13379.1415644798.1147.help-gnu-emacs@gnu.org>
@ 2014-11-11 17:33             ` 3246251196ryan
  0 siblings, 0 replies; 9+ messages in thread
From: 3246251196ryan @ 2014-11-11 17:33 UTC (permalink / raw)
  To: help-gnu-emacs

On Monday, 10 November 2014 18:40:01 UTC, Drew Adams  wrote:
> > (if (string= "c-mode" major-mode)
> 
> I haven't followed this thread at all.  But since `major-mode'
> has a symbol value, you can just use (eq 'c-mode major-mode)
> here.  (And maybe you really want (derived-mode-p 'c-mode)
> instead - dunno.)

Cheers Drew I will try those out.


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2014-11-11 17:33 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-07 14:18 Emacs *-mode add-hook functions (not working>) 3246251196ryan
2014-11-07 14:59 ` Eli Zaretskii
2014-11-07 17:58   ` Stefan Monnier
     [not found]   ` <mailman.13162.1415383171.1147.help-gnu-emacs@gnu.org>
2014-11-09 23:15     ` 3246251196ryan
2014-11-10 15:49       ` 3246251196ryan
2014-11-10 17:37         ` 3246251196ryan
2014-11-10 18:39           ` Drew Adams
     [not found]           ` <mailman.13379.1415644798.1147.help-gnu-emacs@gnu.org>
2014-11-11 17:33             ` 3246251196ryan
     [not found] ` <mailman.13128.1415372413.1147.help-gnu-emacs@gnu.org>
2014-11-07 17:21   ` 3246251196ryan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).