patch 9.1.0013: Modula2 filetype support lacking
Commit:
https://github.com/vim/vim/commit/68a89470693c7687d4e736ca056c05de632e3ac7
Author: Doug Kearns <[email protected]>
Date: Fri Jan 5 17:59:04 2024 +0100
patch 9.1.0013: Modula2 filetype support lacking
Problem: Modula2 filetype support lacking
Solution: Improve the Modula-2 runtime support, add additional modula2
dialects, add compiler plugin, update syntax highlighting,
include syntax tests, update Makefiles (Doug Kearns)
closes: #6796
closes: #8115
Signed-off-by: Doug Kearns <[email protected]>
Signed-off-by: Benjamin Kowarsch <[email protected]>
Signed-off-by: Christian Brabandt <[email protected]>
diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS
index af32d6a3a..6ebaeda19 100644
--- a/.github/CODEOWNERS
+++ b/.github/CODEOWNERS
@@ -13,6 +13,7 @@ runtime/autoload/freebasic.vim @dkearns
runtime/autoload/getscript.vim @cecamp
runtime/autoload/haskell.vim @alx741
runtime/autoload/javascript.vim @jsit
+runtime/autoload/modula2.vim @dkearns
runtime/autoload/netrw.vim @cecamp
runtime/autoload/netrwFileHandlers.vim @cecamp
runtime/autoload/netrwSettings.vim @cecamp
@@ -65,6 +66,7 @@ runtime/compiler/eruby.vim @dkearns
runtime/compiler/fbc.vim @dkearns
runtime/compiler/gawk.vim @dkearns
runtime/compiler/gjs.vim @dkearns
+runtime/compiler/gm2.vim @dkearns
runtime/compiler/go.vim @dbarnett
runtime/compiler/haml.vim @tpope
runtime/compiler/hare.vim @rsaihe
@@ -182,6 +184,7 @@ runtime/ftplugin/m3quake.vim @dkearns
runtime/ftplugin/markdown.vim @tpope
runtime/ftplugin/matlab.vim @cecamp
runtime/ftplugin/meson.vim @Liambeguin
+runtime/ftplugin/modula2.vim @dkearns
runtime/ftplugin/modula3.vim @dkearns
runtime/ftplugin/nginx.vim @chr4
runtime/ftplugin/nroff.vim @a-vrma
@@ -442,6 +445,10 @@ runtime/syntax/maple.vim @cecamp
runtime/syntax/markdown.vim @tpope
runtime/syntax/mason.vim @petdance
runtime/syntax/meson.vim @Liambeguin
+runtime/syntax/modula2.vim @dkearns
+runtime/syntax/modula2/opt/iso.vim @trijezdci
+runtime/syntax/modula2/opt/pim.vim @trijezdci
+runtime/syntax/modula2/opt/r10.vim @trijezdci
runtime/syntax/modula3.vim @dkearns
runtime/syntax/n1ql.vim @pr3d4t0r
runtime/syntax/netrw.vim @cecamp
diff --git a/Filelist b/Filelist
index df188e8a5..d4fbca342 100644
--- a/Filelist
+++ b/Filelist
@@ -818,6 +818,7 @@ RT_SCRIPTS = \
runtime/plugin/README.txt \
runtime/syntax/*.vim \
runtime/syntax/README.txt \
+ runtime/syntax/modula2/opt/*.vim \
runtime/syntax/shared/*.vim \
runtime/syntax/shared/README.txt \
runtime/syntax/Makefile \
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index 2423fd446..9d0f2ee7a 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -2,8 +2,8 @@ vim9script
# Vim functions for file type detection
#
-# Maintainer: The Vim Project <https://github.com/vim/vim>
-# Last Change: 2023 Aug 10
+# Maintainer: The Vim Project <https://github.com/vim/vim>
+# Last Change: 2024 Jan 05
# Former Maintainer: Bram Moolenaar <[email protected]>
# These functions are moved here from runtime/filetype.vim to make startup
@@ -279,6 +279,19 @@ export def DtraceCheck()
endif
enddef
+export def FTdef()
+ if get(g:, "filetype_def", "") == "modula2" || IsModula2()
+ SetFiletypeModula2()
+ return
+ endif
+
+ if exists("g:filetype_def")
+ exe "setf " .. g:filetype_def
+ else
+ setf def
+ endif
+enddef
+
export def FTe()
if exists('g:filetype_euphoria')
exe 'setf ' .. g:filetype_euphoria
@@ -517,16 +530,53 @@ def IsLProlog(): bool
return getline(lnum) =~ '\<module\s\+\w\+\s*\.\s*\(%\|$\)'
enddef
+def IsModula2(): bool
+ return getline(nextnonblank(1)) =~ '\<MODULE\s\+\w\+\s*;\|^\s*(\*'
+enddef
+
+def SetFiletypeModula2()
+ const KNOWN_DIALECTS = ["iso", "pim", "r10"]
+ const KNOWN_EXTENSIONS = ["gm2"]
+ const LINE_COUNT = 200
+ const TAG = '(\*!m2\(\w\+\)\%(+\(\w\+\)\)\=\*)'
+
+ var dialect = get(g:, "modula2_default_dialect", "pim")
+ var extension = get(g:, "modula2_default_extension", "")
+
+ var matches = []
+
+ # ignore unknown dialects or badly formatted tags
+ for lnum in range(1, min([line("$"), LINE_COUNT]))
+ matches = matchlist(getline(lnum), TAG)
+ if !empty(matches)
+ if index(KNOWN_DIALECTS, matches[1]) >= 0
+ dialect = matches[1]
+ endif
+ if index(KNOWN_EXTENSIONS, matches[2]) >= 0
+ extension = matches[2]
+ endif
+ break
+ endif
+ endfor
+
+ modula2#SetDialect(dialect, extension)
+
+ setf modula2
+enddef
+
# Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod
export def FTmod()
+ if get(g:, "filetype_mod", "") == "modula2" || IsModula2()
+ SetFiletypeModula2()
+ return
+ endif
+
if exists("g:filetype_mod")
exe "setf " .. g:filetype_mod
elseif expand("<afile>") =~ '\<go.mod$'
setf gomod
elseif IsLProlog()
setf lprolog
- elseif getline(nextnonblank(1)) =~ '\%(\<MODULE\s\+\w\+\s*;\|^\s*(\*\)'
- setf modula2
elseif IsRapid()
setf rapid
else
@@ -1243,4 +1293,4 @@ export def FTvba()
enddef
# Uncomment this line to check for compilation errors early
-# defcompile
+defcompile
diff --git a/runtime/autoload/modula2.vim b/runtime/autoload/modula2.vim
new file mode 100644
index 000000000..284dc2768
--- /dev/null
+++ b/runtime/autoload/modula2.vim
@@ -0,0 +1,31 @@
+" Vim filetype plugin file
+" Language: Modula-2
+" Maintainer: Doug Kearns <[email protected]>
+" Last Change: 2024 Jan 04
+
+" Dialect can be one of pim, iso, r10
+function modula2#GetDialect() abort
+
+ if exists("b:modula2.dialect")
+ return b:modula2.dialect
+ endif
+
+ if exists("g:modula2_default_dialect")
+ let dialect = g:modula2_default_dialect
+ else
+ let dialect = "pim"
+ endif
+
+ return dialect
+endfunction
+
+function modula2#SetDialect(dialect, extension = "") abort
+ if exists("b:modula2")
+ unlockvar! b:modula2
+ endif
+
+ let b:modula2 = #{ dialect: a:dialect, extension: a:extension }
+ lockvar! b:modula2
+endfunction
+
+" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
diff --git a/runtime/compiler/gm2.vim b/runtime/compiler/gm2.vim
new file mode 100644
index 000000000..505391220
--- /dev/null
+++ b/runtime/compiler/gm2.vim
@@ -0,0 +1,26 @@
+" Vim compiler file
+" Compiler: GNU Modula-2 Compiler
+" Maintainer: Doug Kearns <[email protected]>
+" Last Change: 2024 Jan 04
+
+if exists("current_compiler")
+ finish
+endif
+let current_compiler = "gm2"
+
+if exists(":CompilerSet") != 2 " older Vim always used :setlocal
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+CompilerSet makeprg=gm2
+CompilerSet errorformat=%-G%f:%l:%c:\ error:\ compilation\ failed,
+ \%f:%l:%c:\ %trror:\ %m,
+ \%f:%l:%c:\ %tarning:\ %m,
+ \%f:%l:%c:\ %tote:\ %m,
+ \%-G%.%#
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index e8445db54..4876e3d75 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -1,4 +1,4 @@
-*filetype.txt* For Vim version 9.1. Last change: 2024 Jan 01
+*filetype.txt* For Vim version 9.1. Last change: 2024 Jan 04
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -148,6 +148,7 @@ variables can be used to overrule the filetype used for
certain extensions:
*.cls g:filetype_cls
*.csh g:filetype_csh |ft-csh-syntax|
*.dat g:filetype_dat
+ *.def g:filetype_def
*.f g:filetype_f |ft-forth-syntax|
*.frm g:filetype_frm |ft-form-syntax|
*.fs g:filetype_fs |ft-forth-syntax|
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index e3cac2e24..cc293a597 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -2251,6 +2251,56 @@ have the following in your .vimrc: >
let filetype_m = "mma"
+MODULA2 *modula2.vim*
*ft-modula2-syntax*
+
+Vim will recognise comments with dialect tags to automatically select a given
+dialect.
+
+The syntax for a dialect tag comment is: >
+
+ taggedComment :=
+ '(*!' dialectTag '*)'
+ ;
+
+ dialectTag :=
+ m2pim | m2iso | m2r10
+ ;
+
+ reserved words
+ m2pim = 'm2pim', m2iso = 'm2iso', m2r10 = 'm2r10'
+
+A dialect tag comment is recognised by Vim if it occurs within the first 200
+lines of the source file. Only the very first such comment is recognised, any
+additional dialect tag comments are ignored.
+
+Example: >
+
+ DEFINITION MODULE FooLib; (*!m2pim*)
+ ...
+
+Variable g:modula2_default_dialect sets the default Modula-2 dialect when the
+dialect cannot be determined from the contents of the Modula-2 file: if
+defined and set to 'm2pim', the default dialect is PIM.
+
+Example: >
+
+ let g:modula2_default_dialect = 'm2pim'
+
+
+Highlighting is further configurable for each dialect via the following
+variables.
+
+Variable Highlight ~
+*modula2_iso_allow_lowline* allow low line in identifiers
+*modula2_iso_disallow_octals* disallow octal integer literals
+*modula2_iso_disallow_synonyms* disallow "@", "&" and "~" synonyms
+
+*modula2_pim_allow_lowline* allow low line in identifiers
+*modula2_pim_disallow_octals* disallow octal integer literals
+*modula2_pim_disallow_synonyms* disallow "&" and "~" synonyms
+
+*modula2_r10_allow_lowline* allow low line in identifiers
+
MOO *moo.vim* *ft-moo-syntax*
If you use C-style comments inside expressions and find it mangles your
diff --git a/runtime/doc/tags b/runtime/doc/tags
index 9af1ac0f6..5b9e5a9b6 100644
--- a/runtime/doc/tags
+++ b/runtime/doc/tags
@@ -7270,6 +7270,7 @@ ft-metapost-intro ft_mp.txt /*ft-metapost-intro*
ft-metapost-mappings ft_mp.txt /*ft-metapost-mappings*
ft-metapost-settings ft_mp.txt /*ft-metapost-settings*
ft-mma-syntax syntax.txt /*ft-mma-syntax*
+ft-modula2-syntax syntax.txt /*ft-modula2-syntax*
ft-moo-syntax syntax.txt /*ft-moo-syntax*
ft-msql-syntax syntax.txt /*ft-msql-syntax*
ft-n1ql-syntax syntax.txt /*ft-n1ql-syntax*
@@ -8659,6 +8660,14 @@ modeline options.txt /*modeline*
modeline-local options.txt /*modeline-local*
modeline-version options.txt /*modeline-version*
modifyOtherKeys map.txt /*modifyOtherKeys*
+modula2.vim syntax.txt /*modula2.vim*
+modula2_iso_allow_lowline syntax.txt /*modula2_iso_allow_lowline*
+modula2_iso_disallow_octals syntax.txt /*modula2_iso_disallow_octals*
+modula2_iso_disallow_synonyms syntax.txt /*modula2_iso_disallow_synonyms*
+modula2_pim_allow_lowline syntax.txt /*modula2_pim_allow_lowline*
+modula2_pim_disallow_octals syntax.txt /*modula2_pim_disallow_octals*
+modula2_pim_disallow_synonyms syntax.txt /*modula2_pim_disallow_synonyms*
+modula2_r10_allow_lowline syntax.txt /*modula2_r10_allow_lowline*
moo.vim syntax.txt /*moo.vim*
more-compatible version5.txt /*more-compatible*
more-prompt message.txt /*more-prompt*
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 30f8a1e16..0c2869a01 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -619,8 +619,12 @@ au BufNewFile,BufRead *.intr setf
dylanintr
" Dylan
au BufNewFile,BufRead *.dylan setf dylan
-" Microsoft Module Definition
-au BufNewFile,BufRead *.def setf def
+" Microsoft Module Definition or Modula-2
+au BufNewFile,BufRead *.def call dist#ft#FTdef()
+
+if has("fname_case")
+ au BufNewFile,BufRead *.DEF setf modula2
+endif
" Dracula
au BufNewFile,BufRead *.drac,*.drc,*lvs,*lpe setf dracula
@@ -1339,9 +1343,6 @@ au BufNewFile,BufRead *.mmp setf mmp
" ABB Rapid, Modula-2, Modsim III or LambdaProlog
au BufNewFile,BufRead *.mod
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/E1rLnmi-00EUCj-6S%40256bit.org.