* c-style-alist
@ 2010-09-16 14:42 Andrea Crotti
2010-09-25 11:54 ` c-style-alist Andrea Crotti
0 siblings, 1 reply; 10+ messages in thread
From: Andrea Crotti @ 2010-09-16 14:42 UTC (permalink / raw
To: help-gnu-emacs
Supposing I have a new language (actually NED), and I already have some
syntax highlighting.
The only thing I want to add is a smarter indentation, and for that is
quite similar to C++.
Looking for possible answers I found out that in
c-style-alist there is also for example python-mode, which is not a
c-mode derivatives.
Is that is the general way to define the correct the policy of spacing?
And what if I define it as a derived mode even if it's quite different
from the original c/c++ branch?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: c-style-alist
2010-09-16 14:42 c-style-alist Andrea Crotti
@ 2010-09-25 11:54 ` Andrea Crotti
2010-09-25 14:02 ` c-style-alist Andreas Röhler
0 siblings, 1 reply; 10+ messages in thread
From: Andrea Crotti @ 2010-09-25 11:54 UTC (permalink / raw
To: help-gnu-emacs
Andrea Crotti <andrea.crotti.0@gmail.com> writes:
> Supposing I have a new language (actually NED), and I already have some
> syntax highlighting.
>
> The only thing I want to add is a smarter indentation, and for that is
> quite similar to C++.
>
> Looking for possible answers I found out that in
> c-style-alist there is also for example python-mode, which is not a
> c-mode derivatives.
>
> Is that is the general way to define the correct the policy of spacing?
> And what if I define it as a derived mode even if it's quite different
> from the original c/c++ branch?
I solved making that mode a derived-mode from cc-mode.
Then I created another derived-mode for c++ files used by omnetpp, but
I'm struggling to make it automatically enabled.
It's very very simple
--8<---------------cut here---------------start------------->8---
(require 'derived)
(define-derived-mode cpp-omnet-mode c++-mode "C++ Omnet mode"
"Major mode for editing c++ files used with omnet++"
)
(provide 'cpp-omnet-mode)
--8<---------------cut here---------------end--------------->8---
and I thought I could do simply something like
--8<---------------cut here---------------start------------->8---
;; Look for the file .ini or the header inclusion
(defun is-omnet-cpp-file ()
(if
(or (file-exists-p "omnetpp.ini")
(search-forward "<omnetpp.h>"))
(cpp-omnet-mode)))
;FIXME: Not working correctly yet, because it goes in infinite loop
;; (add-hook 'c++-mode-hook 'is-omnet-cpp-file)
--8<---------------cut here---------------end--------------->8---
But it's not fine, since it will evaluate infinitely this hook.
Another possibility would be to use "find-file-hook", but it doesn't
really make sense because the files possible are a subset of c++ files.
How can I make it non recurse keeping this?
Or some other suggestions?
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: c-style-alist
2010-09-25 11:54 ` c-style-alist Andrea Crotti
@ 2010-09-25 14:02 ` Andreas Röhler
2010-09-25 22:07 ` c-style-alist PJ Weisberg
0 siblings, 1 reply; 10+ messages in thread
From: Andreas Röhler @ 2010-09-25 14:02 UTC (permalink / raw
To: help-gnu-emacs
Am 25.09.2010 13:54, schrieb Andrea Crotti:
> Andrea Crotti<andrea.crotti.0@gmail.com> writes:
>
>> Supposing I have a new language (actually NED), and I already have some
>> syntax highlighting.
>>
>> The only thing I want to add is a smarter indentation, and for that is
>> quite similar to C++.
>>
>> Looking for possible answers I found out that in
>> c-style-alist there is also for example python-mode, which is not a
>> c-mode derivatives.
>>
>> Is that is the general way to define the correct the policy of spacing?
>> And what if I define it as a derived mode even if it's quite different
>> from the original c/c++ branch?
>
> I solved making that mode a derived-mode from cc-mode.
> Then I created another derived-mode for c++ files used by omnetpp, but
> I'm struggling to make it automatically enabled.
>
> It's very very simple
> --8<---------------cut here---------------start------------->8---
> (require 'derived)
>
> (define-derived-mode cpp-omnet-mode c++-mode "C++ Omnet mode"
> "Major mode for editing c++ files used with omnet++"
> )
>
> (provide 'cpp-omnet-mode)
> --8<---------------cut here---------------end--------------->8---
>
> and I thought I could do simply something like
> --8<---------------cut here---------------start------------->8---
> ;; Look for the file .ini or the header inclusion
> (defun is-omnet-cpp-file ()
> (if
> (or (file-exists-p "omnetpp.ini")
> (search-forward "<omnetpp.h>"))
> (cpp-omnet-mode)))
>
> ;FIXME: Not working correctly yet, because it goes in infinite loop
> ;; (add-hook 'c++-mode-hook 'is-omnet-cpp-file)
> --8<---------------cut here---------------end--------------->8---
>
> But it's not fine, since it will evaluate infinitely this hook.
> Another possibility would be to use "find-file-hook", but it doesn't
> really make sense because the files possible are a subset of c++ files.
>
> How can I make it non recurse keeping this?
> Or some other suggestions?
>
>
>
Maybe like this:
(defun is-omnet-cpp-file ()
(or (cpp-omnet-mode)
(if
(or (file-exists-p "omnetpp.ini")
(search-forward "<omnetpp.h>"))
(cpp-omnet-mode))))
There is no path with "omnetpp.ini", which however should not cause a
infinite.
Andreas
--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: c-style-alist
2010-09-25 14:02 ` c-style-alist Andreas Röhler
@ 2010-09-25 22:07 ` PJ Weisberg
2010-09-28 9:00 ` c-style-alist Andrea Crotti
0 siblings, 1 reply; 10+ messages in thread
From: PJ Weisberg @ 2010-09-25 22:07 UTC (permalink / raw
To: help-gnu-emacs
On Sat, Sep 25, 2010 at 7:02 AM, Andreas Röhler
<andreas.roehler@easy-emacs.de> wrote:
> Am 25.09.2010 13:54, schrieb Andrea Crotti:
>> I solved making that mode a derived-mode from cc-mode.
>> Then I created another derived-mode for c++ files used by omnetpp, but
>> I'm struggling to make it automatically enabled.
>>
>> It's very very simple
>> --8<---------------cut here---------------start------------->8---
>> (require 'derived)
>>
>> (define-derived-mode cpp-omnet-mode c++-mode "C++ Omnet mode"
>> "Major mode for editing c++ files used with omnet++"
>> )
>>
>> (provide 'cpp-omnet-mode)
>> --8<---------------cut here---------------end--------------->8---
>>
>> and I thought I could do simply something like
>> --8<---------------cut here---------------start------------->8---
>> ;; Look for the file .ini or the header inclusion
>> (defun is-omnet-cpp-file ()
>> (if
>> (or (file-exists-p "omnetpp.ini")
>> (search-forward "<omnetpp.h>"))
>> (cpp-omnet-mode)))
>>
>> ;FIXME: Not working correctly yet, because it goes in infinite loop
>> ;; (add-hook 'c++-mode-hook 'is-omnet-cpp-file)
>> --8<---------------cut here---------------end--------------->8---
>>
>> But it's not fine, since it will evaluate infinitely this hook.
>> Another possibility would be to use "find-file-hook", but it doesn't
>> really make sense because the files possible are a subset of c++ files.
>>
>> How can I make it non recurse keeping this?
>> Or some other suggestions?
>
> Maybe like this:
>
> (defun is-omnet-cpp-file ()
> (or (cpp-omnet-mode)
> (if
> (or (file-exists-p "omnetpp.ini")
> (search-forward "<omnetpp.h>"))
> (cpp-omnet-mode))))
>
> There is no path with "omnetpp.ini", which however should not cause a
> infinite.
It looks to me like what's happening is that in the hook it switches
to cpp-omnet-mode, and since that's derived from c++-mode it results
in c++-mode-hooks getting run again, so it again switches to
cpp-omnet-mode and runs c++-mode-hooks, ad infinitum.
I'm not an expert and I'm sure there's a better way to do it, but one
way I could suggest is to set a buffer-local variable to mark that
you're switching to cpp-omnet-mode, and don't switch to cpp-omnet-mode
again if it's already set.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: c-style-alist
2010-09-25 22:07 ` c-style-alist PJ Weisberg
@ 2010-09-28 9:00 ` Andrea Crotti
2010-09-28 10:41 ` c-style-alist Andreas Röhler
[not found] ` <AANLkTinKPzz3aNY0e-7uOvK=3nN7Gs+dgf_3xv4+pLva@mail.gmail.com>
0 siblings, 2 replies; 10+ messages in thread
From: Andrea Crotti @ 2010-09-28 9:00 UTC (permalink / raw
To: help-gnu-emacs
PJ Weisberg <pj@irregularexpressions.net> writes:
>
> It looks to me like what's happening is that in the hook it switches
> to cpp-omnet-mode, and since that's derived from c++-mode it results
> in c++-mode-hooks getting run again, so it again switches to
> cpp-omnet-mode and runs c++-mode-hooks, ad infinitum.
>
> I'm not an expert and I'm sure there's a better way to do it, but one
> way I could suggest is to set a buffer-local variable to mark that
> you're switching to cpp-omnet-mode, and don't switch to cpp-omnet-mode
> again if it's already set.
That's exactly what happens, and also the solutions from Andreas doesn't
work, it still loops forever.
But I don't understand why, since if the OR is short circuiting...
But probably I never really pass to cpp-omnet UNTIL all the hooks in
c++-mode have been executed.
I don't see how the variable could help me with that, maybe an example?
Another non related thing, I made a ned-file mode derivate of cc-mode,
because it comes handy for many things, but now is there a way to tell
yasnippet to expand ONLY the snippets for ned-mode?
Otherwise I also see all the snippets for C and C++ which I don't need
at all in this case..
Thanks,
Andrea
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: c-style-alist
2010-09-28 9:00 ` c-style-alist Andrea Crotti
@ 2010-09-28 10:41 ` Andreas Röhler
[not found] ` <AANLkTinKPzz3aNY0e-7uOvK=3nN7Gs+dgf_3xv4+pLva@mail.gmail.com>
1 sibling, 0 replies; 10+ messages in thread
From: Andreas Röhler @ 2010-09-28 10:41 UTC (permalink / raw
To: help-gnu-emacs
Am 28.09.2010 11:00, schrieb Andrea Crotti:
> PJ Weisberg<pj@irregularexpressions.net> writes:
>
>>
>> It looks to me like what's happening is that in the hook it switches
>> to cpp-omnet-mode, and since that's derived from c++-mode it results
>> in c++-mode-hooks getting run again, so it again switches to
>> cpp-omnet-mode and runs c++-mode-hooks, ad infinitum.
>>
>> I'm not an expert and I'm sure there's a better way to do it, but one
>> way I could suggest is to set a buffer-local variable to mark that
>> you're switching to cpp-omnet-mode, and don't switch to cpp-omnet-mode
>> again if it's already set.
>
> That's exactly what happens, and also the solutions from Andreas doesn't
> work, it still loops forever.
>
> But I don't understand why, since if the OR is short circuiting...
> But probably I never really pass to cpp-omnet UNTIL all the hooks in
> c++-mode have been executed.
>
> I don't see how the variable could help me with that, maybe an example?
Using a variable is the right thing.
Even example code would work, if your mode, once set, returns it.
Begin questioning, if the variable is set:
(unless my-code-already-active-p
... ACTIVATE
(setq my-code-already-active-p t)
This should avoid the loop.
>
> Another non related thing, I made a ned-file mode derivate of cc-mode,
> because it comes handy for many things, but now is there a way to tell
> yasnippet to expand ONLY the snippets for ned-mode?
>
> Otherwise I also see all the snippets for C and C++ which I don't need
> at all in this case..
> Thanks,
> Andrea
>
>
>
^ permalink raw reply [flat|nested] 10+ messages in thread
[parent not found: <AANLkTinKPzz3aNY0e-7uOvK=3nN7Gs+dgf_3xv4+pLva@mail.gmail.com>]
end of thread, other threads:[~2010-10-07 16:30 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-16 14:42 c-style-alist Andrea Crotti
2010-09-25 11:54 ` c-style-alist Andrea Crotti
2010-09-25 14:02 ` c-style-alist Andreas Röhler
2010-09-25 22:07 ` c-style-alist PJ Weisberg
2010-09-28 9:00 ` c-style-alist Andrea Crotti
2010-09-28 10:41 ` c-style-alist Andreas Röhler
[not found] ` <AANLkTinKPzz3aNY0e-7uOvK=3nN7Gs+dgf_3xv4+pLva@mail.gmail.com>
[not found] ` <B10177A4-D04A-417D-944C-F21564A9C4A9@gmail.com>
2010-09-29 22:02 ` c-style-alist PJ Weisberg
2010-10-06 14:13 ` c-style-alist Andrea Crotti
2010-10-06 21:40 ` c-style-alist PJ Weisberg
2010-10-07 16:30 ` c-style-alist Andrea Crotti
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.