forked from WolfgangMehner/vim-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperl-support.vim
More file actions
2852 lines (2779 loc) · 118 KB
/
perl-support.vim
File metadata and controls
2852 lines (2779 loc) · 118 KB
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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"#################################################################################
"
" Filename: perl-support.vim
"
" Description: perl-support.vim implements a Perl-IDE for Vim/gVim. It is
" written to considerably speed up writing code in a consistent
" style.
" This is done by inserting complete statements, comments,
" idioms, code snippets, templates, comments and POD
" documentation. Reading perldoc is integrated. Syntax
" checking, running a script, starting a debugger and a
" profiler can be done by a keystroke.
" There a many additional hints and options which can improve
" speed and comfort when writing Perl. Please read the
" documentation.
"
" Configuration: There are at least some personal details which should be
" configured (see the files README.perlsupport and
" perlsupport.txt).
"
" Dependencies: perl pod2man
" podchecker pod2text
" pod2html perldoc
"
" optional:
"
" Devel::FastProf (profiler)
" Devel::NYTProf (profiler)
" Devel::SmallProf (profiler)
" Devel::ptkdb (debugger frontend)
" Perl::Critic (stylechecker)
" Perl::Tags::Naive (generate Ctags style tags)
" Perl::Tidy (beautifier)
" YAPE::Regex::Explain (regular expression analyzer)
" ddd (debugger frontend)
" sort(1) (rearrange profiler statistics)
"
" Author: Dr.-Ing. Fritz Mehner <[email protected]>
"
" Version: see variable g:Perl_PluginVersion below
" Created: 09.07.2001
" License: Copyright (c) 2001-2014, Fritz Mehner
" This program is free software; you can redistribute it
" and/or modify it under the terms of the GNU General Public
" License as published by the Free Software Foundation,
" version 2 of the License.
" This program is distributed in the hope that it will be
" useful, but WITHOUT ANY WARRANTY; without even the implied
" warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
" PURPOSE.
" See the GNU General Public License version 2 for more details.
" Credits: see perlsupport.txt
"-------------------------------------------------------------------------------
"
" Prevent duplicate loading:
"
if exists("g:Perl_PluginVersion") || &compatible
finish
endif
let g:Perl_PluginVersion= "5.4pre"
"
"=== FUNCTION ================================================================
" NAME: Perl_SetGlobalVariable {{{1
" DESCRIPTION: Define a global variable and assign a default value if nor
" already defined
" PARAMETERS: name - global variable
" default - default value
"===============================================================================
function! s:perl_SetGlobalVariable ( name, default )
if !exists('g:'.a:name)
exe 'let g:'.a:name." = '".a:default."'"
else
" check for an empty initialization
exe 'let val = g:'.a:name
if empty(val)
exe 'let g:'.a:name." = '".a:default."'"
endif
endif
endfunction " ---------- end of function s:perl_SetGlobalVariable ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_SetLocalVariable {{{1
" DESCRIPTION: Assign a value to a local variable if a corresponding global
" variable exists
" PARAMETERS: name - name of a global variable
"===============================================================================
function! s:perl_SetLocalVariable ( name )
if exists('g:'.a:name)
exe 'let s:'.a:name.' = g:'.a:name
endif
endfunction " ---------- end of function s:perl_SetLocalVariable ----------
"
"------------------------------------------------------------------------------
"
" Platform specific items: {{{1
" - plugin directory
" - characters that must be escaped for filenames
"
let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95")
let s:UNIX = has("unix") || has("macunix") || has("win32unix")
"
let s:Perl_Perl = '' " the Perl interpreter used
let s:Perl_Perl_is_executable = 0 " the Perl interpreter used
let g:Perl_Installation = '*undefined*'
let g:Perl_PluginDir = ''
"
let s:Perl_GlobalTemplateFile = ''
let s:Perl_LocalTemplateFile = ''
let s:Perl_CustomTemplateFile = '' " the custom templates
let g:Perl_FilenameEscChar = ''
"
let s:Perl_ToolboxDir = []
"
if s:MSWIN
" ========== MS Windows ======================================================
"
let g:Perl_PluginDir = substitute( expand('<sfile>:p:h:h'), '\', '/', 'g' )
"
" change '\' to '/' to avoid interpretation as escape character
if match( substitute( expand("<sfile>"), '\', '/', 'g' ),
\ substitute( expand("$HOME"), '\', '/', 'g' ) ) == 0
" USER INSTALLATION ASSUMED
let g:Perl_Installation = 'local'
let s:Perl_LocalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates'
let s:Perl_CustomTemplateFile = $HOME.'/vimfiles/templates/perl.templates'
let s:Perl_ToolboxDir += [ g:Perl_PluginDir.'/autoload/mmtoolbox/' ]
else
" SYSTEM WIDE INSTALLATION
let g:Perl_Installation = 'system'
let s:Perl_GlobalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates'
let s:Perl_LocalTemplateFile = $HOME.'/vimfiles/perl-support/templates/Templates'
let s:Perl_CustomTemplateFile = $HOME.'/vimfiles/templates/perl.templates'
let s:Perl_ToolboxDir += [
\ g:Perl_PluginDir.'/autoload/mmtoolbox/',
\ $HOME.'/vimfiles/autoload/mmtoolbox/' ]
end
"
let s:Perl_Perl = 'C:/Perl/bin/perl.exe'
let g:Perl_FilenameEscChar = ''
"
else
" ========== Linux/Unix ======================================================
"
let g:Perl_PluginDir = expand("<sfile>:p:h:h")
"
if match( expand("<sfile>"), resolve( expand("$HOME") ) ) == 0
" USER INSTALLATION ASSUMED
let g:Perl_Installation = 'local'
let s:Perl_LocalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates'
let s:Perl_CustomTemplateFile = $HOME.'/.vim/templates/perl.templates'
let s:Perl_ToolboxDir += [ g:Perl_PluginDir.'/autoload/mmtoolbox/' ]
else
" SYSTEM WIDE INSTALLATION
let g:Perl_Installation = 'system'
let s:Perl_GlobalTemplateFile = g:Perl_PluginDir.'/perl-support/templates/Templates'
let s:Perl_LocalTemplateFile = $HOME.'/.vim/perl-support/templates/Templates'
let s:Perl_CustomTemplateFile = $HOME.'/.vim/templates/perl.templates'
let s:Perl_ToolboxDir += [
\ g:Perl_PluginDir.'/autoload/mmtoolbox/',
\ $HOME.'/.vim/autoload/mmtoolbox/' ]
endif
"
let s:Perl_Perl = '/usr/bin/perl'
let g:Perl_FilenameEscChar = ' \%#[]'
"
" ==============================================================================
endif
"
" g:Perl_CodeSnippets is used in autoload/perlsupportgui.vim
"
let s:Perl_CodeSnippets = g:Perl_PluginDir.'/perl-support/codesnippets/'
call s:perl_SetGlobalVariable( 'Perl_CodeSnippets', s:Perl_CodeSnippets )
"
"
call s:perl_SetGlobalVariable( 'Perl_PerlTags', 'off' )
"
if !exists("g:Perl_Dictionary_File")
let g:Perl_Dictionary_File = g:Perl_PluginDir.'/perl-support/wordlists/perl.list'
endif
"
"
" Modul global variables (with default values) which can be overridden. {{{1
"
let s:Perl_LoadMenus = 'yes' " display the menus ?
let s:Perl_TemplateOverriddenMsg = 'no'
let s:Perl_Ctrl_j = 'on'
"
let s:Perl_TimestampFormat = '%Y%m%d.%H%M%S'
let s:Perl_PerlModuleList = g:Perl_PluginDir.'/perl-support/modules/perl-modules.list'
let s:Perl_XtermDefaults = "-fa courier -fs 12 -geometry 80x24"
let s:Perl_Debugger = "perl"
let s:Perl_ProfilerTimestamp = "no"
let s:Perl_LineEndCommColDefault = 49
let s:PerlStartComment = '#'
let s:Perl_PodcheckerWarnings = "yes"
let s:Perl_PerlcriticOptions = ""
let s:Perl_PerlcriticSeverity = 3
let s:Perl_PerlcriticVerbosity = 5
let s:Perl_Printheader = "%<%f%h%m%< %=%{strftime('%x %X')} Page %N"
let s:Perl_GuiSnippetBrowser = 'gui' " gui / commandline
let s:Perl_CreateMenusDelayed = 'yes'
let s:Perl_DirectRun = 'no'
"
let s:Perl_InsertFileHeader = 'yes'
let s:Perl_Wrapper = g:Perl_PluginDir.'/perl-support/scripts/wrapper.sh'
let s:Perl_PerlModuleListGenerator = g:Perl_PluginDir.'/perl-support/scripts/pmdesc3.pl'
let s:Perl_PerltidyBackup = "no"
"
call s:perl_SetGlobalVariable ( 'Perl_MapLeader', '' )
let s:Perl_RootMenu = '&Perl'
"
let s:Perl_AdditionalTemplates = []
let s:Perl_UseToolbox = 'yes'
call s:perl_SetGlobalVariable ( 'Perl_UseTool_make', 'yes' )
"
"------------------------------------------------------------------------------
"
" Look for global variables (if any), to override the defaults.
"
call s:perl_SetLocalVariable('Perl_Perl ')
call s:perl_SetLocalVariable('Perl_DirectRun ')
call s:perl_SetLocalVariable('Perl_InsertFileHeader ')
call s:perl_SetLocalVariable('Perl_CreateMenusDelayed ')
call s:perl_SetLocalVariable('Perl_Ctrl_j ')
call s:perl_SetLocalVariable('Perl_Debugger ')
call s:perl_SetLocalVariable('Perl_GlobalTemplateFile ')
call s:perl_SetLocalVariable('Perl_LocalTemplateFile ')
call s:perl_SetLocalVariable('Perl_CustomTemplateFile ')
call s:perl_SetLocalVariable('Perl_AdditionalTemplates ')
call s:perl_SetLocalVariable('Perl_GuiSnippetBrowser ')
call s:perl_SetLocalVariable('Perl_LineEndCommColDefault ')
call s:perl_SetLocalVariable('Perl_LoadMenus ')
call s:perl_SetLocalVariable('Perl_NYTProf_browser ')
call s:perl_SetLocalVariable('Perl_NYTProf_html ')
call s:perl_SetLocalVariable('Perl_PerlcriticOptions ')
call s:perl_SetLocalVariable('Perl_PerlcriticSeverity ')
call s:perl_SetLocalVariable('Perl_PerlcriticVerbosity ')
call s:perl_SetLocalVariable('Perl_PerlModuleList ')
call s:perl_SetLocalVariable('Perl_PerlModuleListGenerator')
call s:perl_SetLocalVariable('Perl_PerltidyBackup ')
call s:perl_SetLocalVariable('Perl_PodcheckerWarnings ')
call s:perl_SetLocalVariable('Perl_Printheader ')
call s:perl_SetLocalVariable('Perl_ProfilerTimestamp ')
call s:perl_SetLocalVariable('Perl_TemplateOverriddenMsg ')
call s:perl_SetLocalVariable('Perl_TimestampFormat ')
call s:perl_SetLocalVariable('Perl_UseToolbox ')
call s:perl_SetLocalVariable('Perl_XtermDefaults ')
"
" Initialize global variables, if they do not already exist.
"
call s:perl_SetGlobalVariable( "Perl_MenuHeader",'yes' )
call s:perl_SetGlobalVariable( "Perl_OutputGvim",'vim' )
call s:perl_SetGlobalVariable( "Perl_PerlRegexSubstitution",'$~' )
"
let s:Perl_Perl_is_executable = executable(s:Perl_Perl)
"
" set default geometry if not specified
"
if match( s:Perl_XtermDefaults, "-geometry\\s\\+\\d\\+x\\d\\+" ) < 0
let s:Perl_XtermDefaults = s:Perl_XtermDefaults." -geometry 80x24"
endif
"
" Flags for perldoc
"
if has("gui_running")
let s:Perl_perldoc_flags = ""
else
" Display docs using plain text converter.
let s:Perl_perldoc_flags = "-otext"
endif
"
" escape the printheader
"
let s:Perl_Printheader = escape( s:Perl_Printheader, ' %' )
let s:Perl_PerlExecutableVersion = ''
"
"------------------------------------------------------------------------------
" Control variables (not user configurable)
"------------------------------------------------------------------------------
"
let s:Perl_MenuVisible = 'no'
let s:Perl_TemplateJumpTarget = ''
let s:MsgInsNotAvail = "insertion not available for a fold"
let g:Perl_PerlRegexAnalyser = 'no'
let g:Perl_InterfaceInitialized = 'no'
let s:Perl_saved_global_option = {}
"
let s:PCseverityName = [ "DUMMY", "brutal", "cruel", "harsh", "stern", "gentle" ]
let s:PCverbosityName = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11' ]
"
"=== FUNCTION ================================================================
" NAME: Perl_Input {{{1
" DESCRIPTION: Input after a highlighted prompt
" PARAMETERS: prompt - prompt
" text - default reply
" ... - completion (optional)
" RETURNS:
"===============================================================================
function! Perl_Input ( prompt, text, ... )
echohl Search " highlight prompt
call inputsave() " preserve typeahead
if a:0 == 0 || empty(a:1)
let retval =input( a:prompt, a:text )
else
let retval =input( a:prompt, a:text, a:1 )
endif
call inputrestore() " restore typeahead
echohl None " reset highlighting
let retval = substitute( retval, '^\s\+', "", "" ) " remove leading whitespaces
let retval = substitute( retval, '\s\+$', "", "" ) " remove trailing whitespaces
return retval
endfunction " ---------- end of function Perl_Input ----------
"
"------------------------------------------------------------------------------
" Perl_SaveGlobalOption {{{1
" param 1 : option name
" param 2 : characters to be escaped (optional)
"------------------------------------------------------------------------------
function! s:Perl_SaveGlobalOption ( option, ... )
exe 'let escaped =&'.a:option
if a:0 == 0
let escaped = escape( escaped, ' |"\' )
else
let escaped = escape( escaped, ' |"\'.a:1 )
endif
let s:Perl_saved_global_option[a:option] = escaped
endfunction " ---------- end of function Perl_SaveGlobalOption ----------
"
"------------------------------------------------------------------------------
" Perl_RestoreGlobalOption {{{1
"------------------------------------------------------------------------------
function! s:Perl_RestoreGlobalOption ( option )
exe ':set '.a:option.'='.s:Perl_saved_global_option[a:option]
endfunction " ---------- end of function Perl_RestoreGlobalOption ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_GetLineEndCommCol {{{1
" DESCRIPTION: get end-of-line comment position
"===============================================================================
function! Perl_GetLineEndCommCol ()
let actcol = virtcol(".")
if actcol+1 == virtcol("$")
let b:Perl_LineEndCommentColumn = ''
while match( b:Perl_LineEndCommentColumn, '^\s*\d\+\s*$' ) < 0
let b:Perl_LineEndCommentColumn = Perl_Input( 'start line-end comment at virtual column : ', actcol, '' )
endwhile
else
let b:Perl_LineEndCommentColumn = virtcol(".")
endif
echomsg "line end comments will start at column ".b:Perl_LineEndCommentColumn
endfunction " ---------- end of function Perl_GetLineEndCommCol ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_EndOfLineComment {{{1
" DESCRIPTION: apply single end-of-line comment
"===============================================================================
function! Perl_EndOfLineComment ( ) range
if !exists("b:Perl_LineEndCommentColumn")
let b:Perl_LineEndCommentColumn = s:Perl_LineEndCommColDefault
endif
" ----- trim whitespaces -----
exe a:firstline.','.a:lastline.'s/\s*$//'
for line in range( a:lastline, a:firstline, -1 )
silent exe ":".line
if getline(line) !~ '^\s*$'
let linelength = virtcol( [line, "$"] ) - 1
let diff = 1
if linelength < b:Perl_LineEndCommentColumn
let diff = b:Perl_LineEndCommentColumn -1 -linelength
endif
exe "normal! ".diff."A "
call mmtemplates#core#InsertTemplate(g:Perl_Templates, 'Comments.end-of-line-comment')
endif
endfor
endfunction " ---------- end of function Perl_EndOfLineComment ----------
"
"------------------------------------------------------------------------------
" Perl_AlignLineEndComm: adjust line-end comments
"------------------------------------------------------------------------------
"
" patterns to ignore when adjusting line-end comments (incomplete):
" some heuristics used (only Perl can parse Perl)
let s:AlignRegex = [
\ '\$#' ,
\ "'\\%(\\\\'\\|[^']\\)*'" ,
\ '"\%(\\.\|[^"]\)*"' ,
\ '`[^`]\+`' ,
\ '\%(m\|qr\)#[^#]\+#' ,
\ '\%(m\|qr\)\?\([\?\/]\).*\1[imsxg]*' ,
\ '\%(m\|qr\)\([[:punct:]]\).*\2[imsxg]*' ,
\ '\%(m\|qr\){.*}[imsxg]*' ,
\ '\%(m\|qr\)(.*)[imsxg]*' ,
\ '\%(m\|qr\)\[.*\][imsxg]*' ,
\ '\%(s\|tr\)#[^#]\+#[^#]\+#' ,
\ '\%(s\|tr\){[^}]\+}{[^}]\+}' ,
\ ]
"=== FUNCTION ================================================================
" NAME: Perl_AlignLineEndComm {{{1
" DESCRIPTION: align end-of-line comments
"===============================================================================
function! Perl_AlignLineEndComm ( ) range
"
" comment character (for use in regular expression)
let cc = '#' " start of a Perl comment
"
" patterns to ignore when adjusting line-end comments (maybe incomplete):
let align_regex = join( s:AlignRegex, '\|' )
"
" local position
if !exists( 'b:Perl_LineEndCommentColumn' )
let b:Perl_LineEndCommentColumn = s:Perl_LineEndCommColDefault
endif
let correct_idx = b:Perl_LineEndCommentColumn
"
" === plug-in specific code ends here ===
" === the behavior is governed by the variables above ===
"
" save the cursor position
let save_cursor = getpos('.')
"
for line in range( a:firstline, a:lastline )
silent exe ':'.line
"
let linetxt = getline('.')
"
" "pure" comment line left unchanged
if match ( linetxt, '^\s*'.cc ) == 0
"echo 'line '.line.': "pure" comment'
continue
endif
"
let b_idx1 = 1 + match ( linetxt, '\s*'.cc.'.*$', 0 )
let b_idx2 = 1 + match ( linetxt, cc.'.*$', 0 )
"
" not found?
if b_idx1 == 0
"echo 'line '.line.': no end-of-line comment'
continue
endif
"
" walk through ignored patterns
let idx_start = 0
"
while 1
let this_start = match ( linetxt, align_regex, idx_start )
"
if this_start == -1
break
else
let idx_start = matchend ( linetxt, align_regex, idx_start )
"echo 'line '.line.': ignoring >>>'.strpart(linetxt,this_start,idx_start-this_start).'<<<'
endif
endwhile
"
let b_idx1 = 1 + match ( linetxt, '\s*'.cc.'.*$', idx_start )
let b_idx2 = 1 + match ( linetxt, cc.'.*$', idx_start )
"
" not found?
if b_idx1 == 0
"echo 'line '.line.': no end-of-line comment'
continue
endif
"
call cursor ( line, b_idx2 )
let v_idx2 = virtcol('.')
"
" do b_idx1 last, so the cursor is in the right position for substitute below
call cursor ( line, b_idx1 )
let v_idx1 = virtcol('.')
"
" already at right position?
if ( v_idx2 == correct_idx )
"echo 'line '.line.': already at right position'
continue
endif
" ... or line too long?
if ( v_idx1 > correct_idx )
"echo 'line '.line.': line too long'
continue
endif
"
" substitute all whitespaces behind the cursor (regex '\%#') and the next character,
" to ensure the match is at least one character long
silent exe 'substitute/\%#\s*\(\S\)/'.repeat( ' ', correct_idx - v_idx1 ).'\1/'
"echo 'line '.line.': adjusted'
"
endfor
"
" restore the cursor position
call setpos ( '.', save_cursor )
"
endfunction " ---------- end of function Perl_AlignLineEndComm ----------
"
let s:Perl_CmtCounter = 0
let s:Perl_CmtLabel = "BlockCommentNo_"
"
"=== FUNCTION ================================================================
" NAME: Perl_CommentBlock {{{1
" DESCRIPTION: set block of code within POD == begin / == end
" PARAMETERS: mode - curent edit mode
"===============================================================================
function! Perl_CommentBlock (mode)
"
let s:Perl_CmtCounter = 0
let save_line = line(".")
let actual_line = 0
"
" search for the maximum option number (if any)
"
normal! gg
while actual_line < search( s:Perl_CmtLabel."\\d\\+" )
let actual_line = line(".")
let actual_opt = matchstr( getline(actual_line), s:Perl_CmtLabel."\\d\\+" )
let actual_opt = strpart( actual_opt, strlen(s:Perl_CmtLabel),strlen(actual_opt)-strlen(s:Perl_CmtLabel))
if s:Perl_CmtCounter < actual_opt
let s:Perl_CmtCounter = actual_opt
endif
endwhile
let s:Perl_CmtCounter = s:Perl_CmtCounter+1
silent exe ":".save_line
"
if a:mode=='a'
let zz= "\n=begin BlockComment # ".s:Perl_CmtLabel.s:Perl_CmtCounter
let zz= zz."\n\n=end BlockComment # ".s:Perl_CmtLabel.s:Perl_CmtCounter
let zz= zz."\n\n=cut\n\n"
put =zz
endif
if a:mode=='v'
let zz= "\n=begin BlockComment # ".s:Perl_CmtLabel.s:Perl_CmtCounter."\n\n"
:'<put! =zz
let zz= "\n=end BlockComment # ".s:Perl_CmtLabel.s:Perl_CmtCounter
let zz= zz."\n\n=cut\n\n"
:'>put =zz
endif
endfunction " ---------- end of function Perl_CommentBlock ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_UncommentBlock {{{1
" DESCRIPTION: uncomment block of code (remove POD commands)
"===============================================================================
function! Perl_UncommentBlock ()
let frstline = searchpair( '^=begin\s\+BlockComment\s*#\s*'.s:Perl_CmtLabel.'\d\+',
\ '',
\ '^=end\s\+BlockComment\s\+#\s*'.s:Perl_CmtLabel.'\d\+',
\ 'bn' )
if frstline<=0
echohl WarningMsg | echo 'no comment block/tag found or cursor not inside a comment block'| echohl None
return
endif
let lastline = searchpair( '^=begin\s\+BlockComment\s*#\s*'.s:Perl_CmtLabel.'\d\+',
\ '',
\ '^=end\s\+BlockComment\s\+#\s*'.s:Perl_CmtLabel.'\d\+',
\ 'n' )
if lastline<=0
echohl WarningMsg | echo 'no comment block/tag found or cursor not inside a comment block'| echohl None
return
endif
let actualnumber1 = matchstr( getline(frstline), s:Perl_CmtLabel."\\d\\+" )
let actualnumber2 = matchstr( getline(lastline), s:Perl_CmtLabel."\\d\\+" )
if actualnumber1 != actualnumber2
echohl WarningMsg | echo 'lines '.frstline.', '.lastline.': comment tags do not match'| echohl None
return
endif
let line1 = lastline
let line2 = lastline
" empty line before =end
if match( getline(lastline-1), '^\s*$' ) != -1
let line1 = line1-1
endif
if lastline+1<line("$") && match( getline(lastline+1), '^\s*$' ) != -1
let line2 = line2+1
endif
if lastline+2<line("$") && match( getline(lastline+2), '^=cut' ) != -1
let line2 = line2+1
endif
if lastline+3<line("$") && match( getline(lastline+3), '^\s*$' ) != -1
let line2 = line2+1
endif
silent exe ':'.line1.','.line2.'d'
let line1 = frstline
let line2 = frstline
if frstline>1 && match( getline(frstline-1), '^\s*$' ) != -1
let line1 = line1-1
endif
if match( getline(frstline+1), '^\s*$' ) != -1
let line2 = line2+1
endif
silent exe ':'.line1.','.line2.'d'
endfunction " ---------- end of function Perl_UncommentBlock ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_CommentToggle {{{1
" DESCRIPTION: toggle comment
"===============================================================================
function! Perl_CommentToggle () range
let comment=1 "
for line in range( a:firstline, a:lastline )
if match( getline(line), '^#') == -1 " no comment
let comment = 0
break
endif
endfor
if comment == 0
exe a:firstline.','.a:lastline."s/^/#/"
else
exe a:firstline.','.a:lastline."s/^#//"
endif
endfunction " ---------- end of function Perl_CommentToggle ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_CodeSnippet {{{1
" DESCRIPTION: read / write / edit code sni
" PARAMETERS: mode - edit, read, write, writemarked, view
"===============================================================================
function! Perl_CodeSnippet(mode)
if isdirectory(g:Perl_CodeSnippets)
"
" read snippet file, put content below current line
"
if a:mode == "read"
if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui'
let l:snippetfile=browse(0,"read a code snippet",g:Perl_CodeSnippets,"")
else
let l:snippetfile=input("read snippet ", g:Perl_CodeSnippets, "file" )
endif
if filereadable(l:snippetfile)
let linesread= line("$")
let l:old_cpoptions = &cpoptions " Prevent the alternate buffer from being set to this files
setlocal cpoptions-=a
:execute "read ".l:snippetfile
let &cpoptions = l:old_cpoptions " restore previous options
"
let linesread= line("$")-linesread-1
if linesread>=0 && match( l:snippetfile, '\.\(ni\|noindent\)$' ) < 0
silent exe "normal! =".linesread."+"
endif
endif
endif
"
" update current buffer / split window / edit snippet file
"
if a:mode == "edit"
if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui'
let l:snippetfile=browse(0,"edit a code snippet",g:Perl_CodeSnippets,"")
else
let l:snippetfile=input("edit snippet ", g:Perl_CodeSnippets, "file" )
endif
if !empty(l:snippetfile)
:execute "update! | split | edit ".l:snippetfile
endif
endif
"
" update current buffer / split window / view snippet file
"
if a:mode == "view"
if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui'
let l:snippetfile=browse(0,"view a code snippet",g:Perl_CodeSnippets,"")
else
let l:snippetfile=input("view snippet ", g:Perl_CodeSnippets, "file" )
endif
if !empty(l:snippetfile)
:execute "update! | split | view ".l:snippetfile
endif
endif
"
" write whole buffer or marked area into snippet file
"
if a:mode == "write" || a:mode == "writemarked"
if has("gui_running") && s:Perl_GuiSnippetBrowser == 'gui'
let l:snippetfile=browse(1,"write a code snippet",g:Perl_CodeSnippets,"")
else
let l:snippetfile=input("write snippet ", g:Perl_CodeSnippets, "file" )
endif
if !empty(l:snippetfile)
if filereadable(l:snippetfile)
if confirm("File ".l:snippetfile." exists ! Overwrite ? ", "&Cancel\n&No\n&Yes") != 3
return
endif
endif
if a:mode == "write"
:execute ":write! ".l:snippetfile
else
:execute ":*write! ".l:snippetfile
endif
endif
endif
else
redraw!
echohl ErrorMsg
echo "code snippet directory ".g:Perl_CodeSnippets." does not exist"
echohl None
endif
endfunction " ---------- end of function Perl_CodeSnippet ----------
"
"------------------------------------------------------------------------------
" Perl-Run : Perl_perldoc - lookup word under the cursor or ask
"------------------------------------------------------------------------------
"
let s:Perl_PerldocBufferName = "PERLDOC"
let s:Perl_PerldocHelpBufferNumber = -1
let s:Perl_PerldocModulelistBuffer = -1
let s:Perl_PerldocSearchWord = ""
let s:Perl_PerldocTry = "module"
"
"=== FUNCTION ================================================================
" NAME: Perl_perldoc {{{1
" DESCRIPTION: Perl_perldoc - lookup word under the cursor or ask
"===============================================================================
function! Perl_perldoc()
if( expand("%:p") == s:Perl_PerlModuleList )
normal! 0
let item=expand("<cWORD>") " WORD under the cursor
else
let cuc = getline(".")[col(".") - 1] " character under the cursor
let item = expand("<cword>") " word under the cursor
if empty(item) || match( item, cuc ) == -1
let item=Perl_Input("perldoc - module, function or FAQ keyword : ", "", '')
endif
endif
"------------------------------------------------------------------------------
" replace buffer content with Perl documentation
"------------------------------------------------------------------------------
if item != ""
"
" jump to an already open PERLDOC window or create one
"
if bufloaded(s:Perl_PerldocBufferName) != 0 && bufwinnr(s:Perl_PerldocHelpBufferNumber) != -1
exe bufwinnr(s:Perl_PerldocHelpBufferNumber) . "wincmd w"
" buffer number may have changed, e.g. after a 'save as'
if bufnr("%") != s:Perl_PerldocHelpBufferNumber
let s:Perl_PerldocHelpBufferNumber=bufnr(s:Perl_OutputBufferName)
exe ":bn ".s:Perl_PerldocHelpBufferNumber
endif
else
exe ":new ".s:Perl_PerldocBufferName
let s:Perl_PerldocHelpBufferNumber=bufnr("%")
setlocal buftype=nofile
setlocal noswapfile
setlocal bufhidden=delete
setlocal syntax=OFF
endif
"
" search order: library module --> builtin function --> FAQ keyword
"
let delete_perldoc_errors = ""
if s:UNIX && ( match( $shell, '\ccsh$' ) >= 0 )
" not for csh, tcsh
let delete_perldoc_errors = " 2>/dev/null"
endif
setlocal modifiable
"
" controll repeated search
"
if item == s:Perl_PerldocSearchWord
" last item : search ring :
if s:Perl_PerldocTry == 'module'
let next = 'function'
endif
if s:Perl_PerldocTry == 'function'
let next = 'faq'
endif
if s:Perl_PerldocTry == 'faq'
let next = 'module'
endif
let s:Perl_PerldocTry = next
else
" new item :
let s:Perl_PerldocSearchWord = item
let s:Perl_PerldocTry = 'module'
endif
"
" module documentation
if s:Perl_PerldocTry == 'module'
let command=":%!perldoc ".s:Perl_perldoc_flags." ".item.delete_perldoc_errors
silent exe command
if v:shell_error != 0
redraw!
let s:Perl_PerldocTry = 'function'
endif
if s:MSWIN
call s:perl_RemoveSpecialCharacters()
endif
endif
"
" function documentation
if s:Perl_PerldocTry == 'function'
" -otext has to be ahead of -f and -q
silent exe ":%!perldoc ".s:Perl_perldoc_flags." -f ".item.delete_perldoc_errors
if v:shell_error != 0
redraw!
let s:Perl_PerldocTry = 'faq'
endif
endif
"
" FAQ documentation
if s:Perl_PerldocTry == 'faq'
silent exe ":%!perldoc ".s:Perl_perldoc_flags." -q ".item.delete_perldoc_errors
if v:shell_error != 0
redraw!
let s:Perl_PerldocTry = 'error'
endif
endif
"
" no documentation found
if s:Perl_PerldocTry == 'error'
redraw!
let zz= "No documentation found for perl module, perl function or perl FAQ keyword\n"
let zz=zz." '".item."' "
silent put! =zz
normal! 2jdd$
let s:Perl_PerldocTry = 'module'
let s:Perl_PerldocSearchWord = ""
endif
if s:UNIX
" remove windows line ends
silent! exe ":%s/\r$// | normal! gg"
endif
setlocal nomodifiable
redraw!
" highlight the headlines
:match Search '^\S.*$'
" ------------
"
" ---------- Add ':' to the keyword characters -------------------------------
" Tokens like 'File::Find' are recognized as one keyword
setlocal iskeyword+=:
noremap <buffer> <silent> <S-F1> :call Perl_perldoc()<CR>
inoremap <buffer> <silent> <S-F1> <C-C>:call Perl_perldoc()<CR>
endif
endfunction " ---------- end of function Perl_perldoc ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_RemoveSpecialCharacters {{{1
" DESCRIPTION: remove <backspace><any character> in CYGWIN man(1) output
" remove _<any character> in CYGWIN man(1) output
"===============================================================================
function! s:perl_RemoveSpecialCharacters ( )
let patternunderline = '_\%x08'
let patternbold = '\%x08.'
setlocal modifiable
if search(patternunderline) != 0
silent exe ':%s/'.patternunderline.'//g'
endif
if search(patternbold) != 0
silent exe ':%s/'.patternbold.'//g'
endif
setlocal nomodifiable
silent normal! gg
endfunction " ---------- end of function s:perl_RemoveSpecialCharacters ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_perldoc_show_module_list {{{1
" DESCRIPTION: show module list
"===============================================================================
function! Perl_perldoc_show_module_list()
if !filereadable(s:Perl_PerlModuleList)
redraw!
echohl WarningMsg | echo 'Have to create '.s:Perl_PerlModuleList.' for the first time:'| echohl None
call Perl_perldoc_generate_module_list()
endif
"
" jump to the already open buffer or create one
"
if bufexists(s:Perl_PerldocModulelistBuffer) && bufwinnr(s:Perl_PerldocModulelistBuffer)!=-1
silent exe bufwinnr(s:Perl_PerldocModulelistBuffer) . "wincmd w"
else
:split
exe ":view ".s:Perl_PerlModuleList
let s:Perl_PerldocModulelistBuffer=bufnr("%")
setlocal nomodifiable
setlocal filetype=perl
setlocal syntax=none
noremap <buffer> <silent> <S-F1> :call Perl_perldoc()<CR>
inoremap <buffer> <silent> <S-F1> <C-C>:call Perl_perldoc()<CR>
endif
normal! gg
redraw!
if has("gui_running")
echohl Search | echomsg 'use S-F1 to show a manual' | echohl None
else
echohl Search | echomsg 'use \hh in normal mode to show a manual' | echohl None
endif
endfunction " ---------- end of function Perl_perldoc_show_module_list ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_perldoc_generate_module_list {{{1
" DESCRIPTION: generate module list
"===============================================================================
function! Perl_perldoc_generate_module_list()
" save the module list, if any
if filereadable( s:Perl_PerlModuleList )
let backupfile = s:Perl_PerlModuleList.'.backup'
if rename( s:Perl_PerlModuleList, backupfile ) != 0
echomsg 'Could not rename "'.s:Perl_PerlModuleList.'" to "'.backupfile.'"'
endif
endif
"
echohl Search
echo " ... generating Perl module list ... "
if s:MSWIN
silent exe ":!".s:Perl_Perl." ".fnameescape(s:Perl_PerlModuleListGenerator)." > ".shellescape(s:Perl_PerlModuleList)
silent exe ":!sort ".fnameescape(s:Perl_PerlModuleList)." /O ".fnameescape(s:Perl_PerlModuleList)
else
" direct STDOUT and STDERR to the module list file :
silent exe ":!".s:Perl_Perl." ".shellescape(s:Perl_PerlModuleListGenerator)." -s &> ".s:Perl_PerlModuleList
endif
redraw!
echo " DONE "
echohl None
endfunction " ---------- end of function Perl_perldoc_generate_module_list ----------
"
"=== FUNCTION ================================================================
" NAME: Perl_Settings {{{1
" DESCRIPTION: display various plugin settings
" PARAMETERS: -
" RETURNS:
"===============================================================================
function! Perl_Settings ( verbose )
"
if s:MSWIN | let sys_name = 'Windows'
elseif s:UNIX | let sys_name = 'UN*X'
else | let sys_name = 'unknown' | endif
"
let txt = " Perl-Support settings\n\n"
" template settings: macros, style, ...
if exists ( 'g:Perl_Templates' )
let txt .= ' author : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|AUTHOR|' )."\"\n"
let txt .= ' authorref : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|AUTHORREF|' )."\"\n"
let txt .= ' email : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|EMAIL|' )."\"\n"
let txt .= ' organization : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|ORGANIZATION|' )."\"\n"
let txt .= ' copyright holder : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|COPYRIGHT|' )."\"\n"
let txt .= ' copyright holder : "'.mmtemplates#core#ExpandText( g:Perl_Templates, '|LICENSE|' )."\"\n"
let txt .= ' template style : "'.mmtemplates#core#Resource ( g:Perl_Templates, "style" )[0]."\"\n\n"
else
let txt .= " templates : -not loaded- \n\”"
endif
" plug-in installation, template engine
let txt .= ' plugin installation : '.g:Perl_Installation.' on '.sys_name."\n"
" toolbox
if s:Perl_UseToolbox == 'yes'
let toollist = mmtoolbox#tools#GetList ( s:Perl_Toolbox )
if empty ( toollist )
let txt .= " using toolbox : -no tools-\n"
else
let sep = "\n"." "
let txt .= " using toolbox : "
\ .join ( toollist, sep )."\n"
endif
endif
let txt .= "\n"
" templates, snippets
let [ templist, msg ] = mmtemplates#core#Resource ( g:Perl_Templates, 'template_list' )
if empty ( templist )
let txt .= " template files : -no template files-\n"
else
let sep = "\n"." "
let txt .= " template files : "
\ .join ( templist, sep )."\n"
endif
let txt .=
\ ' code snippets dir. : '.s:Perl_CodeSnippets."\n"
if a:verbose >= 1
let txt .= "\n"
\ .' mapleader : "'.g:Perl_MapLeader."\"\n"
\ .' load menus / delayed : "'.s:Perl_LoadMenus.'" / "'.s:Perl_CreateMenusDelayed."\"\n"
\ .' insert file header : "'.s:Perl_InsertFileHeader."\"\n"
endif
let txt .= "\n"
" ----- xterm ------------------------
if !s:MSWIN
let txt = txt.' xterm defaults : '.s:Perl_XtermDefaults."\n"
endif
" ----- dictionaries ------------------------
if !empty(g:Perl_Dictionary_File)
let ausgabe= &dictionary
let ausgabe = substitute( ausgabe, ",", ",\n + ", "g" )
let txt = txt." dictionary file(s) : ".ausgabe."\n"
endif
let txt = txt." current output dest. : ".g:Perl_OutputGvim."\n"
let txt = txt." perlcritic : perlcritic -severity ".s:Perl_PerlcriticSeverity
\ .' ['.s:PCseverityName[s:Perl_PerlcriticSeverity].']'
\ ." -verbosity ".s:Perl_PerlcriticVerbosity
\ ." ".s:Perl_PerlcriticOptions."\n"
if !empty(s:Perl_PerlExecutableVersion)
let txt = txt." Perl interface version : ".s:Perl_PerlExecutableVersion."\n"