Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime: Miranda files are not recognised #13952

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ runtime/ftplugin/m3build.vim @dkearns
runtime/ftplugin/m3quake.vim @dkearns
runtime/ftplugin/markdown.vim @tpope
runtime/ftplugin/meson.vim @Liambeguin
runtime/ftplugin/miranda.vim @dkearns
runtime/ftplugin/modula2.vim @dkearns
runtime/ftplugin/modula3.vim @dkearns
runtime/ftplugin/nginx.vim @chr4
Expand Down Expand Up @@ -428,6 +429,7 @@ runtime/syntax/mallard.vim @jhradilek
runtime/syntax/markdown.vim @tpope
runtime/syntax/mason.vim @petdance
runtime/syntax/meson.vim @Liambeguin
runtime/syntax/miranda.vim @dkearns
runtime/syntax/modula2.vim @dkearns
runtime/syntax/modula2/opt/iso.vim @trijezdci
runtime/syntax/modula2/opt/pim.vim @trijezdci
Expand Down
29 changes: 21 additions & 8 deletions runtime/autoload/dist/ft.vim
Original file line number Diff line number Diff line change
Expand Up @@ -439,13 +439,17 @@ export def FTm()

# excluding end(for|function|if|switch|while) common to Murphi
var octave_block_terminators = '\<end\%(_try_catch\|classdef\|enumeration\|events\|methods\|parfor\|properties\)\>'

var objc_preprocessor = '^\s*#\s*\%(import\|include\|define\|if\|ifn\=def\|undef\|line\|error\|pragma\)\>'

var n = 1
var saw_comment = 0 # Whether we've seen a multiline comment leader.
while n < 100
var line = getline(n)

# shebang lines have lower priority than content detection and complicate
# Miranda and Octave tests, so consider line 2 the first relevant line of
# the file
var line1 = getline(1) =~ '^#!' ? 2 : 1

for lnum in range(line1, min([100, line("$")]))
var line = getline(lnum)
if line =~ '^\s*/\*'
# /* ... */ is a comment in Objective C and Murphi, so we can't conclude
# it's either of them yet, but track this as a hint in case we don't see
Expand All @@ -457,15 +461,25 @@ export def FTm()
return
endif
if line =~ '^\s*\%(#\|%!\)' || line =~ '^\s*unwind_protect\>' ||
\ line =~ '\%(^\|;\)\s*' .. octave_block_terminators
line =~ '\%(^\|;\)\s*' .. octave_block_terminators
setf octave
return
endif
# TODO: could be Matlab or Octave
# TODO: could be Matlab, Miranda or Octave
if line =~ '^\s*%'
setf matlab
return
endif
if line =~ '^||'
miranda#SetFileTypeInfo({ literate: false } )
setf miranda
return
endif
if line =~ '^>' && lnum == line1
miranda#SetFileTypeInfo({ literate: true } )
setf miranda
return
endif
if line =~ '^\s*(\*'
setf mma
return
Expand All @@ -474,8 +488,7 @@ export def FTm()
setf murphi
return
endif
n += 1
endwhile
endfor

if saw_comment
# We didn't see anything definitive, but this looks like either Objective C
Expand Down
4 changes: 4 additions & 0 deletions runtime/autoload/dist/script.vim
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ export def Exe2filetype(name: string, line1: string): string
elseif name =~ '^execlineb\>'
return 'execline'

# Miranda script
elseif name =~ '^mira\>'
return 'miranda'

endif

return ''
Expand Down
30 changes: 30 additions & 0 deletions runtime/autoload/miranda.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
" Vim filetype plugin file
" Language: Miranda
" Maintainer: Doug Kearns <[email protected]>
" Last Change: 2024 Feb 01

function miranda#GetFileTypeInfo() abort
if exists("b:miranda")
return b:miranda
endif

if exists("g:miranda_default_literate")
let literate = g:miranda_default_literate
else
let literate = v:false
endif

return #{ literate: literate }
endfunction

function miranda#SetFileTypeInfo(info) abort
if exists("b:miranda")
unlockvar! b:miranda
endif

