all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Issue with hide-ifdef and cc-mode
       [not found] <20210527030630.ys6pbkbtqui66iuz.ref@Ergus>
@ 2021-05-27  3:06 ` Ergus
  0 siblings, 0 replies; 9+ messages in thread
From: Ergus @ 2021-05-27  3:06 UTC (permalink / raw)
  To: help-gnu-emacs

Hi:

I am trying to use hide-ifdef to shadow code like:

#if 0
<code>
#endif

But I found that either

#if 0

or 

#if 1

produces the same result disabling the code inside.

Some slightly more complex examples like:

#define var 1
#ifdef var

doesn't work either (of course).

And when I try hif-evaluate-macro it says things like: 

false <= ‘#if 1’

or 

1 is not defined...

Do we have anything smarter in emacs to shows #if 0 codes? O is there
any extra customization or is there an issue in the package? any idea?

Also when I remove the #if macros from around the code the shadow face
persists.

Any help?





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

* Issue with hide-ifdef and cc-mode
       [not found] <20210530070822.h57mmtpp2n7dvpbf.ref@Ergus>
@ 2021-05-30  7:08 ` Ergus
  2021-05-30 11:01   ` Daniel Martín
  0 siblings, 1 reply; 9+ messages in thread
From: Ergus @ 2021-05-30  7:08 UTC (permalink / raw)
  To: emacs-devel

Hi:

I sent this message to the emacs-help mailing list some days ago and I
didn't receive any reply. So I'm resubmitting this here:

I am trying to use hide-ifdef to shadow code like:

#if 0
<code>
#endif

But I found that either

#if 0

or 

#if 1

produces the same result disabling the code inside.

Some slightly more complex examples like:

#define var 1
#ifdef var

doesn't work either (of course).

And when I try hif-evaluate-macro it says things like: 

false <= ‘#if 1’

or 

1 is not defined... Unless the documentation says this function is
capable to understand some more complex constructions like ||, && and
arithmetic 

I only want to disable some code with #if 0 and enable it with #if
1... so my use case is probably the simplest one.

Do we have anything smarter in emacs to shows #if 0 codes? Or is there
any extra customization I am missing or is there any issue in the
package itself? any idea?

Also when I remove the #if macros from around the code the shadow face
sometimes persist.

I would expect such a functionality to be implemented with fontlock or
so, but form an old thread in this mailing list I see that such a thing
is not recommended. But this package is not very documented in the
manual either so I am not sure If I am missing something.

Right now I have only these options:

```
(setq-default hide-ifdef-shadow t
	      hide-ifdef-initially t)
```

Any help than? Should I submit a bug?

Thanks in advance,
Ergus




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

* Re: Issue with hide-ifdef and cc-mode
  2021-05-30  7:08 ` Ergus
@ 2021-05-30 11:01   ` Daniel Martín
  2021-05-30 18:14     ` Ergus
  0 siblings, 1 reply; 9+ messages in thread
From: Daniel Martín @ 2021-05-30 11:01 UTC (permalink / raw)
  To: Ergus; +Cc: emacs-devel

Ergus <spacibba@aol.com> writes:

>
> I am trying to use hide-ifdef to shadow code like:
>
> #if 0
> <code>
> #endif
>
> But I found that either
>
> #if 0
>
> or 
> #if 1
>
> produces the same result disabling the code inside.
>

I tested the following from emacs -Q in Emacs 28:

New C buffer with

#if 0
int i = 0;
#endif

M-x hide-ifdef-mode
M-x hide-ifdef-toggle-shadowing
M-x hide-ifdefs

And the variable definition is shown with a comment font-lock face, as
expected.

If I change it to "#if 1" and M-x hide-ifdefs again, the comment
font-lock face is removed, as expected.  Perhaps some Emacs
customization is getting in the way?

For something more complex than a #if 0, you probably need to ask the C
preprocessor or build system for the defined variables and configure
hide-ifdef-mode accordingly.

>
> Also when I remove the #if macros from around the code the shadow face
> sometimes persist.
>

This could be a bug.  If you have some consistent steps to reproduce it,
you could report it via M-x report-emacs-bug.



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

* Re: Issue with hide-ifdef and cc-mode
  2021-05-30 11:01   ` Daniel Martín
@ 2021-05-30 18:14     ` Ergus
  2021-05-30 18:53       ` Eli Zaretskii
  2021-05-30 19:42       ` Stefan Monnier
  0 siblings, 2 replies; 9+ messages in thread
From: Ergus @ 2021-05-30 18:14 UTC (permalink / raw)
  To: Daniel Martín; +Cc: emacs-devel, Alan Mackenzie

