emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: c-mode pragma and preproc


From: Alan Mackenzie
Subject: Re: c-mode pragma and preproc
Date: Sat, 11 Jan 2020 11:44:02 +0000
User-agent: Mutt/1.10.1 (2018-07-13)

Hello, Ergus.

Happy New Year!

On Thu, Dec 19, 2019 at 15:07:38 +0100, Ergus wrote:
> Hi Alan:

> Recently I have been noticing that many "modern" programming models
> (Open-MP, OmpSs, OpenACC, programming for Intel Xeon Phi) use
> extensively the #pragma sentence.

> But in general, while the pre-processor sentences are usually in column
> zero ([0]), the #pragma, on the other hand, are preferred to be aligned
> with text (0). They are more readable that way.

OK, here's a few thoughts on this.

Just how unusual is this?  I mean, is this indentation only for #pragma,
or are there other directives which might want to be indented thus?

> Is it possible to add a syntactic symbol to distinguish pragmas from
> other preprocessor symbols? (actually pragmas are not pre-processor
> sentences in general)

I don't think the syntactic symbol is the way to go.  It seems to be too
heavy a mechanism for a relatively minor requirement.

The engine part of a solution seems straightforward: we write a function
to be placed on the hook c-special-indent-hook that will run as the last
thing in indentation.  This function will detect #pragma (with or
without spaces) and reindent it.  Also it will use the abbrev mechanism
used by e.g. "else" to get electric indentation after typing a space
after pragma.  This bit is not difficult, and I've got some preliminary
working code.

But what is the interface with the user to look like?  This indentation
clearly has to be optional - but another "minor mode" (like
c-electric-flag, toggled by C-c C-l) doesn't feel right.  Maybe a
function called something like c-toggle-indent-cpp-to-body would be
best.  But do we want a list of directives which get this indentation,
or is it just for #pragma?

> I think that the rest of the rules will not change but probably we need
> analogs for: cpp-macro and cpp-macro-cont.

There may be a need to indent all lines of a multiline #pragma as
cpp-macro-cont.  Normally, multiline macros (usually #define) just get
indented like ordinary code.  Maybe this is a bit more complicated.  :-(

> In general (AFAIK) the pragmas do not create regions inside like a
> define... so we don't need that either.

Yes.  We need to exclude it, though.

> Thanks in advance,
> Ergus

-- 
Alan Mackenzie (Nuremberg, Germany).



reply via email to

[Prev in Thread] Current Thread [Next in Thread]