Skip to content

Commit 6863084

Browse files
Ajit-Thakkarchrisbra
authored andcommitted
runtime(fortran): update syntax and ftplugins
closes: #13629 Signed-off-by: Ajit-Thakkar <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent 4e043b1 commit 6863084

6 files changed

Lines changed: 218 additions & 282 deletions

File tree

runtime/doc/filetype.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*filetype.txt* For Vim version 9.0. Last change: 2023 Sep 11
1+
*filetype.txt* For Vim version 9.0. Last change: 2023 Dec 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -567,8 +567,9 @@ FORTRAN *ft-fortran-plugin*
567567
Options:
568568
'expandtab' is switched on to avoid tabs as required by the Fortran
569569
standards unless the user has set fortran_have_tabs in .vimrc.
570-
'textwidth' is set to 72 for fixed source format as required by the
571-
Fortran standards and to 80 for free source format.
570+
'textwidth' is set to 80 for fixed source format whereas it is set to 132
571+
for free source format. Setting the fortran_extended_line_length
572+
variable increases the width to 132 for fixed source format.
572573
'formatoptions' is set to break code and comment lines and to preserve long
573574
lines. You can format comments with |gq|.
574575
For further discussion of fortran_have_tabs and the method used for the

runtime/doc/indent.txt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*indent.txt* For Vim version 9.0. Last change: 2022 Oct 10
1+
*indent.txt* For Vim version 9.0. Last change: 2023 Dec 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -715,7 +715,7 @@ FORTRAN *ft-fortran-indent*
715715
Block if, select case, where, and forall constructs are indented. So are
716716
type, interface, associate, block, and enum constructs. The indenting of
717717
subroutines, functions, modules, and program blocks is optional. Comments,
718-
labelled statements and continuation lines are indented if the Fortran is in
718+
labeled statements, and continuation lines are indented if the Fortran is in
719719
free source form, whereas they are not indented if the Fortran is in fixed
720720
source form because of the left margin requirements. Hence manual indent
721721
corrections will be necessary for labelled statements and continuation lines
@@ -724,17 +724,16 @@ used for the detection of source format see |ft-fortran-syntax|.
724724

