@@ -114,14 +114,14 @@ endfun
114114
115115" Get port/generic of a given entity or component
116116" a:kind is a kind of tag : e, c, g (generic in entity)
117- " Return [] if nothing is found
117+ " Return -1 if no tag is not found
118118fun ! VHDL_portgeneric_get (name, kind)
119119
120120 let type = a: kind == ' g' ? ' generic' : ' port'
121121 let kind = a: kind == ' g' ? ' e' : a: kind
122122
123123 let l = filter (taglist (' ^' .a: name ), ' v:val.kind==kind' )
124- if empty (l ) | return [] | endif
124+ if empty (l ) | return -1 | endif
125125 let t = l [0 ]
126126
127127 let view_bak = winsaveview ()
@@ -177,8 +177,13 @@ fun! VHDL_comp_ports_put()
177177
178178 let ports = VHDL_portgeneric_get (name, ' e' )
179179 call setpos (' .' , cursor_bak)
180+ if type (ports) != 3 :
181+ " echomsg "Entity tag '".name."' not found."
182+ return
183+ elseif empty (ports)
184+ return
185+ endif
180186
181- if empty (ports) | return | endif
182187 norm a (
183188 silent ! pu = ports
184189 exe ' .-' .(len (ports)-1 ).' ,.call VHDL_nice_align()'
@@ -202,7 +207,6 @@ fun! VHDL_map_put()
202207 endif
203208
204209 let name = matchstr (getline (' .' ), ' :\s*\zs\k\+' )
205-
206210 if name == ' '
207211 call setpos (' .' , cursor_bak)
208212 return
@@ -211,15 +215,14 @@ fun! VHDL_map_put()
211215 call setpos (' .' , cursor_bak)
212216
213217 " Remove the "map"
214- norm Xxx
218+ norm 2 " _X " _x
215219
216220 " Generic
217221 if do_generic
218222
219223 let lines = VHDL_portgeneric_get (name, ' g' )
220224 call setpos (' .' , cursor_bak)
221-
222- if ! empty (lines )
225+ if type (lines ) == 3 && ! empty (lines )
223226
224227 exe " norm ageneric ma\<Esc> ap ("
225228
@@ -233,7 +236,6 @@ fun! VHDL_map_put()
233236 let cursor_bak2 = getpos (' .' )
234237
235238 exe ' .-' .(len (lines )).' ,.call VHDL_nice_align()'
236-
237239 let end_move = 1
238240
239241 endif
@@ -251,15 +253,28 @@ fun! VHDL_map_put()
251253 exe " norm apor\<Esc> at "
252254 endif
253255
254- if empty (lines )
256+ if type (lines ) != 3
257+ " echomsg "Entity tag '".name."' not found."
258+ if exists (' end_move' )
259+ exe " norm ama\<Esc> ap ();"
260+ else
261+ exe " norm ama\<Esc> ap ("
262+ endif
263+
264+ elseif empty (lines )
255265 exe " norm ama\<Esc> ap ();"
266+ " Move cursor in brackets, if nothing has been added
267+ if ! exists (' end_move' )
268+ call cursor (' .' ,col (' .' )-2 )
269+ endif
270+
256271 else
257272 exe " norm ama\<Esc> ap ("
258273
259274 call map (lines , ' substitute(v:val, "\\(--.*\\)\\@<!:[^;]*","=> ", "g")' )
260275 call map (lines , ' substitute(v:val, "\\(--.*\\)\\@<!=> ;","=> ,", "g")' )
261276 if lines [-1 ] !~ ' --'
262- let lines [-1 ] = substitute (lines [-1 ], ' \(,\|);\)$' , ' )' , ' ' ) " XXX
277+ let lines [-1 ] = substitute (lines [-1 ], ' \(,\|);\)$' , ' ); ' , ' ' ) " XXX
263278 endif
264279 silent ! pu = lines
265280 exe ' .-' .(len (lines )).' ,.call VHDL_nice_align()'
@@ -279,13 +294,31 @@ fun! VHDL_map_put()
279294endfun
280295
281296
282-
283297" XXX
284298fun ! VHDL_init ()
285299
286300 setlocal ignorecase
287301 setlocal omnifunc = VHDL_omnicomp
288302
303+
304+ " Simple shortcuts
305+ " XXX use abbrev too ?
306+ imap <buffer> ,, <=
307+ imap <buffer> .. =>
308+ iabbrev <buffer> dt downto
309+ iabbrev <buffer> sig signal
310+ iabbrev <buffer> gen generate
311+ iabbrev <buffer> ot others
312+ iabbrev <buffer> sl std_logic
313+ iabbrev <buffer> slv std_logic_vector
314+ iabbrev <buffer> uns unsigned
315+ iabbrev <buffer> toi to_integer
316+ iabbrev <buffer> tos to_unsigned
317+ iabbrev <buffer> tou to_unsigned
318+ iabbrev <buffer> I: I : in
319+ iabbrev <buffer> O: O : out
320+
321+ " port/map auto-fill
289322 inoreabbrev <buffer> <silent> port port<C-o> :call VHDL_comp_ports_put ()<CR>
290323 inoreabbrev <buffer> <silent> map map<C-o> :call VHDL_map_put()<CR>
291324
@@ -295,56 +328,3 @@ endfun
295328" menu : word, abbr, menu, info, kind, icase, dup
296329" tags : name, filename, cmd, kind, static
297330
298- " """"""""""""""""""""""""""""""""""""""
299- " Load template from ~/.template/vhdl
300- " """"""""""""""""""""""""""""""""""""""
301- " name for the template, the function Template_Replace_Special()
302- " replace $template:filename$ by the filname (for exemple)
303- let s: template_var = {
304- \ ' template:filename' : ' expand("%:t")' ,
305- \ ' template:name' : ' expand("%:t:r")' ,
306- \}
307- " Because not all systems support strftime
308- if exists (" *strftime" )
309- let s: template_var [" template:date" ] = ' strftime("%d\/%m\/%Y")'
310- :endif
311-
312- " replacement function, use s:template_var
313- fun ! Template_Replace_Special ()
314- for [k ,v ] in items (s: template_var )
315- exe ' %s/\$' .k .' \$/\=' .v .' /g'
316- endfor
317- endfun
318-
319- if ! filereadable (expand (" %" ))
320- " Template loading
321- 0 r ~/.templates/vhdl
322- " Filling template replace $template:date$ and $template:filename$
323-
324- call Template_Replace_Special ()
325- endif
326-
327- " """""""""""""""""""""""""""""""""""""
328- " Some cool shortcuts
329- " """""""""""""""""""""""""""""""""""""
330-
331- " shortcuts
332- imap <buffer> ,, <=
333- imap <buffer> .. =>
334-
335- " abbreviations
336- iabbr dt downto
337- iabbr sig signal
338- iabbr gen generate
339- iabbr ot others
340- iabbr sl std_logic
341- iabbr slv std_logic_vector
342- iabbr uns unsigned
343- iabbr toi to_integer
344- iabbr tos to_unsigned
345- iabbr tou to_unsigned
346- imap <buffer> I: I : in
347- imap <buffer> O: O : out
348-
349- " Functions
350- map <F2> :call VHDL_nice_align()<CR>
0 commit comments