GNU bug report logs - #19809
24.4; f90-beginning-of-subprogram wrong behavior with string continuation

Previous Next

Package: emacs;

Reported by: Raul Laasner <raullaasner <at> gmail.com>

Date: Sat, 7 Feb 2015 21:01:02 UTC

Severity: minor

Found in version 24.4

Fixed in version 25.1

Done: Glenn Morris <rgm <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 19809 in the body.
You can then email your comments to 19809 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#19809; Package emacs. (Sat, 07 Feb 2015 21:01:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Raul Laasner <raullaasner <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 07 Feb 2015 21:01:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Raul Laasner <raullaasner <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 24.4;
 f90-beginning-of-subprogram wrong behavior with string continuation
Date: Sat, 7 Feb 2015 22:25:10 +0200
[Message part 1 (text/plain, inline)]
The functions f90-beginning-of-subprogram and f90-end-of-subprogram do not
work correctly if the source file contains lines which begin with the
correct keywords but in fact belong to a continued string. For instance, in
the following,

subroutine foo()
  print*, '&
       end subroutine foo'
  ! The cursor is here
end subroutine foo

f90-beginning-of-subprogram jumps past the line containing 'subroutine
foo()'. A similar example could be written for f90-end-of-subprogram. I
propose to put a small check of whether the previous line ended with an
ampersand into the F90 major mode source file:

--- f90.el    2015-02-07 16:50:56.210519581 +0200
+++ f90_new.el    2015-02-07 16:56:44.997174743 +0200
@@ -1619,6 +1619,14 @@
                 (looking-at "[ \t0-9]*\\(!\\|$\\|#\\)")))
     not-last-statement))

