all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ergus <spacibba@aol.com>
To: Alan Mackenzie <acm@muc.de>
Cc: emacs-devel@gnu.org
Subject: Re: c-mode pragma and preproc
Date: Tue, 14 Jan 2020 15:01:10 +0100	[thread overview]
Message-ID: <20200114140110.hrfqmrfkffwsknse@Ergus> (raw)
In-Reply-To: <20200111114402.GA6005@ACM>

On Sat, Jan 11, 2020 at 11:44:02AM +0000, Alan Mackenzie wrote:
Hi Alan:

>Hello, Ergus.
>
>Happy New Year!
>
Same for you!!

>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?
>
AFAIK only #pragma.

>> 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 am in favour of the simplest possible solution. I think that syntactic
symbol is actually the simplest one for the final user but you know
c-mode better than me.

In general as I said before it is only #pragma and I don't understand
why it needs to be different from any other syntactic symbol.

>> 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.  :-(
>
We can make it as complex as we want. But in general the rest is just
the same as with normal macros. Because as the different models will
have different keywords we don't need more complexity to be general
enough.

For example the most general example so far is:

#pragma omp parallel shared(salaries1, salaries2)
{
     #pragma omp for reduction(+: salaries1)
     for (int employee = 0; employee < 25000; employee++)
     {
         salaries1 += fetchTheSalary(employee, Co::Company1);
     }

     #pragma omp single
     {
         std::cout << "Salaries1: " << salaries1 << std::endl;
     }

     #pragma omp for reduction(+: salaries1)
     for (int employee = 0; employee < 25000; employee++)
     {
         salaries2 += fetchTheSalary(employee, Co::Company2);
     }

     #pragma omp barrier
}

>> 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).
>
Best,
Ergus



  reply	other threads:[~2020-01-14 14:01 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20191219140738.q5zdmily5ubwnmg3.ref@Ergus>
2019-12-19 14:07 ` c-mode pragma and preproc Ergus
2020-01-11 11:44   ` Alan Mackenzie
2020-01-14 14:01     ` Ergus [this message]
2020-01-19 17:26       ` Alan Mackenzie
2020-01-20  2:15         ` Ergus via Emacs development discussions.
2020-01-20 21:27           ` Alan Mackenzie
2020-02-11 20:00             ` Alan Mackenzie
2020-02-12 10:19               ` Ergus via Emacs development discussions.

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200114140110.hrfqmrfkffwsknse@Ergus \
    --to=spacibba@aol.com \
    --cc=acm@muc.de \
    --cc=emacs-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.