On Sun, May 30, 2021 at 01:01:36PM +0200, Daniel Mart�n wrote:
>Ergus <spacibba@aol.com> writes:
>
>>
>> I am trying to use hide-ifdef to shadow code like:
>>
>> #if 0
>> <code>
>> #endif
>>
>> But I found that either
>>
>> #if 0
>>
>> or
>> #if 1
>>
>> produces the same result disabling the code inside.
>>
>
>I tested the following from emacs -Q in Emacs 28:
>
>New C buffer with
>
>#if 0
>int i = 0;
>#endif
>
>M-x hide-ifdef-mode
>M-x hide-ifdef-toggle-shadowing
>M-x hide-ifdefs
>
>And the variable definition is shown with a comment font-lock face, as
>expected.
>
>If I change it to "#if 1" and M-x hide-ifdefs again, the comment
>font-lock face is removed, as expected.  Perhaps some Emacs
>customization is getting in the way?
>
>For something more complex than a #if 0, you probably need to ask the C
>preprocessor or build system for the defined variables and configure
>hide-ifdef-mode accordingly.
>
Hi Daniel:

Thanks for the reply. It looks like I didn't understand the
documentation properly. (It is only a few lines)

I didn't know I need to manually call hide-ifdefs every time I change
the preprocessor argument. Because none of this is documented in the
manual. But also calling that makes the functionality pretty
sub-optimal.

It is bad that this functionality works fine out of the box either in
vim and in VS Code and other editors but not in emacs without user
explicit intervention.

So I am not sure how difficult may be to do it automatic without killing
the performance... Like font-lock does with everything else... Soes it
really kills performance to add his to font-lock?

I hope probably Alan may have an idea about how to solve this in a more
cc-mode way... Without forcing the user to interactively call
hide-ifdefs.

We do something similar with /* */ multi-line comments... I can't
understand why this may be so different for if 0 macros... But I may be
wrong.






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

* Re: Issue with hide-ifdef and cc-mode
  2021-05-30 18:14     ` Ergus
@ 2021-05-30 18:53       ` Eli Zaretskii
  2021-05-30 19:27         ` Ergus
  2021-05-30 19:42       ` Stefan Monnier
  1 sibling, 1 reply; 9+ messages in thread
From: Eli Zaretskii @ 2021-05-30 18:53 UTC (permalink / raw)
  To: Ergus; +Cc: acm, emacs-devel, mardani29

> Date: Sun, 30 May 2021 20:14:11 +0200
> From: Ergus <spacibba@aol.com>
> Cc: emacs-devel@gnu.org, Alan Mackenzie <acm@muc.de>
> 
> I didn't know I need to manually call hide-ifdefs every time I change
> the preprocessor argument. Because none of this is documented in the
> manual. But also calling that makes the functionality pretty
> sub-optimal.

Please be sure to read the commentary at the beginning of hideif.el,
it explains quite a lot.

> It is bad that this functionality works fine out of the box either in
> vim and in VS Code and other editors but not in emacs without user
> explicit intervention.

??? How can Emacs know which preprocessor symbols are defined and
which undefined?  You have "C-c @ d" and "C-c @ u" to tell Emacs which
symbols are defined and which undefined.

> So I am not sure how difficult may be to do it automatic without killing
> the performance... Like font-lock does with everything else... Soes it
> really kills performance to add his to font-lock?

I'm not sure I understand: what do you need to automate?  Once you
turn on hiding, the display automatically changes as you define and
undefine preprocessor symbols.



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