725725
Do loops ~
726726
All do loops are left unindented by default. Do loops can be unstructured in
727-
Fortran with (possibly multiple) loops ending on a labelled executable
727+
Fortran with (possibly multiple) loops ending on a labeled executable
728728
statement of almost arbitrary type. Correct indentation requires
729-
compiler-quality parsing. Old code with do loops ending on labelled statements
730-
of arbitrary type can be indented with elaborate programs such as Tidy
731-
(http://www.unb.ca/chem/ajit/f_tidy.htm). Structured do/continue loops are
732-
also left unindented because continue statements are also used for purposes
733-
other than ending a do loop. Programs such as Tidy can convert structured
734-
do/continue loops to the do/enddo form. Do loops of the do/enddo variety can
735-
be indented. If you use only structured loops of the do/enddo form, you should
736-
declare this by setting the fortran_do_enddo variable in your .vimrc as
737-
follows >
729+
compiler-quality parsing. Old code with do loops ending on labeled statements
730+
of arbitrary type can be indented with elaborate programs such as Tidy.
731+
Structured do/continue loops are also left unindented because continue
732+
statements are used for purposes other than ending a do loop. Programs such
733+
as Tidy can convert structured do/continue loops to the do/enddo form. Do
734+
loops of the do/enddo variety can be indented. If you use only structured
735+
loops of the do/enddo form, you should declare this by setting the
736+
fortran_do_enddo variable in your .vimrc as follows >
738737
739738
let fortran_do_enddo=1
740739
@@ -748,15 +747,14 @@ to get do loops indented in .f90 files and left alone in Fortran files with
748747
other extensions such as .for.
749748

750749
Program units ~
751-
The indenting of program units (subroutines, functions, modules, and program
752-
blocks) is enabled by default but can be suppressed if a lighter, screen-width
753-
preserving indent style is desired. To suppress the indenting of program
754-
units for all fortran files set the global fortran_indent_less variable in
755-
your .vimrc as follows >
750+
Indenting of program units (subroutines, functions, modules, and program
751+
blocks) can be increased by setting the variable fortran_indent_more and can
752+
be decreased by setting the variable fortran_indent_less. These variables
753+
can be set for all fortran files in your .vimrc as follows >
756754
757755
let fortran_indent_less=1
758756
759-
A finer level of suppression can be achieved by setting the corresponding
757+
A finer level of control can be achieved by setting the corresponding
760758
buffer-local variable as follows >
761759
762760
let b:fortran_indent_less=1

runtime/doc/syntax.txt

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*syntax.txt* For Vim version 9.0. Last change: 2023 Apr 24
1+
*syntax.txt* For Vim version 9.0. Last change: 2023 Dec 05
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1591,7 +1591,15 @@ FORTRAN *fortran.vim* *ft-fortran-syntax*
15911591
Default highlighting and dialect ~
15921592
Highlighting appropriate for Fortran 2008 is used by default. This choice
15931593
should be appropriate for most users most of the time because Fortran 2008 is
1594-
almost a superset of previous versions (Fortran 2003, 95, 90, and 77).
1594+
almost a superset of previous versions (Fortran 2003, 95, 90, and 77). A
1595+
small number of features new to Fortran 2018 and Fortran 2023 are supported
1596+
and the complete transition to Fortran 2023 will be completed in the future.
1597+
A few legacy constructs deleted or declared obsolescent in recent Fortran
1598+
standards are highlighted as todo items.
1599+
1600+
The syntax script no longer supports Fortran dialects. The variable
1601+
fortran_dialect is now silently ignored. Since computers are much faster now,
1602+
the variable fortran_more_precise is no longer needed and is silently ignored.
15951603

15961604
Fortran source code form ~
15971605
Fortran code can be in either fixed or free source form. Note that the
@@ -1618,14 +1626,36 @@ neither of these variables have been set, the syntax script attempts to
16181626
determine which source form has been used by examining the file extension
16191627
using conventions common to the ifort, gfortran, Cray, NAG, and PathScale
16201628
compilers (.f, .for, .f77 for fixed-source, .f90, .f95, .f03, .f08 for
1621-
free-source). If none of this works, then the script examines the first five
1622-
columns of the first 500 lines of your file. If no signs of free source form
1623-
are detected, then the file is assumed to be in fixed source form. The
1624-
algorithm should work in the vast majority of cases. In some cases, such as a
1625-
file that begins with 500 or more full-line comments, the script may
1626-
incorrectly decide that the fortran code is in fixed form. If that happens,
1627-
just add a non-comment statement beginning anywhere in the first five columns
1628-
of the first twenty-five lines, save (:w) and then reload (:e!) the file.
1629+
free-source). No default is used for the .fpp and .ftn file extensions because
1630+
different compilers treat them differently. If none of this works, then the
1631+
script examines the first five columns of the first 500 lines of your file. If
1632+
no signs of free source form are detected, then the file is assumed to be in
1633+
fixed source form. The algorithm should work in the vast majority of cases.
1634+
In some cases, such as a file that begins with 500 or more full-line comments,
1635+
the script may incorrectly decide that the code is in fixed form. If that
1636+
happens, just add a non-comment statement beginning anywhere in the first five
1637+
columns of the first twenty-five lines, save (:w), and then reload (:e!) the
1638+
file.
1639+
1640+
Vendor extensions ~
1641+
Fixed-form Fortran requires a maximum line length of 72 characters but the
1642+
script allows a maximum line length of 80 characters as do all compilers
1643+
created in the last three decades. An even longer line length of 132
1644+
characters is allowed if you set the variable fortran_extended_line_length
1645+
with a command such as >
1646+
:let fortran_line_length=1
1647+
placed prior to the :syntax on command.
1648+
1649+
If you want additional highlighting of the CUDA Fortran extensions, you should
1650+
set the variable fortran_CUDA with a command such as >
1651+
:let fortran_CUDA=1
1652+
placed prior to the :syntax on command.
1653+
1654+
To activate recognition of some common, non-standard, vendor-supplied
1655+
intrinsics, you should set the variable fortran_vendor_intrinsics with a
1656+
command such as >
1657+
:let fortran_vendor_intrinsics=1
1658+
placed prior to the :syntax on command.
16291659

16301660
Tabs in fortran files ~
16311661
Tabs are not recognized by the Fortran standards. Tabs are not a good idea in
@@ -1647,8 +1677,8 @@ subprograms, block data subprograms, interface blocks, and modules. If you
16471677
also set the variable fortran_fold_conditionals with a command such as >
16481678
:let fortran_fold_conditionals=1
16491679
then fold regions will also be defined for do loops, if blocks, and select
1650-
case constructs. If you also set the variable
1651-
fortran_fold_multilinecomments with a command such as >
1680+
case constructs. If you also set the variable fortran_fold_multilinecomments
1681+
with a command such as >
16521682
:let fortran_fold_multilinecomments=1
16531683
then fold regions will also be defined for three or more consecutive comment
16541684
lines. Note that defining fold regions can be slow for large files.
@@ -1659,58 +1689,6 @@ you set foldmethod=syntax. Comments or blank lines placed between two program
16591689
units are not folded because they are seen as not belonging to any program
16601690
unit.
16611691

