blob: 5931cd921de0029a01219d4cbd8aa8e3432e0799 [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
Bram Moolenaar071d4272004-06-13 20:20:40 +00005
6" Only do this when not done yet for this buffer
7if exists("b:did_ftplugin") | finish | endif
8
9" Don't load another plugin for this buffer
10let b:did_ftplugin = 1
11
12" Save the compatibility options and temporarily switch to vim defaults
13let s:cpo_save = &cpoptions
14set cpoptions&vim
15
Bram Moolenaar071d4272004-06-13 20:20:40 +000016" Set the format of the include file specification for Abaqus
17" Used in :check gf ^wf [i and other commands
18setlocal include=\\<\\cINPUT\\s*=
19
20" Remove characters up to the first = when evaluating filenames
21setlocal includeexpr=substitute(v:fname,'.\\{-}=','','')
22
Bram Moolenaar8299df92004-07-10 09:47:34 +000023" Remove comma from valid filename characters since it is used to
24" separate keyword parameters
25setlocal isfname-=,
26
Bram Moolenaar071d4272004-06-13 20:20:40 +000027" Define format of comment lines (see 'formatoptions' for uses)
28setlocal comments=:**
29setlocal commentstring=**%s
30
31" Definitions start with a * and assign a NAME, NSET, or ELSET
32" Used in [d ^wd and other commands
33setlocal define=^\\*\\a.*\\c\\(NAME\\\|NSET\\\|ELSET\\)\\s*=
34
35" Abaqus keywords and identifiers may include a - character
36setlocal iskeyword+=-
37
Bram Moolenaar5c736222010-01-06 20:54:52 +010038let b:undo_ftplugin = "setlocal include< includeexpr< isfname<"
39 \ . " comments< commentstring< define< iskeyword<"
40
41if has("folding")
42 " Fold all lines that do not begin with *
43 setlocal foldexpr=getline(v:lnum)[0]!=\"\*\"
44 setlocal foldmethod=expr
45 let b:undo_ftplugin .= " foldexpr< foldmethod<"
46endif
47
Bram Moolenaar071d4272004-06-13 20:20:40 +000048" Set the file browse filter (currently only supported under Win32 gui)
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010049if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000050 let b:browsefilter = "Abaqus Input Files (*.inp *.inc)\t*.inp;*.inc\n" .
51 \ "Abaqus Results (*.dat)\t*.dat\n" .
52 \ "Abaqus Messages (*.pre *.msg *.sta)\t*.pre;*.msg;*.sta\n" .
53 \ "All Files (*.*)\t*.*\n"
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020054 let b:undo_ftplugin .= "|unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000055endif
56
Bram Moolenaar5c736222010-01-06 20:54:52 +010057" Define patterns for the matchit plugin
58if exists("loaded_matchit") && !exists("b:match_words")
59 let b:match_ignorecase = 1
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010060 let b:match_words =
Bram Moolenaar5c736222010-01-06 20:54:52 +010061 \ '\*part:\*end\s*part,' .
62 \ '\*assembly:\*end\s*assembly,' .
63 \ '\*instance:\*end\s*instance,' .
64 \ '\*step:\*end\s*step'
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020065 let b:undo_ftplugin .= "|unlet! b:match_ignorecase b:match_words"
Bram Moolenaar5c736222010-01-06 20:54:52 +010066endif
67
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010068if !exists("no_plugin_maps") && !exists("no_abaqus_maps")
Bram Moolenaar3c053a12022-10-16 13:11:12 +010069 " Map [[ and ]] keys to move [count] keywords backward or forward
70 nnoremap <silent><buffer> ]] :call <SID>Abaqus_NextKeyword(1)<CR>
71 nnoremap <silent><buffer> [[ :call <SID>Abaqus_NextKeyword(-1)<CR>
72 function! <SID>Abaqus_NextKeyword(direction)
73 .mark '
74 if a:direction < 0
75 let flags = 'b'
76 else
77 let flags = ''
78 endif
79 let l:count = abs(a:direction) * v:count1
80 while l:count > 0 && search("^\\*\\a", flags)
81 let l:count -= 1
82 endwhile
83 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +000084
Bram Moolenaar3c053a12022-10-16 13:11:12 +010085 " Map \\ to toggle commenting of the current line or range
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010086 noremap <silent><buffer> <LocalLeader><LocalLeader>
87 \ :call <SID>Abaqus_ToggleComment()<CR>j
88 function! <SID>Abaqus_ToggleComment() range
Bram Moolenaar3c053a12022-10-16 13:11:12 +010089 if strpart(getline(a:firstline), 0, 2) == "**"
90 " Un-comment all lines in range
91 silent execute a:firstline . ',' . a:lastline . 's/^\*\*//'
92 else
93 " Comment all lines in range
94 silent execute a:firstline . ',' . a:lastline . 's/^/**/'
95 endif
96 endfunction
97
98 " Map \s to swap first two comma separated fields
99 noremap <silent><buffer> <LocalLeader>s :call <SID>Abaqus_Swap()<CR>
100 function! <SID>Abaqus_Swap() range
101 silent execute a:firstline . ',' . a:lastline . 's/\([^*,]*\),\([^,]*\)/\2,\1/'
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100102 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +0000103
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100104 let b:undo_ftplugin .= "|unmap <buffer> [[|unmap <buffer> ]]"
105 \ . "|unmap <buffer> <LocalLeader><LocalLeader>"
Bram Moolenaar3c053a12022-10-16 13:11:12 +0100106 \ . "|unmap <buffer> <LocalLeader>s"
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100107endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100108
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200109" Undo must be done in nocompatible mode for <LocalLeader>.
Bram Moolenaar921bde82022-05-09 19:50:35 +0100110let b:undo_ftplugin = "let b:cpo_save = &cpoptions|"
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200111 \ . "set cpoptions&vim|"
112 \ . b:undo_ftplugin
Bram Moolenaar921bde82022-05-09 19:50:35 +0100113 \ . "|let &cpoptions = b:cpo_save"
114 \ . "|unlet b:cpo_save"
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200115
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116" Restore saved compatibility options
117let &cpoptions = s:cpo_save
Bram Moolenaar84f72352012-03-11 15:57:40 +0100118unlet s:cpo_save