* Re: Issue with hide-ifdef and cc-mode
  2021-05-30 18:53       ` Eli Zaretskii
@ 2021-05-30 19:27         ` Ergus
  2021-05-31 11:56           ` Eli Zaretskii
  0 siblings, 1 reply; 9+ messages in thread
From: Ergus @ 2021-05-30 19:27 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: mardani29, emacs-devel, acm

Hi Eli:

On Sun, May 30, 2021 at 09:53:15PM +0300, Eli Zaretskii wrote:
>> Date: Sun, 30 May 2021 20:14:11 +0200
>> From: Ergus <spacibba@aol.com>
>> Cc: emacs-devel@gnu.org, Alan Mackenzie <acm@muc.de>
>>
>> I didn't know I need to manually call hide-ifdefs every time I change
>> the preprocessor argument. Because none of this is documented in the
>> manual. But also calling that makes the functionality pretty
>> sub-optimal.
>
>Please be sure to read the commentary at the beginning of hideif.el,
>it explains quite a lot.
>
>> It is bad that this functionality works fine out of the box either in
>> vim and in VS Code and other editors but not in emacs without user
>> explicit intervention.
>
>??? How can Emacs know which preprocessor symbols are defined and
>which undefined?  You have "C-c @ d" and "C-c @ u" to tell Emacs which
>symbols are defined and which undefined.
>
This part is fine for me. In my use case using 0 or 1 should be defined
as numeric values right? so I don't need to define anything. For more
complex cases I understand these commands are very useful; but not in
this simple case.

>> So I am not sure how difficult may be to do it automatic without killing
>> the performance... Like font-lock does with everything else... Soes it
>> really kills performance to add his to font-lock?
>
>I'm not sure I understand: what do you need to automate?  Once you
>turn on hiding, the display automatically changes as you define and
>undefine preprocessor symbols.

I mean:

#if 0
<CODE>
#endif

M-x hide-ifdef-mode
M-x hide-ifdef-toggle-shadowing

does not shadows the region.

I need to explicitly call 
M-x hide-ifdefs

But also

If I change after that #if 0 -> #if 1; the shadow does not disappears
inmediately. So I need to call: M-x hide-ifdefs again.

This is the part that I think may be automatized. Calling hide-ifdefs
every time is annoying.

Emacs is smart enough to recognize when the user modifies a
cpp-macro. And multi-line code highlight is simple like /* */ does... 

What I am missing here?




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

* Re: Issue with hide-ifdef and cc-mode
  2021-05-30 18:14     ` Ergus
  2021-05-30 18:53       ` Eli Zaretskii
@ 2021-05-30 19:42       ` Stefan Monnier
  2021-05-30 20:26         ` Ergus
  1 sibling, 1 reply; 9+ messages in thread
From: Stefan Monnier @ 2021-05-30 19:42 UTC (permalink / raw)
  To: Ergus; +Cc: Daniel Martín, emacs-devel, Alan Mackenzie

> I didn't know I need to manually call hide-ifdefs every time I change
> the preprocessor argument.  Because none of this is documented in the
> manual. But also calling that makes the functionality pretty
> sub-optimal.

`hide-ifdef` has not be given much love in a long time, so yes its
featureset is a bit outdated.

It'd probably not be too hard to hook hide-ifdef into font-lock.
Patches welcome.  In the mean time, you may want
to `M-x report-emacs-bug` and request it as a new feature.


        Stefan




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

* Re: Issue with hide-ifdef and cc-mode
  2021-05-30 19:42       ` Stefan Monnier
@ 2021-05-30 20:26         ` Ergus
  0 siblings, 0 replies; 9+ messages in thread
From: Ergus @ 2021-05-30 20:26 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Daniel Martín, emacs-devel, Alan Mackenzie

On Sun, May 30, 2021 at 03:42:39PM -0400, Stefan Monnier wrote:


>In the mean time, you may want
>to `M-x report-emacs-bug` and request it as a new feature.
>
>
>        Stefan
>
Done,
Thanks.



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

* Re: Issue with hide-ifdef and cc-mode
  2021-05-30 19:27         ` Ergus
@ 2021-05-31 11:56           ` Eli Zaretskii
  0 siblings, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2021-05-31 11:56 UTC (permalink / raw)
  To: Ergus; +Cc: acm, emacs-devel, mardani29

> Date: Sun, 30 May 2021 21:27:39 +0200
> From: Ergus <spacibba@aol.com>
> Cc: mardani29@yahoo.es, emacs-devel@gnu.org, acm@muc.de
> 
> I mean:
> 
> #if 0
> <CODE>
> #endif
> 
> M-x hide-ifdef-mode
> M-x hide-ifdef-toggle-shadowing
> 
> does not shadows the region.
> 
> I need to explicitly call 
> M-x hide-ifdefs

If you want hide-ifdef-mode automatically hide the "#if 0" blocks when
you turn it on, set hide-ifdef-initially non-nil.  This is in the
commentary in hideif.el

> If I change after that #if 0 -> #if 1; the shadow does not disappears
> inmediately. So I need to call: M-x hide-ifdefs again.

If you want this to happen automatically, it could be provided as an
optional feature, but we should decide what should trigger that.  I'm
not sure using JIT font-lock for this is a good idea, because it would
mean blocks will appear and disappear as you type the preprocessor
instructions, until you actually finish them.

> This is the part that I think may be automatized. Calling hide-ifdefs
> every time is annoying.

Even if you bind that to some key like F7?

> Emacs is smart enough to recognize when the user modifies a
> cpp-macro. And multi-line code highlight is simple like /* */ does... 

I'm not sure we really want the annoyance that dynamic comment
fontification causes, especially since in this case entire blocks of
code will appear and disappear, rather than just be painted in a
different color.



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

end of thread, other threads:[~2021-05-31 11:56 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <20210527030630.ys6pbkbtqui66iuz.ref@Ergus>
2021-05-27  3:06 ` Issue with hide-ifdef and cc-mode Ergus
     [not found] <20210530070822.h57mmtpp2n7dvpbf.ref@Ergus>
2021-05-30  7:08 ` Ergus
2021-05-30 11:01   ` Daniel Martín
2021-05-30 18:14     ` Ergus
2021-05-30 18:53       ` Eli Zaretskii
2021-05-30 19:27         ` Ergus
2021-05-31 11:56           ` Eli Zaretskii
2021-05-30 19:42       ` Stefan Monnier
2021-05-30 20:26         ` Ergus

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.