Mercurial > vim
comparison runtime/autoload/dist/ft.vim @ 34092:ff27442e7851 v9.1.0013
patch 9.1.0013: Modula2 filetype support lacking
Commit: https://github.com/vim/vim/commit/68a89470693c7687d4e736ca056c05de632e3ac7
Author: Doug Kearns <dougkearns@gmail.com>
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 <dougkearns@gmail.com>
Signed-off-by: Benjamin Kowarsch <trijezdci@users.noreply.github.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 05 Jan 2024 18:15:04 +0100 |
parents | e2e9bb5496a5 |
children | b534715fa52c |
comparison
equal
deleted
inserted
replaced
34091:27bd5d0816e0 | 34092:ff27442e7851 |
---|---|
1 vim9script | 1 vim9script |
2 | 2 |
3 # Vim functions for file type detection | 3 # Vim functions for file type detection |
4 # | 4 # |
5 # Maintainer: The Vim Project <https://github.com/vim/vim> | 5 # Maintainer: The Vim Project <https://github.com/vim/vim> |
6 # Last Change: 2023 Aug 10 | 6 # Last Change: 2024 Jan 05 |
7 # Former Maintainer: Bram Moolenaar <Bram@vim.org> | 7 # Former Maintainer: Bram Moolenaar <Bram@vim.org> |
8 | 8 |
9 # These functions are moved here from runtime/filetype.vim to make startup | 9 # These functions are moved here from runtime/filetype.vim to make startup |
10 # faster. | 10 # faster. |
11 | 11 |
277 else | 277 else |
278 setf d | 278 setf d |
279 endif | 279 endif |
280 enddef | 280 enddef |
281 | 281 |
282 export def FTdef() | |
283 if get(g:, "filetype_def", "") == "modula2" || IsModula2() | |
284 SetFiletypeModula2() | |
285 return | |
286 endif | |
287 | |
288 if exists("g:filetype_def") | |
289 exe "setf " .. g:filetype_def | |
290 else | |
291 setf def | |
292 endif | |
293 enddef | |
294 | |
282 export def FTe() | 295 export def FTe() |
283 if exists('g:filetype_euphoria') | 296 if exists('g:filetype_euphoria') |
284 exe 'setf ' .. g:filetype_euphoria | 297 exe 'setf ' .. g:filetype_euphoria |
285 else | 298 else |
286 var n = 1 | 299 var n = 1 |
515 endwhile | 528 endwhile |
516 # this pattern must not catch a go.mod file | 529 # this pattern must not catch a go.mod file |
517 return getline(lnum) =~ '\<module\s\+\w\+\s*\.\s*\(%\|$\)' | 530 return getline(lnum) =~ '\<module\s\+\w\+\s*\.\s*\(%\|$\)' |
518 enddef | 531 enddef |
519 | 532 |
533 def IsModula2(): bool | |
534 return getline(nextnonblank(1)) =~ '\<MODULE\s\+\w\+\s*;\|^\s*(\*' | |
535 enddef | |
536 | |
537 def SetFiletypeModula2() | |
538 const KNOWN_DIALECTS = ["iso", "pim", "r10"] | |
539 const KNOWN_EXTENSIONS = ["gm2"] | |
540 const LINE_COUNT = 200 | |
541 const TAG = '(\*!m2\(\w\+\)\%(+\(\w\+\)\)\=\*)' | |
542 | |
543 var dialect = get(g:, "modula2_default_dialect", "pim") | |
544 var extension = get(g:, "modula2_default_extension", "") | |
545 | |
546 var matches = [] | |
547 | |
548 # ignore unknown dialects or badly formatted tags | |
549 for lnum in range(1, min([line("$"), LINE_COUNT])) | |
550 matches = matchlist(getline(lnum), TAG) | |
551 if !empty(matches) | |
552 if index(KNOWN_DIALECTS, matches[1]) >= 0 | |
553 dialect = matches[1] | |
554 endif | |
555 if index(KNOWN_EXTENSIONS, matches[2]) >= 0 | |
556 extension = matches[2] | |
557 endif | |
558 break | |
559 endif | |
560 endfor | |
561 | |
562 modula2#SetDialect(dialect, extension) | |
563 | |
564 setf modula2 | |
565 enddef | |
566 | |
520 # Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod | 567 # Determine if *.mod is ABB RAPID, LambdaProlog, Modula-2, Modsim III or go.mod |
521 export def FTmod() | 568 export def FTmod() |
569 if get(g:, "filetype_mod", "") == "modula2" || IsModula2() | |
570 SetFiletypeModula2() | |
571 return | |
572 endif | |
573 | |
522 if exists("g:filetype_mod") | 574 if exists("g:filetype_mod") |
523 exe "setf " .. g:filetype_mod | 575 exe "setf " .. g:filetype_mod |
524 elseif expand("<afile>") =~ '\<go.mod$' | 576 elseif expand("<afile>") =~ '\<go.mod$' |
525 setf gomod | 577 setf gomod |
526 elseif IsLProlog() | 578 elseif IsLProlog() |
527 setf lprolog | 579 setf lprolog |
528 elseif getline(nextnonblank(1)) =~ '\%(\<MODULE\s\+\w\+\s*;\|^\s*(\*\)' | |
529 setf modula2 | |
530 elseif IsRapid() | 580 elseif IsRapid() |
531 setf rapid | 581 setf rapid |
532 else | 582 else |
533 # Nothing recognized, assume modsim3 | 583 # Nothing recognized, assume modsim3 |
534 setf modsim3 | 584 setf modsim3 |
1241 setf vb | 1291 setf vb |
1242 endif | 1292 endif |
1243 enddef | 1293 enddef |
1244 | 1294 |
1245 # Uncomment this line to check for compilation errors early | 1295 # Uncomment this line to check for compilation errors early |
1246 # defcompile | 1296 defcompile |