all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* VIM can recognize #if 0 #endif as comment pair, how to do that in Emacs?
@ 2007-08-17 19:02 Leo.Hou
  2007-08-17 20:20 ` J. David Boyd
       [not found] ` <mailman.4927.1187382051.32220.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 4+ messages in thread
From: Leo.Hou @ 2007-08-17 19:02 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Experts,


I saw a friend using VIM and it recognizes #if 0 -- #endif as comment
pair and use the comment color for the code in between!

This is so cool because I had a big headache using emacs+etags jumping
into others' code, spent 5 minutes and then realized that emacs
brought me to some codes between a #if0 -- #endif pair. :'-(

Can anyone make Emacs to recognize this common convention and
highlight all the pieces between them as comment?



Thanks!

Leo

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

* Re: VIM can recognize #if 0 #endif as comment pair, how to do that in Emacs?
  2007-08-17 19:02 VIM can recognize #if 0 #endif as comment pair, how to do that in Emacs? Leo.Hou
@ 2007-08-17 20:20 ` J. David Boyd
       [not found] ` <mailman.4927.1187382051.32220.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 4+ messages in thread
From: J. David Boyd @ 2007-08-17 20:20 UTC (permalink / raw)
  To: help-gnu-emacs

"Leo.Hou" <leo.hou@gmail.com> writes:

> Hi Experts,
>
>
> I saw a friend using VIM and it recognizes #if 0 -- #endif as comment
> pair and use the comment color for the code in between!
>
> This is so cool because I had a big headache using emacs+etags jumping
> into others' code, spent 5 minutes and then realized that emacs
> brought me to some codes between a #if0 -- #endif pair. :'-(
>
> Can anyone make Emacs to recognize this common convention and
> highlight all the pieces between them as comment?
>
>
>
> Thanks!
>
> Leo

Not _exactly_ what you are talking about, but I like this:

>From C-h f hide-ifdef-mode

hide-ifdef-mode is an interactive autoloaded Lisp function in `hideif'.
(hide-ifdef-mode &optional arg)

Toggle Hide-Ifdef mode.  This is a minor mode, albeit a large one.
With arg, turn Hide-Ifdef mode on if arg is positive, off otherwise.
In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor
would eliminate may be hidden from view.  Several variables affect
how the hiding is done:

`hide-ifdef-env'
	An association list of defined and undefined symbols for the
	current buffer.  Initially, the global value of `hide-ifdef-env'
	is used.

`hide-ifdef-define-alist'
	An association list of defined symbol lists.
        Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env'
        and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env'
        from one of the lists in `hide-ifdef-define-alist'.

`hide-ifdef-lines'
	Set to non-nil to not show #if, #ifdef, #ifndef, #else, and
	#endif lines when hiding.

`hide-ifdef-initially'
	Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode
	is activated.

`hide-ifdef-read-only'
	Set to non-nil if you want to make buffers read only while hiding.
	After `show-ifdefs', read-only status is restored to previous value.


Uses keymap "hide-ifdef-mode-map", which is not currently defined.

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

* Re: VIM can recognize #if 0 #endif as comment pair, how to do that in Emacs?
       [not found] ` <mailman.4927.1187382051.32220.help-gnu-emacs@gnu.org>
@ 2007-08-17 23:20   ` Leo.Hou
  2007-08-20 14:33     ` J. David Boyd
  0 siblings, 1 reply; 4+ messages in thread
From: Leo.Hou @ 2007-08-17 23:20 UTC (permalink / raw)
  To: help-gnu-emacs

On Aug 17, 1:20 pm, da...@adboyd.com (J. David Boyd) wrote:
> "Leo.Hou" <leo....@gmail.com> writes:
> > Hi Experts,
>
> > I saw a friend using VIM and it recognizes #if 0 -- #endif as comment
> > pair and use the comment color for the code in between!
>
> > This is so cool because I had a big headache using emacs+etags jumping
> > into others' code, spent 5 minutes and then realized that emacs
> > brought me to some codes between a #if0 -- #endif pair. :'-(
>
> > Can anyone make Emacs to recognize this common convention and
> > highlight all the pieces between them as comment?
>
> > Thanks!
>
> > Leo
>
> Not _exactly_ what you are talking about, but I like this:
>
> >From C-h f hide-ifdef-mode
>
> hide-ifdef-mode is an interactive autoloaded Lisp function in `hideif'.
> (hide-ifdef-mode &optional arg)
>
> Toggle Hide-Ifdef mode.  This is a minor mode, albeit a large one.
> With arg, turn Hide-Ifdef mode on if arg is positive, off otherwise.
> In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor
> would eliminate may be hidden from view.  Several variables affect
> how the hiding is done:
>
> `hide-ifdef-env'
>         An association list of defined and undefined symbols for the
>         current buffer.  Initially, the global value of `hide-ifdef-env'
>         is used.
>
> `hide-ifdef-define-alist'
>         An association list of defined symbol lists.
>         Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env'
>         and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env'
>         from one of the lists in `hide-ifdef-define-alist'.
>
> `hide-ifdef-lines'
>         Set to non-nil to not show #if, #ifdef, #ifndef, #else, and
>         #endif lines when hiding.
>
> `hide-ifdef-initially'
>         Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode
>         is activated.
>
> `hide-ifdef-read-only'
>         Set to non-nil if you want to make buffers read only while hiding.
>         After `show-ifdefs', read-only status is restored to previous value.
>
> Uses keymap "hide-ifdef-mode-map", which is not currently defined.- Hide quoted text -
>
> - Show quoted text -

Thanks David! I tried it and I loved it except for one thing: I need
to M-x hide-ifdefs every time I open a new file. Can i add some hooks
or something like that to keep it on forever?

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

* Re: VIM can recognize #if 0 #endif as comment pair, how to do that in Emacs?
  2007-08-17 23:20   ` Leo.Hou