+(defsubst f90-test-string-continuation ()
+  "Return true if the the current is a string continuation."
+  (save-excursion
+    (beginning-of-line)
+    (backward-char)
+    (skip-chars-backward " ")
+    (string= (string (char-before)) "&")))
+
 (defun f90-beginning-of-subprogram ()
   "Move point to the beginning of the current subprogram.
 Return (TYPE NAME), or nil if not found."
@@ -1629,9 +1637,13 @@
                 (re-search-backward f90-program-block-re nil 'move))
       (beginning-of-line)
       (skip-chars-forward " \t0-9")
-      (cond ((setq matching-beg (f90-looking-at-program-block-start))
+      (cond ((and
+          (setq matching-beg (f90-looking-at-program-block-start))
+          (not (f90-test-string-continuation)))
              (setq count (1- count)))
-            ((f90-looking-at-program-block-end)
+            ((and
+          (f90-looking-at-program-block-end)
+          (not (f90-test-string-continuation)))
              (setq count (1+ count)))))
     (beginning-of-line)
     (if (zerop count)
@@ -1654,9 +1666,13 @@
                 (re-search-forward f90-program-block-re nil 'move))
       (beginning-of-line)
       (skip-chars-forward " \t0-9")
-      (cond ((f90-looking-at-program-block-start)
+      (cond ((and
+          (f90-looking-at-program-block-start)
+          (not (f90-test-string-continuation)))
              (setq count (1+ count)))
-            ((setq matching-end (f90-looking-at-program-block-end))
+            ((and
+          (setq matching-end (f90-looking-at-program-block-end))
+          (not (f90-test-string-continuation)))
              (setq count (1- count))))
       (end-of-line))
     ;; This means f90-end-of-subprogram followed by f90-start-of-subprogram


Best wishes,
Raul Laasner

-- 
Raul Laasner
Institute of Physics
University of Tartu
Ravila 14c, 50411, Estonia
e-mail: raullaasner <at> gmail.com
cell: (+372)5182268
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19809; Package emacs. (Wed, 11 Feb 2015 01:28:02 GMT) Full text and rfc822 format available.

Message #8 received at 19809 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Raul Laasner <raullaasner <at> gmail.com>
Cc: 19809 <at> debbugs.gnu.org
Subject: Re: bug#19809: 24.4;
 f90-beginning-of-subprogram wrong behavior with string continuation
Date: Tue, 10 Feb 2015 20:27:25 -0500
Raul Laasner wrote:

> The functions f90-beginning-of-subprogram and f90-end-of-subprogram do not
> work correctly if the source file contains lines which begin with the
> correct keywords but in fact belong to a continued string. For instance, in
> the following,
>
> subroutine foo()
>   print*, '&
>        end subroutine foo'
>   ! The cursor is here
> end subroutine foo

But that's not valid Fortran? Continued strings must use '&' at the
start of the continued lines as well? Eg gfortran 4.8.2 says:

    Warning: Missing '&' in continued character constant at (1)

Ie, you must write
  
   subroutine foo()
     print*, '&
          &end subroutine foo'
   end subroutine foo

in which case there isn't a problem.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19809; Package emacs. (Wed, 11 Feb 2015 09:54:01 GMT) Full text and rfc822 format available.

Message #11 received at 19809 <at> debbugs.gnu.org (full text, mbox):

From: Raul Laasner <raullaasner <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 19809 <at> debbugs.gnu.org
Subject: Re: bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with
 string continuation
Date: Wed, 11 Feb 2015 11:53:18 +0200
[Message part 1 (text/plain, inline)]
I don't think the standard requires the second '&', although it is
recommended. Moreover, GFortran permits its omission and so in practice
people sometimes write such code. In any case, I have realized that the
proposed modification leads to new problems because in principle one could
also have

  subroutine foo
    ! &
  end subroutine foo

or something as weird as

  subroutine foo
    ; &
  end subroutine foo

and it's probably not worth the effort to account for such unlikely cases.
If the function is used mainly interactively then it's immediately clear
anyway if it fails due to unusual coding style. (On a different subject, it
also fails if the subprogram ends with a bare 'end' not followed by a
keyword, also allowed by the standard.)


On Wed, Feb 11, 2015 at 3:27 AM, Glenn Morris <rgm <at> gnu.org> wrote:

> Raul Laasner wrote:
>
> > The functions f90-beginning-of-subprogram and f90-end-of-subprogram do
> not
> > work correctly if the source file contains lines which begin with the
> > correct keywords but in fact belong to a continued string. For instance,
> in
> > the following,
> >
> > subroutine foo()
> >   print*, '&
> >        end subroutine foo'
> >   ! The cursor is here
> > end subroutine foo
>
> But that's not valid Fortran? Continued strings must use '&' at the
> start of the continued lines as well? Eg gfortran 4.8.2 says:
>
>     Warning: Missing '&' in continued character constant at (1)
>
> Ie, you must write
>
>    subroutine foo()
>      print*, '&
>           &end subroutine foo'
>    end subroutine foo
>
> in which case there isn't a problem.
>



-- 
Raul Laasner
Institute of Physics
University of Tartu
Ravila 14c, 50411, Estonia
e-mail: raullaasner <at> gmail.com
[Message part 2 (text/html, inline)]

Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19809; Package emacs. (Wed, 11 Feb 2015 19:10:01 GMT) Full text and rfc822 format available.

Message #14 received at 19809 <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: Raul Laasner <raullaasner <at> gmail.com>
Cc: 19809 <at> debbugs.gnu.org
Subject: Re: bug#19809: 24.4;
 f90-beginning-of-subprogram wrong behavior with string continuation
Date: Wed, 11 Feb 2015 14:09:06 -0500
Raul Laasner wrote:

> I don't think the standard requires the second '&', although it is
> recommended.

By my reading, it does require it.
Quoting from FCD 1539-1:
    
    3.3.2.4 Free form statement continuation:
    
    [...]
    
    If a character context is to be continued, an "&" shall be the last
    nonblank character on the line and shall not be followed by commentary.
    There shall be a later line that is not a comment; an "&" shall be the
    first nonblank character on the next such line and the statement
    continues with the next character following that "&".

Maybe it has changed in newer version of the standard.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#19809; Package emacs. (Wed, 11 Feb 2015 19:34:02 GMT) Full text and rfc822 format available.

Message #17 received at 19809 <at> debbugs.gnu.org (full text, mbox):

From: Raul Laasner <raullaasner <at> gmail.com>
To: Glenn Morris <rgm <at> gnu.org>
Cc: 19809 <at> debbugs.gnu.org
Subject: Re: bug#19809: 24.4; f90-beginning-of-subprogram wrong behavior with
 string continuation
Date: Wed, 11 Feb 2015 21:33:37 +0200
[Message part 1 (text/plain, inline)]
I stand corrected. Indeed, what I said before only applies to a
noncharacter context.

On Wed, Feb 11, 2015 at 9:09 PM, Glenn Morris <rgm <at> gnu.org> wrote:

> Raul Laasner wrote:
>
> > I don't think the standard requires the second '&', although it is
> > recommended.
>
> By my reading, it does require it.
> Quoting from FCD 1539-1:
>
>     3.3.2.4 Free form statement continuation:
>
>     [...]
>
>     If a character context is to be continued, an "&" shall be the last
>     nonblank character on the line and shall not be followed by commentary.
>     There shall be a later line that is not a comment; an "&" shall be the
>     first nonblank character on the next such line and the statement
>     continues with the next character following that "&".
>
> Maybe it has changed in newer version of the standard.
>



-- 
Raul Laasner
Institute of Physics
University of Tartu
Ravila 14c, 50411, Estonia
e-mail: raullaasner <at> gmail.com
cell: (+372)5182268
[Message part 2 (text/html, inline)]

Reply sent to Glenn Morris <rgm <at> gnu.org>:
You have taken responsibility. (Tue, 24 Feb 2015 07:19:01 GMT) Full text and rfc822 format available.

Notification sent to Raul Laasner <raullaasner <at> gmail.com>:
bug acknowledged by developer. (Tue, 24 Feb 2015 07:19:02 GMT) Full text and rfc822 format available.

Message #22 received at 19809-done <at> debbugs.gnu.org (full text, mbox):

From: Glenn Morris <rgm <at> gnu.org>
To: 19809-done <at> debbugs.gnu.org
Subject: Re: bug#19809: 24.4;
 f90-beginning-of-subprogram wrong behavior with string continuation
Date: Tue, 24 Feb 2015 02:18:08 -0500
Version: 25.1

I added some support for this in e8a11db, but I suspect there are more
places where f90.el assumes strings are not continued in that way. It
doesn't seem especially important to me to track them all down.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Tue, 24 Mar 2015 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 9 years and 42 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.