unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Fortran indentation
@ 2024-08-26 23:37 Ken Mankoff
  2024-08-27 12:17 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Mankoff @ 2024-08-26 23:37 UTC (permalink / raw)
  To: emacs-devel

Hello,

I'm working with Emacs 29.3, a Fortran file with this syntax,

do_foo = some_function()
  if (do_foo) then
    ...

and options

(setq fortran-do-indent 2)
(setq fortran-if-indent 2)
(setq fortran-structure-indent 2)

The if statement should not be indented, because do_foo is not the start  of a do loop. I can fix this behavior if I change line 1634 of fortrtan.el from

((looking-at "do\\b")

to

((looking-at "do\\ \\b")

I'm not terribly familiar with all the various old Fortran syntax options and often see very little whitespace (e.g., IF(ARR(I,J).LT.0.)THEN ) so it may be inappropriate to assume a space exists after DO.

Is this a reasonable fix? Should I submit a patch?

Thanks,

  Ken Mankoff



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

* Re: Fortran indentation
  2024-08-26 23:37 Fortran indentation Ken Mankoff
@ 2024-08-27 12:17 ` Eli Zaretskii
  2024-08-27 13:15   ` Ken Mankoff
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2024-08-27 12:17 UTC (permalink / raw)
  To: Ken Mankoff; +Cc: emacs-devel

> From: Ken Mankoff <km@kenmankoff.com>
> Date: Mon, 26 Aug 2024 16:37:54 -0700
> 
> Hello,
> 
> I'm working with Emacs 29.3, a Fortran file with this syntax,
> 
> do_foo = some_function()
>   if (do_foo) then
>     ...
> 
> and options
> 
> (setq fortran-do-indent 2)
> (setq fortran-if-indent 2)
> (setq fortran-structure-indent 2)
> 
> The if statement should not be indented, because do_foo is not the start  of a do loop. I can fix this behavior if I change line 1634 of fortrtan.el from
> 
> ((looking-at "do\\b")
> 
> to
> 
> ((looking-at "do\\ \\b")
> 
> I'm not terribly familiar with all the various old Fortran syntax options and often see very little whitespace (e.g., IF(ARR(I,J).LT.0.)THEN ) so it may be inappropriate to assume a space exists after DO.
> 
> Is this a reasonable fix? Should I submit a patch?

I think it must be an optional feature, because at least old variants
of Fortran ignore whitespace.  So this:

	DO42000I=1,42

AFAIR is a valid Fortran do-loop starter.

There's an old Fortran-related urban legend, whereby a variant of the
above caused (or may have caused) loss of a spacecraft, see
https://www-users.york.ac.uk/~ss44/cyc/p/fbug.htm .



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

* Re: Fortran indentation
  2024-08-27 12:17 ` Eli Zaretskii
@ 2024-08-27 13:15   ` Ken Mankoff
  2024-08-27 13:56     ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Mankoff @ 2024-08-27 13:15 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


On 2024-08-27 at 05:17 -07, Eli Zaretskii <eliz@gnu.org> wrote...
>> From: Ken Mankoff <km@kenmankoff.com>
>> 
>> do_foo = some_function()
>>   if (do_foo) then
>> 
>> The if statement should not be indented, because do_foo is not the
>> start of a do loop. I can fix this behavior if I change line 1634 of
>> fortrtan.el from
>> 
>> ((looking-at "do\\b")
>> 
>> to
>> 
>> ((looking-at "do\\ \\b")
>> 
>
> 	DO42000I=1,42
>
> AFAIR is a valid Fortran do-loop starter.

You're right, that is valid. The 'looking-at' regex can be improved to handle this case - match "DO42I=1,42" but not "do_foo = f()".

My first attempt is to expect a space or numbers after "DO": "do[\\ |0-9]+". This still matches a vector assignment of: DO42 = [1,2]

More comprehensive - search for only certain characters on the RHS. do[\\ |0-9]+.*=[\\ a-z0-9_]*,[\\ a-z0-9_]*

The last regex appears to work in regexp-builder with these few tests:

      do42I=1,42 ! match
      do_foo = bar()
      do i = 1,42 ! match
      do i = 1,n ! match
      do i_var = a_var,b_var ! match
      do42i_var = a_var,b_var ! match
      DO42 = [1,2]

Would this change be acceptable?

   -k.
   



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

* Re: Fortran indentation
  2024-08-27 13:15   ` Ken Mankoff
@ 2024-08-27 13:56     ` Eli Zaretskii
  0 siblings, 0 replies; 4+ messages in thread
From: Eli Zaretskii @ 2024-08-27 13:56 UTC (permalink / raw)
  To: Ken Mankoff; +Cc: emacs-devel

> From: Ken Mankoff <km@kenmankoff.com>
> Cc: emacs-devel@gnu.org
> Date: Tue, 27 Aug 2024 06:15:33 -0700
> 
> > 	DO42000I=1,42
> >
> > AFAIR is a valid Fortran do-loop starter.
> 
> You're right, that is valid. The 'looking-at' regex can be improved to handle this case - match "DO42I=1,42" but not "do_foo = f()".
> 
> My first attempt is to expect a space or numbers after "DO": "do[\\ |0-9]+". This still matches a vector assignment of: DO42 = [1,2]
> 
> More comprehensive - search for only certain characters on the RHS. do[\\ |0-9]+.*=[\\ a-z0-9_]*,[\\ a-z0-9_]*
> 
> The last regex appears to work in regexp-builder with these few tests:
> 
>       do42I=1,42 ! match
>       do_foo = bar()
>       do i = 1,42 ! match
>       do i = 1,n ! match
>       do i_var = a_var,b_var ! match
>       do42i_var = a_var,b_var ! match
>       DO42 = [1,2]
> 
> Would this change be acceptable?

I think so.  But then last time I used Fortran seriously was 30 years
ago.

Would users of Fortran please chime in?



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

end of thread, other threads:[~2024-08-27 13:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-26 23:37 Fortran indentation Ken Mankoff
2024-08-27 12:17 ` Eli Zaretskii
2024-08-27 13:15   ` Ken Mankoff
2024-08-27 13:56     ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).