forked from lanxuezaipiao/vim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot.vim
executable file
·491 lines (446 loc) · 14.4 KB
/
dot.vim
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
" wmgraphviz.vim plugin
" Author: Wannes Meert
" Email: [email protected]
" Version: 1.0.3
if exists('s:loaded')
finish
endif
let s:loaded = 1
" Settings
if !exists('g:WMGraphviz_dot')
let g:WMGraphviz_dot = 'dot'
endif
if !exists('g:WMGraphviz_output')
let g:WMGraphviz_output = 'pdf'
endif
if !exists('g:WMGraphviz_viewer')
if has('mac')
let g:WMGraphviz_viewer = 'open'
elseif has ('unix')
if executable('xdg-open')
let g:WMGraphviz_viewer = 'xdg-open'
else
if g:WMGraphviz_output == 'ps'
let g:WMGraphviz_viewer = 'gv'
else
let g:WMGraphviz_viewer = 'acroread'
endif
endif
else
let g:WMGraphviz_viewer = 'open'
endif
endif
if !exists('g:WMGraphviz_shelloptions')
let g:WMGraphviz_shelloptions = ''
endif
if !exists('g:WMGraphviz_dot2tex')
let g:WMGraphviz_dot2tex = 'dot2tex'
endif
if !exists('g:WMGraphviz_dot2texoptions')
let g:WMGraphviz_dot2texoptions = '-tmath'
endif
" Compilation
" If argument given, use it as output
fu! GraphvizCompile(...)
if !executable(g:WMGraphviz_dot)
echoerr 'The "'.g:WMGraphviz_dot.'" executable was not found.'
return
endif
let s:output = a:0 >= 1 ? a:1 : g:WMGraphviz_output
let s:logfile = expand('%:p:r').'.log'
" DOT command uses -O option instead of -o because this doesn't work if
" there are multiple graphs in the file.
let cmd = '!('.g:WMGraphviz_dot.' -O -T'.s:output.' '.g:WMGraphviz_shelloptions.' '.shellescape(expand('%:p')).' 2>&1) | tee '.shellescape(expand('%:p:r').'.log')
exec cmd
exec 'cfile '.escape(s:logfile, ' \"!?''')
endfu
fu! GraphvizCompileToLaTeX(...)
if !executable(g:WMGraphviz_dot2tex)
echoerr 'The "'.g:WMGraphviz_dot2tex.'" executable was not found.'
return
endif
let s:logfile = expand('%:p:r').'.log'
" DOT command uses -O option instead of -o because this doesn't work if
" there are multiple graphs in the file.
let cmd = '!(('.g:WMGraphviz_dot2tex.' '.g:WMGraphviz_dot2texoptions.' '.shellescape(expand('%:p')).' > '.shellescape(expand('%:p:r').'.tex').') 2>&1) | tee '.shellescape(expand('%:p:r').'.log')
exec cmd
exec 'cfile '.escape(s:logfile, ' \"!?''')
endfu
" Viewing
fu! GraphvizShow()
if !filereadable(expand('%:p').'.'.g:WMGraphviz_output)
call GraphvizCompile()
endif
if !executable(g:WMGraphviz_viewer)
echoerr 'Viewer program not found: "'.g:WMGraphviz_viewer.'"'
return
endif
exec '!'.g:WMGraphviz_viewer.' '.shellescape(expand('%:p').'.'.g:WMGraphviz_output)
endfu
" Available functions
com! -nargs=0 GraphvizCompile :call GraphvizCompile()
com! -nargs=0 GraphvizCompilePS :call GraphvizCompile('ps')
com! -nargs=0 GraphvizCompilePDF :call GraphvizCompile('pdf')
com! -nargs=0 GraphvizCompileToLaTeX :call GraphvizCompileToLaTeX()
com! -nargs=0 GraphvizShow : call GraphvizShow()
" Mappings
nmap <silent> <buffer> <LocalLeader>ll :GraphvizCompile<CR>
nmap <silent> <buffer> <LocalLeader>lt :GraphvizCompileToLaTeX<CR>
nmap <silent> <buffer> <LocalLeader>lv :GraphvizShow<CR>
" Completion
let s:completion_type = ''
" Completion dictionaries
let s:attrs = [
\ {'word': 'arrowhead=', 'menu': 'Style of arrowhead at head end [E]'},
\ {'word': 'arrowsize=', 'menu': 'Scaling factor for arrowheads [E]'},
\ {'word': 'arrowtail=', 'menu': 'Style of arrowhead at tail end [E]'},
\ {'word': 'bgcolor=', 'menu': 'Background color [G]'},
\ {'word': 'color=', 'menu': 'Node shape/edge/cluster color [E,G,N]'},
\ {'word': 'comment=', 'menu': 'Any string [E,G,N]'},
\ {'word': 'compound=', 'menu': 'Allow edges between clusters [G]'},
\ {'word': 'concentrate=', 'menu': 'Enables edge concentrators [G]'},
\ {'word': 'constraints=', 'menu': 'Use edge to affect node ranking [E]'},
\ {'word': 'decorate=', 'menu': 'If set, line between label and edge [E]'},
\ {'word': 'dir=', 'menu': 'Direction of edge [E]'},
\ {'word': 'distortion=', 'menu': 'Node distortion [N]'},
\ {'word': 'fillcolor=', 'menu': 'Node/cluster fill color [G,N]'},
\ {'word': 'fixedsize=', 'menu': 'Label text has no effect on node size [N]'},
\ {'word': 'fontcolor=', 'menu': 'Font face color [E,G,N]'},
\ {'word': 'fontname=', 'menu': 'Font family [E,G,N]'},
\ {'word': 'fontsize=', 'menu': 'Point size of label [E,G,N]'},
\ {'word': 'group=', 'menu': 'Name of node group [N]'},
\ {'word': 'headlabel=', 'menu': 'Label placed near head of edge [E]'},
\ {'word': 'headport=', 'menu': 'Location of label [E]'},
\ {'word': 'height=', 'menu': 'Height in inches [N]'},
\ {'word': 'label=', 'menu': 'Any string [E,N]'},
\ {'word': 'labelangle=', 'menu': 'Ange in degrees [E]'},
\ {'word': 'labeldistance=', 'menu': 'Scaling factor for distance for head or tail label [E]'},
\ {'word': 'labelfontcolor=','menu': 'Type face color for head and tail labels [E]'},
\ {'word': 'labelfontname=', 'menu': 'Font family for head and tail labels [E]'},
\ {'word': 'labelfontsize=', 'menu': 'Point size for head and tail labels [E]'},
\ {'word': 'labeljust=', 'menu': 'Label justficiation [G]'},
\ {'word': 'labelloc=', 'menu': 'Label vertical justficiation [G]'},
\ {'word': 'layer=', 'menu': 'Overlay range [E,N]'},
\ {'word': 'lhead=', 'menu': '[E]'},
\ {'word': 'ltail=', 'menu': '[E]'},
\ {'word': 'minlen=', 'menu': '[E]'},
\ {'word': 'nodesep=', 'menu': 'Separation between nodes, in inches [G]'},
\ {'word': 'orientation=', 'menu': 'Node rotation angle [N]'},
\ {'word': 'peripheries=', 'menu': 'Number of node boundaries [N]'},
\ {'word': 'rank=', 'menu': '[G]'},
\ {'word': 'rankdir=', 'menu': '[G]'},
\ {'word': 'ranksep=', 'menu': 'Separation between ranks, in inches [G]'},
\ {'word': 'ratio=', 'menu': 'Aspect ratio [G]'},
\ {'word': 'regular=', 'menu': 'Force polygon to be regular [N]'},
\ {'word': 'rotate=', 'menu': 'If 90, set orientation to landscape [G]'},
\ {'word': 'samehead=', 'menu': '[E]'},
\ {'word': 'sametail=', 'menu': '[E]'},
\ {'word': 'shape=', 'menu': 'Node shape [N]'},
\ {'word': 'shapefile=', 'menu': 'External custom shape file [N]'},
\ {'word': 'sides=', 'menu': 'Number of sides for shape=polygon [N]'},
\ {'word': 'skew=', 'menu': 'Skewing node for for shape=polygon [N]'},
\ {'word': 'style=', 'menu': 'Graphics options [E,N]'},
\ {'word': 'taillabel=', 'menu': 'Label placed near tail of edge [E]'},
\ {'word': 'tailport=', 'menu': '[E]'},
\ {'word': 'weight=', 'menu': 'Integer cost of stretching an edge [E]'},
\ {'word': 'width=', 'menu': 'width in inches [N]'}
\ ]
let s:shapes = [
\ {'word': 'box'},
\ {'word': 'circle'},
\ {'word': 'diamond'},
\ {'word': 'doublecircle'},
\ {'word': 'doubleoctagon'},
\ {'word': 'egg'},
\ {'word': 'ellipse'},
\ {'word': 'hexagon'},
\ {'word': 'house'},
\ {'word': 'invhouse'},
\ {'word': 'invtrapezium'},
\ {'word': 'invtriangle'},
\ {'word': 'octagon'},
\ {'word': 'plaintext'},
\ {'word': 'parallelogram'},
\ {'word': 'point'},
\ {'word': 'polygon'},
\ {'word': 'record'},
\ {'word': 'traingle'},
\ {'word': 'trapezium'},
\ {'word': 'tripleoctagon'},
\ {'word': 'Mcircle'},
\ {'word': 'Mdiamon'},
\ {'word': 'Mrecord'},
\ {'word': 'Msquare'}
\ ]
let s:arrowheads = [
\ {'word': 'normal'},
\ {'word': 'dot'},
\ {'word': 'odot'},
\ {'word': 'inv'},
\ {'word': 'invdot'},
\ {'word': 'invodot'},
\ {'word': 'none'}
\ ]
" More colornames are available but make the menu too long.
let s:colors = [
\ {'word': '#000000'},
\ {'word': '0.0 0.0 0.0'},
\ {'word': 'beige'},
\ {'word': 'black'},
\ {'word': 'blue'},
\ {'word': 'brown'},
\ {'word': 'cyan'},
\ {'word': 'gray'},
\ {'word': 'gray[0-100]'},
\ {'word': 'green'},
\ {'word': 'magenta'},
\ {'word': 'orange'},
\ {'word': 'orchid'},
\ {'word': 'red'},
\ {'word': 'violet'},
\ {'word': 'white'},
\ {'word': 'yellow'}
\ ]
let s:fonts = [
\ {'abbr': 'Courier' , 'word': '"Courier"'},
\ {'abbr': 'Courier-Bold' , 'word': '"Courier-Bold"'},
\ {'abbr': 'Courier-Oblique' , 'word': '"Courier-Oblique"'},
\ {'abbr': 'Helvetica' , 'word': '"Helvetica"'},
\ {'abbr': 'Helvetica-Bold' , 'word': '"Helvetica-Bold"'},
\ {'abbr': 'Helvetica-Narrow' , 'word': '"Helvetica-Narrow"'},
\ {'abbr': 'Helvetica-Oblique', 'word': '"Helvetica-Oblique"'},
\ {'abbr': 'Symbol' , 'word': '"Symbol"'},
\ {'abbr': 'Times-Bold' , 'word': '"Times-Bold"'},
\ {'abbr': 'Times-BoldItalic' , 'word': '"Times-BoldItalic"'},
\ {'abbr': 'Times-Italic' , 'word': '"Times-Italic"'},
\ {'abbr': 'Times-Roman' , 'word': '"Times-Roman"'}
\ ]
let s:style = [
\ {'word': 'bold'},
\ {'word': 'dotted'},
\ {'word': 'filled'}
\ ]
let s:dir = [
\ {'word': 'forward'},
\ {'word': 'back'},
\ {'word': 'both'},
\ {'word': 'none'}
\ ]
let s:port = [
\ {'word': '_', 'menu': 'appropriate side or center (default)' },
\ {'word': 'c', 'menu': 'center'},
\ {'word': 'e'},
\ {'word': 'n'},
\ {'word': 'ne'},
\ {'word': 'nw'},
\ {'word': 's'},
\ {'word': 'se'},
\ {'word': 'sw'},
\ {'word': 'w'},
\ ]
let s:rank = [
\ {'word': 'same'},
\ {'word': 'min'},
\ {'word': 'max'},
\ {'word': 'source'},
\ {'word': 'sink'}
\ ]
let s:rankdir = [
\ {'word': 'BT'},
\ {'word': 'LR'},
\ {'word': 'RL'},
\ {'word': 'TB'},
\ ]
let s:just = [
\ {'word': 'centered'},
\ {'word': 'l'},
\ {'word': 'r'}
\ ]
let s:loc = [
\ {'word': 'b', 'menu': 'bottom'},
\ {'word': 'c', 'menu': 'center'},
\ {'word': 't', 'menu': 'top'},
\ ]
let s:boolean = [
\ {'word': 'true'},
\ {'word': 'false'}
\ ]
fu! GraphvizComplete(findstart, base)
"echomsg 'findstart='.a:findstart.', base='.a:base
if a:findstart
" return the starting point of the word
let line = getline('.')
let pos = col('.') - 1
while pos > 0 && line[pos - 1] !~ '=\|,\|\[\|\s'
let pos -= 1
endwhile
let withspacepos = pos
if line[withspacepos - 1] =~ '\s'
while withspacepos > 0 && line[withspacepos - 1] !~ '=\|,\|\['
let withspacepos -= 1
endwhile
endif
if line[withspacepos - 1] == '='
" label=...?
let labelpos = withspacepos - 1
" ignore spaces
while labelpos > 0 && line[labelpos - 1] =~ '\s'
let labelpos -= 1
let withspacepos -= 1
endwhile
while labelpos > 0 && line[labelpos - 1] =~ '[a-z]'
let labelpos -= 1
endwhile
let labelstr=strpart(line, labelpos, withspacepos - 1 - labelpos)
if labelstr == 'shape'
let s:completion_type = 'shape'
elseif labelstr =~ 'fontname'
let s:completion_type = 'font'
elseif labelstr =~ 'color'
let s:completion_type = 'color'
elseif labelstr == 'arrowhead'
let s:completion_type = 'arrowhead'
elseif labelstr == 'rank'
let s:completion_type = 'rank'
elseif labelstr == 'port'
let s:completion_type = 'port'
elseif labelstr == 'rankdir'
let s:completion_type = 'rankdir'
elseif labelstr == 'style'
let s:completion_type = 'style'
elseif labelstr == 'labeljust'
let s:completion_type = 'just'
elseif labelstr == 'fixedsize' || labelstr == 'regular' || labelstr == 'constraint' || labelstr == 'labelfloat' || labelstr == 'center' || labelstr == 'compound' || labelstr == 'concentrate'
let s:completion_type = 'boolean'
elseif labelstr == 'labelloc'
let s:completion_type = 'loc'
else
let s:completion_type = ''
endif
elseif line[withspacepos - 1] =~ ',\|\['
" attr
let attrstr=line[0:withspacepos - 1]
" skip spaces
while line[withspacepos] =~ '\s'
let withspacepos += 1
endwhile
if attrstr =~ '^\s*node'
let s:completion_type = 'attrnode'
elseif attrstr =~ '^\s*edge'
let s:completion_type = 'attredge'
elseif attrstr =~ '\( -> \)\|\( -- \)'
let s:completion_type = 'attredge'
elseif attrstr =~ '^\s*graph'
let s:completion_type = 'attrgraph'
else
let s:completion_type = 'attrnode'
endif
else
let s:completion_type = ''
endif
return pos
else
" return suggestions in an array
let suggestions = []
if s:completion_type == 'shape'
for entry in s:shapes
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'arrowhead'
for entry in s:arrowheads
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'boolean'
for entry in s:boolean
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'font'
for entry in s:fonts
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'color'
for entry in s:colors
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'rank'
for entry in s:rank
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'rankdir'
for entry in s:rankdir
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'style'
for entry in s:style
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'port'
for entry in s:port
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'just'
for entry in s:just
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'loc'
for entry in s:loc
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'attr'
for entry in s:attrs
if entry.word =~ '^'.escape(a:base, '/')
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'attrnode'
for entry in s:attrs
if entry.word =~ '^'.escape(a:base, '/') && entry.menu =~ '\[.*N.*\]'
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'attredge'
for entry in s:attrs
if entry.word =~ '^'.escape(a:base, '/') && entry.menu =~ '\[.*E.*\]'
call add(suggestions, entry)
endif
endfor
elseif s:completion_type == 'attrgraph'
for entry in s:attrs
if entry.word =~ '^'.escape(a:base, '/') && entry.menu =~ '\[.*G.*\]'
call add(suggestions, entry)
endif
endfor
endif
if !has('gui_running')
redraw!
endif
return suggestions
endif
endfu
setlocal omnifunc=GraphvizComplete
" Quickfix list
setlocal errorformat=%EError:\ %f:%l:%m,%+Ccontext:\ %.%#,%WWarning:\ %m
" Comments
set commentstring="// %s"