unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Activating a mode in a hook
@ 2014-07-18  9:03 Florian Lindner
  2014-07-18 13:23 ` Tassilo Horn
  2014-07-19  0:56 ` Michael Heerdegen
  0 siblings, 2 replies; 5+ messages in thread
From: Florian Lindner @ 2014-07-18  9:03 UTC (permalink / raw)
  To: help-gnu-emacs

Hello,

Two questions about hooks. I have that piece of code:

(add-hook 'c-mode-common-hook
  (lambda()
    (c-add-style "my-cc-style"
       '("linux" (c-offsets-alist . (					
	            (c-basic-offset . 2)
                      (innamespace . 0)
                      (namespace-open . 0)
                      (namespace-close . 0)
                      ))) t)

    (semantic-mode 1)
    (semanticdb-enable-gnu-global-databases 'c-mode)
    (semanticdb-enable-gnu-global-databases 'c++-mode)
    (global-semantic-idle-summary-mode 1)
    (global-semantic-idle-completions-mode 1)
    (global-semantic-decoration-mode 1)
    (global-semantic-stickyfunc-mode 1)
    ))


First question: When entering c++ mode it activates my-cc-style. It works 
finde regarding the namespaces, but c-basic-offset is still 8, not 2.

c-basic-offset: Its value is 8, original value was set-from-style
Local in buffer namespace.cpp; global value is set-from-style.

c-style-alist contains: 
(("my-cc-style" "linux"
  (c-offsets-alist
   (c-basic-offset . 2)
   (innamespace . 0)
   (namespace-open . 0)
   (namespace-close . 0)))


Second question: semantic-mode will be activated when entering c++ mode but 
then it's globablly activated, how can I activate it only for specific 
modes?

Thanks!

Florian




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

* Re: Activating a mode in a hook
  2014-07-18  9:03 Activating a mode in a hook Florian Lindner
@ 2014-07-18 13:23 ` Tassilo Horn
  2014-07-21 11:10   ` Suvayu Ali
  2014-07-19  0:56 ` Michael Heerdegen
  1 sibling, 1 reply; 5+ messages in thread
From: Tassilo Horn @ 2014-07-18 13:23 UTC (permalink / raw)
  To: Florian Lindner; +Cc: help-gnu-emacs

Florian Lindner <mailinglists@xgm.de> writes:

Hi Florian,

I have no clue about the first question, but...

> Second question: semantic-mode will be activated when entering c++
> mode but then it's globablly activated, how can I activate it only for
> specific modes?

I think, you cannot.  At least it's defined as a global minor mode in
semantic.el:

--8<---------------cut here---------------start------------->8---
(define-minor-mode semantic-mode
  "..."
  :global t
  ^^^^^^^^^
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



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

* Re: Activating a mode in a hook
       [not found] <mailman.5604.1405674266.1147.help-gnu-emacs@gnu.org>
@ 2014-07-18 20:16 ` Emanuel Berg
  0 siblings, 0 replies; 5+ messages in thread
From: Emanuel Berg @ 2014-07-18 20:16 UTC (permalink / raw)
  To: help-gnu-emacs

Florian Lindner <mailinglists@xgm.de> writes:

> First question: When entering c++ mode it activates
> my-cc-style. It works finde regarding the namespaces,
> but c-basic-offset is still 8, not 2.

I don't understand your problem/purpose, but:

(setq c++-mode-hook (lambda () (setq c-basic-offset 2)))

> Second question: semantic-mode will be activated when
> entering c++ mode but then it's globablly activated,
> how can I activate it only for specific modes?

I don't use `sematic-mode' (what is it?) - but are you
able to activate it for specific modes manually
somehow? If so, do it again for the specific modes in a
hook, as above...

-- 
underground experts united


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

* Re: Activating a mode in a hook
  2014-07-18  9:03 Activating a mode in a hook Florian Lindner
  2014-07-18 13:23 ` Tassilo Horn
@ 2014-07-19  0:56 ` Michael Heerdegen
  1 sibling, 0 replies; 5+ messages in thread
From: Michael Heerdegen @ 2014-07-19  0:56 UTC (permalink / raw)
  To: help-gnu-emacs

Florian Lindner <mailinglists@xgm.de> writes:

> c-basic-offset: Its value is 8, original value was set-from-style
> Local in buffer namespace.cpp; global value is set-from-style.

This seems to be the problem: you somehow set the (buffer local) binding
to 8 - before the style stuff is applied.  But AFAIU the style binding
is only applied when it finds a value of 'set-from-style.  You should
find out where the binding to 8 comes from (maybe a file local variable
binding?)

> Second question: semantic-mode will be activated when entering c++ mode but 
> then it's globablly activated, how can I activate it only for specific 
> modes?

I don't use it, but yes, it seems to exist only as a global mode.




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

* Re: Activating a mode in a hook
  2014-07-18 13:23 ` Tassilo Horn
@ 2014-07-21 11:10   ` Suvayu Ali
  0 siblings, 0 replies; 5+ messages in thread
From: Suvayu Ali @ 2014-07-21 11:10 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, Jul 18, 2014 at 03:23:37PM +0200, Tassilo Horn wrote:
> Florian Lindner <mailinglists@xgm.de> writes:
> 
> Hi Florian,
> 
> I have no clue about the first question, but...
> 
> > Second question: semantic-mode will be activated when entering c++
> > mode but then it's globablly activated, how can I activate it only for
> > specific modes?
> 
> I think, you cannot.  At least it's defined as a global minor mode in
> semantic.el:
> 
> --8<---------------cut here---------------start------------->8---
> (define-minor-mode semantic-mode
>   "..."
>   :global t
>   ^^^^^^^^^
> --8<---------------cut here---------------end--------------->8---

I use something like this to limit semantic:

;; disable semantic in all non C/C++ buffers
(add-to-list 'semantic-inhibit-functions
	     (lambda () (not (member major-mode '(c-mode c++-mode)))))

Hope this helps,

-- 
Suvayu

Open source is the future. It sets us free.



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

end of thread, other threads:[~2014-07-21 11:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-18  9:03 Activating a mode in a hook Florian Lindner
2014-07-18 13:23 ` Tassilo Horn
2014-07-21 11:10   ` Suvayu Ali
2014-07-19  0:56 ` Michael Heerdegen
     [not found] <mailman.5604.1405674266.1147.help-gnu-emacs@gnu.org>
2014-07-18 20:16 ` Emanuel Berg

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