all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* 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

* Re: c-style-alist
       [not found]           ` <B10177A4-D04A-417D-944C-F21564A9C4A9@gmail.com>
@ 2010-09-29 22:02             ` PJ Weisberg
  2010-10-06 14:13               ` c-style-alist Andrea Crotti
  0 siblings, 1 reply; 10+ messages in thread
From: PJ Weisberg @ 2010-09-29 22:02 UTC (permalink / raw)
  To: Andrea Crotti, help-gnu-emacs

On Wed, Sep 29, 2010 at 5:40 AM, Andrea Crotti
<andrea.crotti.0@gmail.com> wrote:
>
> Il giorno 28/set/2010, alle ore 18.26, PJ Weisberg ha scritto
>>
>> The or is short-circuiting, but problem is with calling
>> cpp-omnet-mode, not search-forward.
>>
>> I was thinking something like this:
>>
>> (add-hook 'c++-mode-hook 'is-omnet-cpp-file)
>> (make-variable-buffer-local 'changing-to-omnet)
>>
>> (defun is-omnet-cpp-file ()
>>  (when (and (or (file-exists-p "omnetpp.ini")
>>                 (search-forward "<omnetpp.h>"))
>>             (not changing-to-omnet))
>>    (setq changing-to-omnet t)
>>    (cpp-omnet-mode)
>>    (setq changing-to-omnet nil)))
>
> Thanks, but I don't see it on the list I think you only sent to me...
> Unfortunately still doesn't work, the same infinite loop problem, even
> if this time I really think it was working, very weird!

Hm.  With that code I don't think it can be calling cpp-omnet-mode
from is-omnet-cpp-file before it's returned from the previous call to
cpp-omnet-mode from is-omnet-cpp file.  What list of function calls do
you get with the error?



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

* Re: c-style-alist
  2010-09-29 22:02             ` c-style-alist PJ Weisberg
@ 2010-10-06 14:13               ` Andrea Crotti
  2010-10-06 21:40                 ` c-style-alist PJ Weisberg
  0 siblings, 1 reply; 10+ messages in thread
From: Andrea Crotti @ 2010-10-06 14:13 UTC (permalink / raw)
  To: help-gnu-emacs

PJ Weisberg <pj@irregularexpressions.net> writes:
>
> Hm.  With that code I don't think it can be calling cpp-omnet-mode
> from is-omnet-cpp-file before it's returned from the previous call to
> cpp-omnet-mode from is-omnet-cpp file.  What list of function calls do
> you get with the error?

Still doesn't work, or well it works because the mode is activated
correctly, but it still goes in
--8<---------------cut here---------------start------------->8---
block: Lisp nesting exceeds `max-lisp-eval-depth'
--8<---------------cut here---------------end--------------->8---

I also activated the debug-on-error but I don't see any list of function
calls.
Maybe you meant that I have to trace the function?
Thanks,
Andrea




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

* Re: c-style-alist
  2010-10-06 14:13               ` c-style-alist Andrea Crotti
@ 2010-10-06 21:40                 ` PJ Weisberg
  2010-10-07 16:30                   ` c-style-alist Andrea Crotti
  0 siblings, 1 reply; 10+ messages in thread
From: PJ Weisberg @ 2010-10-06 21:40 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs

On Wed, Oct 6, 2010 at 7:13 AM, Andrea Crotti <andrea.crotti.0@gmail.com> wrote:
> PJ Weisberg <pj@irregularexpressions.net> writes:
>>
>> Hm.  With that code I don't think it can be calling cpp-omnet-mode
>> from is-omnet-cpp-file before it's returned from the previous call to
>> cpp-omnet-mode from is-omnet-cpp file.  What list of function calls do
>> you get with the error?
>
> Still doesn't work, or well it works because the mode is activated
> correctly, but it still goes in
> --8<---------------cut here---------------start------------->8---
> block: Lisp nesting exceeds `max-lisp-eval-depth'
> --8<---------------cut here---------------end--------------->8---
>
> I also activated the debug-on-error but I don't see any list of function
> calls.
> Maybe you meant that I have to trace the function?
> Thanks,
> Andrea

I meant what shows up in the *Backtrace* buffer.  For me it usually
appears in another window on the frame when I get an error, but I
guess not always.



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

* Re: c-style-alist
  2010-10-06 21:40                 ` c-style-alist PJ Weisberg
@ 2010-10-07 16:30                   ` Andrea Crotti
  0 siblings, 0 replies; 10+ messages in thread
From: Andrea Crotti @ 2010-10-07 16:30 UTC (permalink / raw)
  To: help-gnu-emacs

PJ Weisberg <pj@irregularexpressions.net> writes:

>
> I meant what shows up in the *Backtrace* buffer.  For me it usually
> appears in another window on the frame when I get an error, but I
> guess not always.

No apparently it doesn't...
But there is another problem now, being omnet-cpp a major mode also
semantic doesn't work anymore.
In an older version it was possible to do something like
--8<---------------cut here---------------start------------->8---
  ;; (add-to-list 'semantic-new-buffer-setup-functions
  ;;              '(cpp-omnet-mode . semantic-default-c-setup))
--8<---------------cut here---------------end--------------->8---

but that variable is not there anymore and I can't find something
similar, any idea?

And another problem, when I open a file ".h" which is clearly a c++
file (there are classes for example) is not possible for emacs to use
the correct mode automatically?

Thanks




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

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.