Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion ftplugin/orca.vim
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ function! s:DetectBlock()
endfunction

" Inline directives that look like blocks but have no 'end' and no skeleton.
let s:inline_directives = ['maxcore', 'moinp', 'moread']
let s:inline_directives = ['compound', 'maxcore', 'moinp', 'moread']

" Completion items for block names. Full blocks carry user_data so MaybeSkeleton
" inserts the skeleton; inline directives don't.
Expand Down Expand Up @@ -556,6 +556,12 @@ function! s:IsMOInpLine()
return before =~? '^\s*%moinp\s'
endfunction

" True when cursor is past %compound (ready for the .cmp filename).
function! s:IsCompoundLine()
let before = strpart(getline('.'), 0, col('.') - 1)
return before =~? '^\s*%compound\s'
endfunction

" Candidates for the current cursor context (bang line or inside a block).
function! s:Candidates(base)
let line = getline('.')
Expand All @@ -570,6 +576,11 @@ function! s:Candidates(base)
return map(glob(dir . '/' . a:base . '*.gbw', 0, 1), {_, f -> fnamemodify(f, ':t')})
endif

if s:IsCompoundLine()
let dir = expand('%:p:h')
return map(glob(dir . '/' . a:base . '*.cmp', 0, 1), {_, f -> fnamemodify(f, ':t')})
endif

let block = s:DetectBlock()
if !empty(block) && has_key(g:orca_block_params, block)
return s:FilterList(g:orca_block_params[block], a:base)
Expand Down Expand Up @@ -678,6 +689,25 @@ function! s:AutoTrigger()
" which calls s:Candidates → s:IsMOInpLine path for prefix filtering
endif

" %compound line: auto-insert "" on first space, then complete .cmp inside them
if s:IsCompoundLine()
if ch ==# ' ' && getline('.') =~? '^\s*%compound\s*$'
" First space after %compound: insert "", park cursor inside, trigger omni
call feedkeys('""' . "\<Left>" . "\<C-x>\<C-o>", 'n')
return
endif
if ch ==# '"'
" Opening quote typed manually: show all cmp files
let matches = s:Candidates('')
if !empty(matches)
call complete(col + 1, matches)
endif
return
endif
" \w chars inside quotes fall through to the general handler below,
" which calls s:Candidates → s:IsCompoundLine path for prefix filtering
endif

" Block solvent-value context triggered by space: 'smdsolvent |'
if ch ==# ' '
let m = matchlist(strpart(line, 0, col - 1), '^\s*\(\w\+\)\s*$\c')
Expand Down Expand Up @@ -757,6 +787,14 @@ function! s:MaybeSkeleton()
return
endif

" After a .cmp completion on a %compound line, add closing " if not present
if getline('.') =~? '^\s*%compound\s'
if !empty(get(item, 'word', '')) && getline('.')[col('.') - 1] !=# '"'
call feedkeys('"', 'n')
endif
return
endif

if get(item, 'user_data', '') !~# '^block:' | return | endif
let lnum = line('.')
call append(lnum, [repeat(' ', shiftwidth()), 'end'])
Expand Down
10 changes: 7 additions & 3 deletions syntax/orca.vim
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,9 @@ syn keyword orcaBasis contained PCH-1 PCH-2 PCH-3 PCH-4 AUG-PCH-1 AUG-PCH-2 AUG-

" ============================================================
" Block directives (% ... end)
" - Inline directives: %maxcore, %moread (no end)
" - Inline directives: %maxcore, %moread, %moinp, and the file form of
" %compound (no end). These must NOT appear in the methodBlock start=
" alternation, or the region swallows everything until the next col-0 'end'.
" - Paired regions: all others
" To add a new block:
" 1. append its name to the methodBlock start= alternation below
Expand All @@ -1266,18 +1268,20 @@ syn keyword orcaBasis contained PCH-1 PCH-2 PCH-3 PCH-4 AUG-PCH-1 AUG-PCH-2 AUG-
syn match orcaBlock "%maxcore\>" contains=startBlock
syn match orcaBlock "%moread\>" contains=startBlock
syn match orcaBlock "%moinp\>" contains=startBlock
syn match orcaBlock "%compound\>" contains=startBlock

" block directive regions
" end= matches 'end' only at column 0 (no leading whitespace), so indented
" 'end' tokens closing sub-blocks (e.g. CASDFT...end, Constraints...end)
" do not close the outer block region.
" To add a new block: add its name to the alternation below AND to orcaBlock above.
syn region methodBlock
\ start="%\(method\|basis\|scf\|mp2\|cis\|tddft\|mrci\|geom\|freq\|vpt2\|esd\|dftmrci\|moinp\)"
\ start="%\(method\|basis\|scf\|mp2\|cis\|tddft\|mrci\|geom\|freq\|vpt2\|esd\|dftmrci\)"
\ start="%\(coords\|output\|ci\|plots\|parameters\|ndoparas\|rel\|dkh\|pal\|cosmo\|rr\)"
\ start="%\(eprnmr\|loc\|elprop\|casscf\|mcrpa\|mdci\|dlpnocc\|mm\|mtr\|xes\|chelpg\)"
\ start="%\(numgrad\|mecp\|ecp\|rocis\|mrcc\|cipsi\|ice\|iceci\|md\|nbo\|lft\|autoci\)"
\ start="%\(cpcm\|cim\|compound\|neb\|irc\|anmr\|cregen\|confscript\|anmrrc\|qmmm\)"
\ start="%\(cpcm\|cim\|neb\|irc\|anmr\|cregen\|confscript\|anmrrc\|qmmm\)"
\ start="%compound\s*$"
\ start="%\(conical\|ecrism\|shark\|symmetry\|sym\|xtb\|goat\|docker\|solvator\)"
\ start="%\(casresp\|frag\|casdft\|mcd\|qgprop\|magrelax\|eda\)"
\ end="^end\>"
Expand Down
7 changes: 7 additions & 0 deletions test/example.inp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
H 0.630 -0.630 -0.630
*

# ------------------------------------------------------------------------------
# Inline directives (no end) - must not swallow highlighting of lines below
# ------------------------------------------------------------------------------
%maxcore 4000
%moinp "previous.gbw"
%compound "workflow.cmp"

# ------------------------------------------------------------------------------
%pal
nprocs 8
Expand Down