1662-
More precise fortran syntax ~
1663-
If you set the variable fortran_more_precise with a command such as >
1664-
:let fortran_more_precise=1
1665-
then the syntax coloring will be more precise but slower. In particular,
1666-
statement labels used in do, goto and arithmetic if statements will be
1667-
recognized, as will construct names at the end of a do, if, select or forall
1668-
construct.
1669-
1670-
Non-default fortran dialects ~
1671-
The syntax script supports two Fortran dialects: f08 and F. You will probably
1672-
find the default highlighting (f08) satisfactory. A few legacy constructs
1673-
deleted or declared obsolescent in the 2008 standard are highlighted as todo
1674-
items.
1675-
1676-
If you use F, the advantage of setting the dialect appropriately is that
1677-
other legacy features excluded from F will be highlighted as todo items and
1678-
that free source form will be assumed.
1679-
1680-
The dialect can be selected in various ways. If all your fortran files use
1681-
the same dialect, set the global variable fortran_dialect in your .vimrc prior
1682-
to your syntax on statement. The case-sensitive, permissible values of
1683-
fortran_dialect are "f08" or "F". Invalid values of fortran_dialect are
1684-
ignored.
1685-
1686-
If the dialect depends upon the file extension, then it is most convenient to
1687-
set a buffer-local variable in a ftplugin file. For more information on
1688-
ftplugin files, see |ftplugin|. For example, if all your fortran files with
1689-
an .f90 extension are written in the F subset, your ftplugin file should
1690-
contain the code >
1691-
let s:extfname = expand("%:e")
1692-
if s:extfname ==? "f90"
1693-
let b:fortran_dialect="F"
1694-
else
1695-
unlet! b:fortran_dialect
1696-
endif
1697-
Note that this will work only if the "filetype plugin indent on" command
1698-
precedes the "syntax on" command in your .vimrc file.
1699-
1700-
Finer control is necessary if the file extension does not uniquely identify
1701-
the dialect. You can override the default dialect, on a file-by-file basis,
1702-
by including a comment with the directive "fortran_dialect=xx" (where xx=F or
1703-
f08) in one of the first three lines in your file. For example, your older .f
1704-
files may be legacy code but your newer ones may be F codes, and you would
1705-
identify the latter by including in the first three lines of those files a
1706-
Fortran comment of the form >
1707-
! fortran_dialect=F
1708-
1709-
For previous versions of the syntax, you may have set fortran_dialect to the
1710-
now-obsolete values "f77", "f90", "f95", or "elf". Such settings will be
1711-
silently handled as "f08". Users of "elf" may wish to experiment with "F"
1712-
instead.
1713-
17141692
The syntax/fortran.vim script contains embedded comments that tell you how to
17151693
comment and/or uncomment some lines to (a) activate recognition of some
17161694
non-standard, vendor-supplied intrinsics and (b) to prevent features deleted

runtime/ftplugin/fortran.vim

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
" Vim settings file
22
" Language: Fortran 2008 (and older: Fortran 2003, 95, 90, 77, 66)
3-
" Version: (v53) 2021 April 06 (updated 2022 May 22)
4-
" Maintainer: Ajit J. Thakkar <[email protected]>; <http://www2.unb.ca/~ajit/>
3+
" Version: (v54) 2023 December 5
4+
" Maintainers: Ajit J. Thakkar <[email protected]>; <https://ajit.ext.unb.ca/>
5+
" Joshua Hollett <[email protected]>
56
" Usage: For instructions, do :help fortran-plugin from Vim
67
" Credits:
78
" Version 0.1 was created in September 2000 by Ajit Thakkar.
@@ -39,7 +40,7 @@ if !exists("b:fortran_fixed_source")
3940
" Fixed-form file extension defaults
4041
let b:fortran_fixed_source = 1
4142
else
42-
" Modern fortran still allows both fixed and free source form
43+
" Modern fortran compilers still allow both fixed and free source form
4344
" Assume fixed source form unless signs of free source form
4445
" are detected in the first five columns of the first s:lmax lines.
4546
" Detection becomes more accurate and time-consuming if more lines
@@ -70,14 +71,14 @@ if (b:fortran_fixed_source == 1)
7071
" but some vendor extensions allow longer lines
7172
if exists("fortran_extended_line_length")
7273
setlocal tw=132
73-
elseif exists("fortran_cardimage_line_length")
74-
setlocal tw=80
7574
else
76-
setlocal tw=72
75+
" The use of columns 73-80 for sequence numbers is obsolete
76+
" so almost all compilers allow a textwidth of 80
77+
setlocal tw=80
7778
" If you need to add "&" on continued lines so that the code is
7879
" compatible with both free and fixed format, then you should do so
79-
" in column 73 and uncomment the next line
80-
" setlocal tw=73
80+
" in column 81 and uncomment the next line
81+
" setlocal tw=81
8182
endif
8283
else
8384
setlocal comments=:!

runtime/indent/fortran.vim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
" Vim indent file
2-
" Language: Fortran 2008 (and older: Fortran 2003, 95, 90, and 77)
3-
" Version: (v49) 2022 May 14
4-
" Maintainer: Ajit J. Thakkar <[email protected]>; <http://www2.unb.ca/~ajit/>
2+
" Language: Fortran 2008 (and Fortran 2003, 95, 90, and 77)
3+
" Version: (v49) 2023 December 1
4+
" Maintainers: Ajit J. Thakkar <[email protected]>; <https://ajit.ext.unb.ca/>
5+
" Joshua Hollett <[email protected]>
56
" Usage: For instructions, do :help fortran-indent from Vim
67
" Credits:
78
" Version 0.1 was created in September 2000 by Ajit Thakkar.

0 commit comments

Comments
 (0)