@ 2007-08-20 14:33     ` J. David Boyd
  0 siblings, 0 replies; 4+ messages in thread
From: J. David Boyd @ 2007-08-20 14:33 UTC (permalink / raw)
  To: help-gnu-emacs

"Leo.Hou" <leo.hou@gmail.com> writes:

> On Aug 17, 1:20 pm, da...@adboyd.com (J. David Boyd) wrote:
>> "Leo.Hou" <leo....@gmail.com> writes:
>> > Hi Experts,
>>
>> > I saw a friend using VIM and it recognizes #if 0 -- #endif as comment
>> > pair and use the comment color for the code in between!
>>
>> > This is so cool because I had a big headache using emacs+etags jumping
>> > into others' code, spent 5 minutes and then realized that emacs
>> > brought me to some codes between a #if0 -- #endif pair. :'-(
>>
>> > Can anyone make Emacs to recognize this common convention and
>> > highlight all the pieces between them as comment?
>>
>> > Thanks!
>>
>> > Leo
>>
>> Not _exactly_ what you are talking about, but I like this:
>>
>> >From C-h f hide-ifdef-mode
>>
>> hide-ifdef-mode is an interactive autoloaded Lisp function in `hideif'.
>> (hide-ifdef-mode &optional arg)
>>
>> Toggle Hide-Ifdef mode.  This is a minor mode, albeit a large one.
>> With arg, turn Hide-Ifdef mode on if arg is positive, off otherwise.
>> In Hide-Ifdef mode, code within #ifdef constructs that the C preprocessor
>> would eliminate may be hidden from view.  Several variables affect
>> how the hiding is done:
>>
>> `hide-ifdef-env'
>>         An association list of defined and undefined symbols for the
>>         current buffer.  Initially, the global value of `hide-ifdef-env'
>>         is used.
>>
>> `hide-ifdef-define-alist'
>>         An association list of defined symbol lists.
>>         Use `hide-ifdef-set-define-alist' to save the current `hide-ifdef-env'
>>         and `hide-ifdef-use-define-alist' to set the current `hide-ifdef-env'
>>         from one of the lists in `hide-ifdef-define-alist'.
>>
>> `hide-ifdef-lines'
>>         Set to non-nil to not show #if, #ifdef, #ifndef, #else, and
>>         #endif lines when hiding.
>>
>> `hide-ifdef-initially'
>>         Indicates whether `hide-ifdefs' should be called when Hide-Ifdef mode
>>         is activated.
>>
>> `hide-ifdef-read-only'
>>         Set to non-nil if you want to make buffers read only while hiding.
>>         After `show-ifdefs', read-only status is restored to previous value.
>>
>> Uses keymap "hide-ifdef-mode-map", which is not currently defined.- Hide quoted text -
>>
>> - Show quoted text -
>
> Thanks David! I tried it and I loved it except for one thing: I need
> to M-x hide-ifdefs every time I open a new file. Can i add some hooks
> or something like that to keep it on forever?


Here's what I do for programming mode, in my .emacs:


(load-library "cc-mode")

(defun my-c-mode-common-hook ()
  (c-set-style "user")
  (c-set-offset 'case-label '+)
  (c-set-offset 'substatement-open 0)
  (setq fill-column 75)
  (imenu-add-menubar-index)
  (add-hook 'c-mode-hook 'turn-on-cwarn-mode)
  (add-hook 'c-mode-hook 'hide-ifdef-mode))
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


Hope this helps.  I don't really remember how I came about using this method
of initialization, but its been in my .emacs file for years and years and
years now.

Dave

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

end of thread, other threads:[~2007-08-20 14:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-17 19:02 VIM can recognize #if 0 #endif as comment pair, how to do that in Emacs? Leo.Hou
2007-08-17 20:20 ` J. David Boyd
     [not found] ` <mailman.4927.1187382051.32220.help-gnu-emacs@gnu.org>
2007-08-17 23:20   ` Leo.Hou
2007-08-20 14:33     ` J. David Boyd

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.