unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* fortran indentation bug?
@ 2008-06-10  6:09 Miles Bader
  2008-06-10 23:37 ` Glenn Morris
  0 siblings, 1 reply; 4+ messages in thread
From: Miles Bader @ 2008-06-10  6:09 UTC (permalink / raw)
  To: Glenn Morris; +Cc: emacs-devel

The following program fragment is indented by fortran-mode, with 
`fortran-check-all-num-for-matching-do' set to t.

Isn't the statement on the numbered line part of the DO body, and so
should be indented along with the body?

      DO 110 J=1,NZ
         DTEMP=GRID(IEXT(J))
         DTEMP=DCOS(DTEMP*PI2)
 110  X(J)=DTEMP

Thanks,

-Miles

-- 
`To alcohol!  The cause of, and solution to,
 all of life's problems' --Homer J. Simpson




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

* Re: fortran indentation bug?
  2008-06-10  6:09 fortran indentation bug? Miles Bader
@ 2008-06-10 23:37 ` Glenn Morris
  2008-06-11  0:06   ` Miles Bader
  0 siblings, 1 reply; 4+ messages in thread
From: Glenn Morris @ 2008-06-10 23:37 UTC (permalink / raw)
  To: Miles Bader; +Cc: emacs-devel

Miles Bader wrote:

> The following program fragment is indented by fortran-mode, with 
> `fortran-check-all-num-for-matching-do' set to t.
>
> Isn't the statement on the numbered line part of the DO body, and so
> should be indented along with the body?
>
>       DO 110 J=1,NZ
>          DTEMP=GRID(IEXT(J))
>          DTEMP=DCOS(DTEMP*PI2)
>  110  X(J)=DTEMP

The numbered statement is part of the loop body, yes.

I guess fortran-mode indents under the assumption that most people
using numbered DO loops will use CONTINUE (as a proxy for END DO)
rather than an actual code statement to close the loop, in which case
the current indentation is the normal one people tend to use.

I might try and change it to do a different thing for non-CONTINUEs,
but it's a very old format (insert Fortran joke of your choice here).
END DO has been around since 1978.




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

* Re: fortran indentation bug?
  2008-06-10 23:37 ` Glenn Morris
@ 2008-06-11  0:06   ` Miles Bader
  2008-06-11  1:18     ` Glenn Morris
  0 siblings, 1 reply; 4+ messages in thread
From: Miles Bader @ 2008-06-11  0:06 UTC (permalink / raw)
  To: Glenn Morris; +Cc: emacs-devel

Glenn Morris <rgm@gnu.org> writes:
> I might try and change it to do a different thing for non-CONTINUEs,
> but it's a very old format (insert Fortran joke of your choice here).
> END DO has been around since 1978.

There's lots of achingly old fortran code around though. :-)

[I found this bug when I re-indented some old code trying to better
understand it.  From the comments, the code originally came from
"Theory and Application of Digital Signal Processing" by Rabiner and
Gold -- publication date 1975 ... :-]

Anyway, it would seem simple to special-case "continue".

Thanks,

-Miles

-- 
Everywhere is walking distance if you have the time.  -- Steven Wright




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

* Re: fortran indentation bug?
  2008-06-11  0:06   ` Miles Bader
@ 2008-06-11  1:18     ` Glenn Morris
  0 siblings, 0 replies; 4+ messages in thread
From: Glenn Morris @ 2008-06-11  1:18 UTC (permalink / raw)
  To: Miles Bader; +Cc: emacs-devel

Miles Bader wrote:

> There's lots of achingly old fortran code around though. :-)

Yes, but no sane man should actually try to edit it any more. :)

> Anyway, it would seem simple to special-case "continue".

Try this, which includes an anti-inflooping patch.


*** fortran.el	17 May 2008 20:08:37 -0000	1.148
--- fortran.el	11 Jun 2008 01:16:22 -0000
***************
*** 1187,1198 ****
                   (fortran-check-end-prog-re)))
            (forward-line)
          (beginning-of-line 2)
!         (catch 'ok
            (while (re-search-forward fortran-end-prog-re nil 'move)
              (if (fortran-check-end-prog-re)
                  (throw 'ok t))))
          (goto-char (match-beginning 0))
!         (forward-line)))))
  
  (defun fortran-previous-statement ()
    "Move point to beginning of the previous Fortran statement.
--- 1187,1198 ----
                   (fortran-check-end-prog-re)))
            (forward-line)
          (beginning-of-line 2)
!         (when (catch 'ok
                  (while (re-search-forward fortran-end-prog-re nil 'move)
                    (if (fortran-check-end-prog-re)
                        (throw 'ok t))))
            (goto-char (match-beginning 0))
!           (forward-line))))))
  
  (defun fortran-previous-statement ()
    "Move point to beginning of the previous Fortran statement.
***************
*** 1651,1657 ****
                ((and (looking-at fortran-end-prog-re1)
                      (fortran-check-end-prog-re))
                 ;; Previous END resets indent to minimum.
!                (setq icol fortran-minimum-statement-indent)))))
      (save-excursion
        (beginning-of-line)
        (cond ((looking-at "[ \t]*$"))
--- 1651,1667 ----
                ((and (looking-at fortran-end-prog-re1)
                      (fortran-check-end-prog-re))
                 ;; Previous END resets indent to minimum.
!                (setq icol fortran-minimum-statement-indent))
!               ;; Previous statement was a numbered DO loop without a
!               ;; closing CONTINUE or END DO, so we indented the
!               ;; terminator like the loop body.
!               ((and fortran-check-all-num-for-matching-do
!                     (not (looking-at "\\(continue\\|end[ \t]*do\\)\\>"))
!                     (progn
!                       (beginning-of-line)
!                       (and (looking-at "[ \t]*[0-9]+")
!                            (fortran-check-for-matching-do))))
!                (setq icol (- icol fortran-do-indent))))))
      (save-excursion
        (beginning-of-line)
        (cond ((looking-at "[ \t]*$"))
***************
*** 1676,1683 ****
                         6
                       (+ icol fortran-continuation-indent))))
              (first-statement)
              ((and fortran-check-all-num-for-matching-do
!                   (looking-at "[ \t]*[0-9]+")
                    (fortran-check-for-matching-do))
               (setq icol (- icol fortran-do-indent)))
              (t
--- 1686,1697 ----
                         6
                       (+ icol fortran-continuation-indent))))
              (first-statement)
+             ;; The terminating statement is actually part of the
+             ;; loop body, so unless it is a CONTINUE or END DO, we
+             ;; indent it like the loop body (see above).
              ((and fortran-check-all-num-for-matching-do
!                   (looking-at "[ \t]*[0-9]+[ \t]*\
! \\(continue\\|end[ \t]*do\\)\\>")
                    (fortran-check-for-matching-do))
               (setq icol (- icol fortran-do-indent)))
              (t






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

end of thread, other threads:[~2008-06-11  1:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-10  6:09 fortran indentation bug? Miles Bader
2008-06-10 23:37 ` Glenn Morris
2008-06-11  0:06   ` Miles Bader
2008-06-11  1:18     ` Glenn Morris

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).