blob: c16e7b032e003ac5d6a1eaf18a2ae2dfb3e77b5b [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)
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
7" Only do this when not done yet for this buffer
8if exists("b:did_ftplugin") | finish | endif
9
10" Don't load another plugin for this buffer
11let b:did_ftplugin = 1
12
13" Save the compatibility options and temporarily switch to vim defaults
14let s:cpo_save = &cpoptions
15set cpoptions&vim
16
Bram Moolenaar071d4272004-06-13 20:20:40 +000017" Set the format of the include file specification for Abaqus
18" Used in :check gf ^wf [i and other commands
19setlocal include=\\<\\cINPUT\\s*=
20
21" Remove characters up to the first = when evaluating filenames
22setlocal includeexpr=substitute(v:fname,'.\\{-}=','','')
23
Bram Moolenaar8299df92004-07-10 09:47:34 +000024" Remove comma from valid filename characters since it is used to
25" separate keyword parameters
26setlocal isfname-=,
27
Bram Moolenaar071d4272004-06-13 20:20:40 +000028" Define format of comment lines (see 'formatoptions' for uses)
29setlocal comments=:**
30setlocal commentstring=**%s
31
32" Definitions start with a * and assign a NAME, NSET, or ELSET
33" Used in [d ^wd and other commands
34setlocal define=^\\*\\a.*\\c\\(NAME\\\|NSET\\\|ELSET\\)\\s*=
35
36" Abaqus keywords and identifiers may include a - character
37setlocal iskeyword+=-
38
Bram Moolenaar5c736222010-01-06 20:54:52 +010039let b:undo_ftplugin = "setlocal include< includeexpr< isfname<"
40 \ . " comments< commentstring< define< iskeyword<"
41
42if has("folding")
43 " Fold all lines that do not begin with *
44 setlocal foldexpr=getline(v:lnum)[0]!=\"\*\"
45 setlocal foldmethod=expr
46 let b:undo_ftplugin .= " foldexpr< foldmethod<"
47endif
48
Bram Moolenaar071d4272004-06-13 20:20:40 +000049" Set the file browse filter (currently only supported under Win32 gui)
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010050if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000051 let b:browsefilter = "Abaqus Input Files (*.inp *.inc)\t*.inp;*.inc\n" .
52 \ "Abaqus Results (*.dat)\t*.dat\n" .
Doug Kearns93197fd2024-01-14 20:59:02 +010053 \ "Abaqus Messages (*.pre, *.msg, *.sta)\t*.pre;*.msg;*.sta\n"
54 if has("win32")
55 let b:browsefilter .= "All Files (*.*)\t*\n"
56 else
57 let b:browsefilter .= "All Files (*)\t*\n"
58 endif
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020059 let b:undo_ftplugin .= "|unlet! b:browsefilter"
Bram Moolenaar071d4272004-06-13 20:20:40 +000060endif
61
Bram Moolenaar5c736222010-01-06 20:54:52 +010062" Define patterns for the matchit plugin
63if exists("loaded_matchit") && !exists("b:match_words")
64 let b:match_ignorecase = 1
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010065 let b:match_words =
Bram Moolenaar5c736222010-01-06 20:54:52 +010066 \ '\*part:\*end\s*part,' .
67 \ '\*assembly:\*end\s*assembly,' .
68 \ '\*instance:\*end\s*instance,' .
69 \ '\*step:\*end\s*step'
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020070 let b:undo_ftplugin .= "|unlet! b:match_ignorecase b:match_words"
Bram Moolenaar5c736222010-01-06 20:54:52 +010071endif
72
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010073if !exists("no_plugin_maps") && !exists("no_abaqus_maps")
Bram Moolenaar3c053a12022-10-16 13:11:12 +010074 " Map [[ and ]] keys to move [count] keywords backward or forward
75 nnoremap <silent><buffer> ]] :call <SID>Abaqus_NextKeyword(1)<CR>
76 nnoremap <silent><buffer> [[ :call <SID>Abaqus_NextKeyword(-1)<CR>
77 function! <SID>Abaqus_NextKeyword(direction)
78 .mark '
79 if a:direction < 0
80 let flags = 'b'
81 else
82 let flags = ''
83 endif
84 let l:count = abs(a:direction) * v:count1
85 while l:count > 0 && search("^\\*\\a", flags)
86 let l:count -= 1
87 endwhile
88 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +000089
Bram Moolenaar3c053a12022-10-16 13:11:12 +010090 " Map \\ to toggle commenting of the current line or range
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +010091 noremap <silent><buffer> <LocalLeader><LocalLeader>
92 \ :call <SID>Abaqus_ToggleComment()<CR>j
93 function! <SID>Abaqus_ToggleComment() range
Bram Moolenaar3c053a12022-10-16 13:11:12 +010094 if strpart(getline(a:firstline), 0, 2) == "**"
95 " Un-comment all lines in range
96 silent execute a:firstline . ',' . a:lastline . 's/^\*\*//'
97 else
98 " Comment all lines in range
99 silent execute a:firstline . ',' . a:lastline . 's/^/**/'
100 endif
101 endfunction
102
103 " Map \s to swap first two comma separated fields
104 noremap <silent><buffer> <LocalLeader>s :call <SID>Abaqus_Swap()<CR>
105 function! <SID>Abaqus_Swap() range
106 silent execute a:firstline . ',' . a:lastline . 's/\([^*,]*\),\([^,]*\)/\2,\1/'
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100107 endfunction
Bram Moolenaar071d4272004-06-13 20:20:40 +0000108
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100109 let b:undo_ftplugin .= "|unmap <buffer> [[|unmap <buffer> ]]"
110 \ . "|unmap <buffer> <LocalLeader><LocalLeader>"
Bram Moolenaar3c053a12022-10-16 13:11:12 +0100111 \ . "|unmap <buffer> <LocalLeader>s"
Bram Moolenaar48c3f4e2022-08-08 15:42:38 +0100112endif
Bram Moolenaar5c736222010-01-06 20:54:52 +0100113
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200114" Undo must be done in nocompatible mode for <LocalLeader>.
Bram Moolenaar921bde82022-05-09 19:50:35 +0100115let b:undo_ftplugin = "let b:cpo_save = &cpoptions|"
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200116 \ . "set cpoptions&vim|"
117 \ . b:undo_ftplugin
Bram Moolenaar921bde82022-05-09 19:50:35 +0100118 \ . "|let &cpoptions = b:cpo_save"
119 \ . "|unlet b:cpo_save"
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200120
Bram Moolenaar071d4272004-06-13 20:20:40 +0000121" Restore saved compatibility options
122let &cpoptions = s:cpo_save
Bram Moolenaar84f72352012-03-11 15:57:40 +0100123unlet s:cpo_save