blob: d4bb6fe777a20c0ae3558c6ea8d99cff3e9a56de [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
2" Language: Abaqus finite element input file (www.abaqus.com)
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +01003" Maintainer: Carl Osterwisch <costerwi@gmail.com>
Bram Moolenaar3c053a12022-10-16 13:11:12 +01004" Last Change: 2022 Oct 08
Doug Kearns93197fd2024-01-14 20:59:02 +01005" 2024 Jan 14 by Vim Project (browsefilter)
Riley Bruins0a083062024-06-03 20:40:45 +02006" 2024 May 23 by Riley Bruins <ribru17@gmail.com> ('commentstring')
Bram Moolenaar071d4272004-06-13 20:20:40 +00007
8" Only do this when not done yet for this buffer
9if exists("b:did_ftplugin") | finish | endif
10
11" Don't load another plugin for this buffer
12let b:did_ftplugin = 1
13
14" Save the compatibility options and temporarily switch to vim defaults
15let s:cpo_save = &cpoptions
16set cpoptions&vim
17
Bram Moolenaar071d4272004-06-13 20:20:40 +000018" Set the format of the include file specification for Abaqus
19" Used in :check gf ^wf [i and other commands
20setlocal include=\\<\\cINPUT\\s*=
21
22" Remove characters up to the first = when evaluating filenames
23setlocal includeexpr=substitute(v:fname,'.\\{-}=','','')
24
Bram Moolenaar8299df92004-07-10 09:47:34 +000025" Remove comma from valid filename characters since it is used to
26" separate keyword parameters
27setlocal isfname-=,
28
Bram Moolenaar071d4272004-06-13 20:20:40 +000029" Define format of comment lines (see 'formatoptions' for uses)
30setlocal comments=:**
Riley Bruins0a083062024-06-03 20:40:45 +020031setlocal commentstring=**\ %s
Bram Moolenaar071d4272004-06-13 20:20:40 +000032
33" Definitions start with a * and assign a NAME, NSET, or ELSET
34" Used in [d ^wd and other commands
35setlocal define=^\\*\\a.*\\c\\(NAME\\\|NSET\\\|ELSET\\)\\s*=
36
37" Abaqus keywords and identifiers may include a - character
38setlocal iskeyword+=-
39
Bram Moolenaar5c736222010-01-06 20:54:52 +010040let b:undo_ftplugin = "setlocal include< includeexpr< isfname<"
41 \ . " comments< commentstring< define< iskeyword<"
42
43if has("folding")
44 " Fold all lines that do not begin with *
45 setlocal foldexpr=getline(v:lnum)[0]!=\"\*\"
46 setlocal foldmethod=expr
47 let b:undo_ftplugin .= " foldexpr< foldmethod<"
48endif
49
Bram Moolenaar071d4272004-06-13 20:20:40 +000050" Set the file browse filter (currently only supported under Win32 gui)
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010051if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000052 let b:browsefilter = "Abaqus Input Files (*.inp *.inc)\t*.inp;*.inc\n" .
53 \ "Abaqus Results (*.dat)\t*.dat\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010054 \ "Abaqus Messages (*.pre, *.msg, *.sta)\t*.pre;*.msg;*.sta\n"
55 if has("win32")
56 let b:browsefilter .= "All Files (*.*)\t*\n"
57 else
58 let b:browsefilter .= "All Files (*)\t*\n"
59 endif
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020060 let b:undo_ftplugin .= "|unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000061endif
62
Bram Moolenaar5c736222010-01-06 20:54:52 +010063" Define patterns for the matchit plugin
64if exists("loaded_matchit") && !exists("b:match_words")
65 let b:match_ignorecase = 1
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010066 let b:match_words =
Bram Moolenaar5c736222010-01-06 20:54:52 +010067 \ '\*part:\*end\s*part,' .
68 \ '\*assembly:\*end\s*assembly,' .
69 \ '\*instance:\*end\s*instance,' .
70 \ '\*step:\*end\s*step'
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020071 let b:undo_ftplugin .= "|unlet! b:match_ignorecase b:match_words"
Bram Moolenaar5c736222010-01-06 20:54:52 +010072endif
73
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010074if !exists("no_plugin_maps") && !exists("no_abaqus_maps")
Bram Moolenaar3c053a12022-10-16 13:11:12 +010075 " Map [[ and ]] keys to move [count] keywords backward or forward
76 nnoremap <silent><buffer> ]] :call <SID>Abaqus_NextKeyword(1)<CR>
77 nnoremap <silent><buffer> [[ :call <SID>Abaqus_NextKeyword(-1)<CR>
78 function! <SID>Abaqus_NextKeyword(direction)
79 .mark '
80 if a:direction < 0
81 let flags = 'b'
82 else
83 let flags = ''
84 endif
85 let l:count = abs(a:direction) * v:count1
86 while l:count > 0 && search("^\\*\\a", flags)
87 let l:count -= 1
88 endwhile
89 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +000090
Bram Moolenaar3c053a12022-10-16 13:11:12 +010091 " Map \\ to toggle commenting of the current line or range
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010092 noremap <silent><buffer> <LocalLeader><LocalLeader>
93 \ :call <SID>Abaqus_ToggleComment()<CR>j
94 function! <SID>Abaqus_ToggleComment() range
Bram Moolenaar3c053a12022-10-16 13:11:12 +010095 if strpart(getline(a:firstline), 0, 2) == "**"
96 " Un-comment all lines in range
97 silent execute a:firstline . ',' . a:lastline . 's/^\*\*//'
98 else
99 " Comment all lines in range
100 silent execute a:firstline . ',' . a:lastline . 's/^/**/'
101 endif
102 endfunction
103
104 " Map \s to swap first two comma separated fields
105 noremap <silent><buffer> <LocalLeader>s :call <SID>Abaqus_Swap()<CR>
106 function! <SID>Abaqus_Swap() range
107 silent execute a:firstline . ',' . a:lastline . 's/\([^*,]*\),\([^,]*\)/\2,\1/'
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100108 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100110 let b:undo_ftplugin .= "|unmap <buffer> [[|unmap <buffer> ]]"
111 \ . "|unmap <buffer> <LocalLeader><LocalLeader>"
Bram Moolenaar3c053a12022-10-16 13:11:12 +0100112 \ . "|unmap <buffer> <LocalLeader>s"
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100113endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100114
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200115" Undo must be done in nocompatible mode for <LocalLeader>.
Bram Moolenaar921bde82022-05-09 19:50:35 +0100116let b:undo_ftplugin = "let b:cpo_save = &cpoptions|"
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200117 \ . "set cpoptions&vim|"
118 \ . b:undo_ftplugin
Bram Moolenaar921bde82022-05-09 19:50:35 +0100119 \ . "|let &cpoptions = b:cpo_save"
120 \ . "|unlet b:cpo_save"
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200121
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122" Restore saved compatibility options
123let &cpoptions = s:cpo_save
Bram Moolenaar84f72352012-03-11 15:57:40 +0100124unlet s:cpo_save