let b:miranda = a:info
lockvar! b:miranda
endfunction

" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:

5 changes: 5 additions & 0 deletions runtime/doc/syntax.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,11 @@ have the following in your .vimrc: >
let filetype_m = "mma"


MIRANDA *miranda.vim* *ft-miranda-syntax*

TODO


MODULA2 *modula2.vim* *ft-modula2-syntax*

Vim will recognise comments with dialect tags to automatically select a given
Expand Down
2 changes: 2 additions & 0 deletions runtime/doc/tags
Original file line number Diff line number Diff line change
Expand Up @@ -7322,6 +7322,7 @@ ft-metapost-commands ft_mp.txt /*ft-metapost-commands*
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-miranda-syntax syntax.txt /*ft-miranda-syntax*
ft-mma-syntax syntax.txt /*ft-mma-syntax*
ft-modula2-syntax syntax.txt /*ft-modula2-syntax*
ft-moo-syntax syntax.txt /*ft-moo-syntax*
Expand Down Expand Up @@ -8710,6 +8711,7 @@ meta intro.txt /*meta*
method eval.txt /*method*
mf.vim ft_mp.txt /*mf.vim*
min() builtin.txt /*min()*
miranda.vim syntax.txt /*miranda.vim*
missing-options vi_diff.txt /*missing-options*
mkdir() builtin.txt /*mkdir()*
mlang.txt mlang.txt /*mlang.txt*
Expand Down
5 changes: 4 additions & 1 deletion runtime/filetype.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1393,7 +1393,10 @@ au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md
" Mason
au BufNewFile,BufRead *.mason,*.mhtml,*.comp setf mason

" Mathematica, Matlab, Murphi, Objective C or Octave
" Mathematica, Matlab, Miranda, Murphi, Objective C or Octave
au BufNewFile,BufRead *.lit.m
\ call miranda#SetFileTypeInfo(#{ literate: v:true }) |
\ setf miranda
au BufNewFile,BufRead *.m call dist#ft#FTm()

" Mathematica notebook
Expand Down
35 changes: 35 additions & 0 deletions runtime/ftplugin/miranda.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
" Vim filetype plugin file
" Language: Miranda
" Maintainer: Doug Kearns <[email protected]>
" Last Change: 2024 May 14

if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1

setlocal comments=:\|\|
setlocal commentstring=\|\|\ %s
setlocal formatoptions+=croql formatoptions-=t

setlocal iskeyword=a-z,A-Z,48-57,_,'

let &l:include = '%\%(insert\|include\)'
setlocal suffixes+=.x
setlocal suffixesadd=.m

let b:undo_ftplugin = "setl cms< com< fo< inc< isk< su< sua<"

if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
let b:browsefilter =
\ "Miranda Script Files (*.m)\t*.m\n" ..
\ "Miranda Literate Script Files (*.lit.m)\t*.lit.m\n"
if has("win32")
let b:browsefilter ..= "All Files (*.*)\t*\n"
else
let b:browsefilter ..= "All Files (*)\t*\n"
endif
let b:undo_ftplugin ..= " | unlet! b:browsefilter"
endif

" vim: nowrap sw=2 sts=2 ts=8 noet:
30 changes: 30 additions & 0 deletions runtime/syntax/miranda.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
" Vim syntax file
" Language: Miranda
" Maintainer: Doug Kearns <[email protected]>
" Last Change: 2024 May 14

if exists("b:current_syntax")
finish
endif

syn iskeyword a-z,A-Z,48-57,_,'

if miranda#GetFileTypeInfo().literate
syn include @mirandaTop syntax/shared/miranda.vim
syn region mirandaLiterate start="^[^>[:space:]]" end="^\ze\%(\s*\n\)*>\|\%$"
syn region mirandaProgram start="^>" skip="^>" end="^\ze\s*$\|\%$" contains=@mirandaTop

syn sync linebreaks=2

hi def link mirandaLiterate Comment
else
runtime! syntax/shared/miranda.vim
endif

syn match mirandaSharpBang /\%^#!.*/ display

hi def link mirandaSharpBang PreProc

let b:current_syntax = "miranda"

" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
92 changes: 92 additions & 0 deletions runtime/syntax/shared/miranda.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
" Vim syntax file
" Language: Miranda
" Maintainer: Doug Kearns <[email protected]>
" Last Change: 2024 May 14

syn iskeyword a-z,A-Z,48-57,_,'

" Operators {{{1
" list
syn match mirandaOperator /\%([:#!]\|++\|--\)/
" relational
syn match mirandaOperator _\%(\\/\|&\|\~\)\|\%(>\|>=\|=\|\~=\|<=\|<\)_
" arithmetic
syn match mirandaOperator _[+\-*/^]_
syn keyword mirandaOperator div mod
" function
syn match mirandaOperator /\.\|$\a\@=/

" Reserved {{{1
syn keyword mirandaReserved
\ abstype if otherwise readvals show type where with
"\ div mod

" Functions {{{1
syn keyword mirandaFunction
\ abs and arctan cjustify code concat const converse cos decode digit
\ drop dropwhile e entier error exp filemode filter foldl foldl1 foldr
\ foldr1 force fst getenv hd hugenum id index init integer iterate last
\ lay layn letter limit lines ljustify log log10 map map2 max max2
\ member merge min min2 mkset neg numval or pi postfix product read
\ readb rep repeat reverse rjustify scan seq showfloat showhex shownum
\ showoct showscaled sin snd sort spaces sqrt subtract sum system take
\ takewhile tinynum tl transpose undef until zip2 zip3 zip4 zip5 zip6
\ zip

" Constants {{{1
syn keyword mirandaConstant e pi tinynum
syn keyword mirandaUndef undef

" Constructors {{{1
syn keyword mirandaFunction
\ Appendfile Appendfileb Closefile Exit Stderr Stdout Stdoutb System
\ Tofile Tofileb

syn keyword mirandaType bool char num sys_message
" syn match mirandaTypeVar /\*\+/

" Literals {{{1
syn keyword mirandaBoolean True False

" Numbers {{{2
syn match mirandaNatural /\<\d\+\>/ display
syn match mirandaFloat /\<\d\+e[+-]\=\d\+\>/ display
syn match mirandaFloat /\<\d*\.\d\+\%(e[+-]\=\d\+\)\=/ display

" Strings {{{2
" syn match mirandaEscape /\\[ntfrb\\'"]/ contained
syn match mirandaEscape /\\./ contained
syn match mirandaEscape /\\\d\{1,3}/ contained
syn match mirandaEscape /\\$/ contained

syn match mirandaCharacter /\<'\%(\\.\|\%(\\$\n\)\=[[:print:]]\)'\>/ contains=mirandaEscape
syn region mirandaString start=/"/ skip=/\\\\\|\\"\|\\$/ end=/"/ end=/$/ contains=mirandaEscape,mirandaEscapeError

" Comments {{{1
syn keyword mirandaTodo contained TODO FIXME XXX NOTE
syn match mirandaComment /||.*/ contains=mirandaTodo,@Spell

" Compiler directives {{{1
syn match mirandaCompilerDirective /%\%(list\|nolist\)\>/
syn match mirandaCompilerDirective /%\%(include\|insert\)\>/ nextgroup=mirandaFileId skipwhite
syn region mirandaFileId start=/</ end=/>/ contained oneline
syn region mirandaFileId start=/"/ end=/"/ contained oneline
syn match mirandaCompilerDirective /%\%(export\|free\)\>/

" Highlighting {{{1
hi def link mirandaBoolean Boolean
hi def link mirandaCharacter Character
hi def link mirandaComment Comment
hi def link mirandaCompilerDirective PreProc
hi def link mirandaConstant Constant
hi def link mirandaEscape Special
hi def link mirandaFileId mirandaString
hi def link mirandaFloat Float
hi def link mirandaFunction Function
hi def link mirandaNatural Number
hi def link mirandaOperator Operator
hi def link mirandaReserved Keyword
hi def link mirandaString String
hi def link mirandaType Type

" vim: nowrap sw=2 sts=2 ts=8 noet fdm=marker:
20 changes: 20 additions & 0 deletions runtime/syntax/testdir/dumps/miranda-lit_00.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
>>+0#af5f00255#ffffff0| +0#0000000&||+0#0000e05&@1| |A| |M|i|r|a|n|d|a| |l|i|t|e|r|a|t|e| |s|c|r|i|p|t| |s|p|e|c|i|f|i|e|d| |b|y| |f|o|r|m|a|l|i|s|i|n|g| |s|y|m|b|o|l| |'|>|'|.| +0#0000000&@7
@75
|>+0#af5f00255&| +0#0000000&@1|f|a|c| |0+0#e000002&| +0#0000000&|=+0#af5f00255&| +0#0000000&|1+0#e000002&| +0#0000000&@62
|>+0#af5f00255&| +0#0000000&@1|f|a|c| |(|n| |++0#af5f00255&| +0#0000000&|1+0#e000002&|)+0#0000000&| |=+0#af5f00255&| +0#0000000&|(|n| |++0#af5f00255&| +0#0000000&|1+0#e000002&|)+0#0000000&| |*+0#af5f00255&| +0#0000000&|f|a|c| |n| @42
@75
|S+0#0000e05&|o|m|e| |c|l|o|s|i|n|g| |t|e|x|t|.| +0#0000000&@56
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
| +0#0000000&@56|1|,|1| @10|A|l@1|
20 changes: 20 additions & 0 deletions runtime/syntax/testdir/dumps/miranda-lit_99.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
|>+0#af5f00255#ffffff0| +0#0000000&||+0#0000e05&@1| |A| |M|i|r|a|n|d|a| |l|i|t|e|r|a|t|e| |s|c|r|i|p|t| |s|p|e|c|i|f|i|e|d| |b|y| |f|o|r|m|a|l|i|s|i|n|g| |s|y|m|b|o|l| |'|>|'|.| +0#0000000&@7
@75
|>+0#af5f00255&| +0#0000000&@1|f|a|c| |0+0#e000002&| +0#0000000&|=+0#af5f00255&| +0#0000000&|1+0#e000002&| +0#0000000&@62
|>+0#af5f00255&| +0#0000000&@1|f|a|c| |(|n| |++0#af5f00255&| +0#0000000&|1+0#e000002&|)+0#0000000&| |=+0#af5f00255&| +0#0000000&|(|n| |++0#af5f00255&| +0#0000000&|1+0#e000002&|)+0#0000000&| |*+0#af5f00255&| +0#0000000&|f|a|c| |n| @42
@75
>S+0#0000e05&|o|m|e| |c|l|o|s|i|n|g| |t|e|x|t|.| +0#0000000&@56
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
| +0#0000000&@56|6|,|1| @10|A|l@1|
20 changes: 20 additions & 0 deletions runtime/syntax/testdir/dumps/miranda.lit_00.dump
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
>A+0#0000e05#ffffff0| |M|i|r|a|n|d|a| |l|i|t|e|r|a|t|e| |s|c|r|i|p|t| |s|p|e|c|i|f|i|e|d| |b|y| |f|i|l|e|n|a|m|e| |e|x|t|e|n|s|i|o|n| |'|*|.|l|i|t|.|m|'|.| +0#0000000&@6
@75
|>+0#af5f00255&| +0#0000000&@1|f|a|c| |0+0#e000002&| +0#0000000&|=+0#af5f00255&| +0#0000000&|1+0#e000002&| +0#0000000&@62
|>+0#af5f00255&| +0#0000000&@1|f|a|c| |(|n| |++0#af5f00255&| +0#0000000&|1+0#e000002&|)+0#0000000&| |=+0#af5f00255&| +0#0000000&|(|n| |++0#af5f00255&| +0#0000000&|1+0#e000002&|)+0#0000000&| |*+0#af5f00255&| +0#0000000&|f|a|c| |n| @42
@75
|S+0#0000e05&|o|m|e| |c|l|o|s|i|n|g| |t|e|x|t|.| +0#0000000&@56
|~+0#4040ff13&| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
|~| @73
| +0#0000000&@56|1|,|1| @10|A|l@1|