~gpanders/dotfiles

ref: 2da1dde5ea566f82ebe6532bc6d3b8670fd77ce8 dotfiles/vim/.vim/autoload/ft/vhdl.vim -rw-r--r-- 1.6 KiB
2da1dde5Greg Anders Note 'open' subcommand opens editor in NOTES_DIR when no argument given 1 year, 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
let s:mark_debug_def = 'attribute MARK_DEBUG : string;'
let s:mark_debug = 'attribute MARK_DEBUG of {} : signal is "true";'

function! ft#vhdl#toggle_debug()
  " Use a mark to preserve current cursor location, since it will
  " automatically update its line number as new lines are added
  let oldz = getpos("'z")
  mark z
  let l = getline('.')
  let view = winsaveview()
  let matches = matchlist(l, '\c^\s*signal\s\+\(\h\w*\)\s*:')
  if !empty(matches)
    " The current line is a signal definition
    let signal = matches[1]
  else
    let signal = expand('<cword>')

    " Jump to signal definition, if it exists
    if !search('\c^\s*signal\s\+' . signal . '\s*:')
      echohl ErrorMsg
      echo 'No signal ' . signal . ' found'
      echohl None
      return
    endif
  endif

  let text = substitute(s:mark_debug, '{}', signal, '')

  " If text already exists, delete it
  let textloc = search('^\s*' . text, 'n')
  if textloc
    execute textloc . 'd'
  else
    " Use :normal! o to take advantage of Vim's autoindenting
    execute 'normal! o' . text . "\<Esc>"
  endif

  " If MARK_DEBUG attribute is not defined, define it
  if !search(s:mark_debug_def, 'n')
    let archbegin = search('^\s*architecture\s\+')
    if archbegin
      execute "normal! o\<CR>" . s:mark_debug_def . "\<Esc>"
    endif
  endif

  " Reposition the cursor to the mark set at the beginning of the function
  let view.lnum = line("'z")
  call winrestview(view)

  " Restore the old value of the mark
  call setpos("'z", oldz)
endfunction

function! ft#vhdl#find_package(fname)
  let path = glob(expand('%:h:.') . '/*' . a:fname . '*', 0, 1)
  if !empty(path)
    return path[0]
  endif
endfunction