Repository navigation
Expand file tree
/
Copy pathhyperlist.vmb
More file actions
4688 lines (4089 loc) · 182 KB
/
Copy pathhyperlist.vmb
File metadata and controls
4688 lines (4089 loc) · 182 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
" Vimball Archiver by Charles E. Campbell
UseVimball
finish
syntax/hyperlist.vim [[[1
2258
" Script info {{{1
" Vim syntax and filetype plugin for HyperList files (.hl)
" Language: Self defined markup and functions for HyperLists in Vim
" Author: Geir Isene <g@isene.com>
" Web_site: http://isene.com/
" HyperList: http://isene.org/hyperlist/
" Github: https://github.com/isene/hyperlist.vim
" License: I release all copyright claims.
" This code is in the public domain.
" Permission is granted to use, copy modify, distribute, and
" sell this software for any purpose. I make no guarantee
" about the suitability of this software for any purpose and
" I am not liable for any damages resulting from its use.
" Further, I am under no obligation to maintain or extend
" this software. It is provided on an 'as is' basis without
" any expressed or implied warranty.
" Version: 2.9.1 - compatible with the HyperList definition v. 2.9
" Modified: 2025-10-21
" Changes: Added support for HyperList folding in markdown fenced code blocks. Closes #12
" Instructions {{{1
"
" Use tabs/shifts or * for indentations
"
" Use <SPACE> to toggle one fold. Use <c-SPACE> to toggle a fold recursively.
" Use \0 to \9, \a, \b, \c, \d, \e, \f to show up to 15 levels expanded.
"
" <leader># or <leader>an toggles autonumbering of new items (the previous
" item must be numbered for the next item to be autonumbered). An item is
" indented to the right with <c-t>, adding one level of numbering. An item
" is indented to the left with <c-d>, removing one level of numbering and
" increasing the number by one.
"
" As a sort of "presentation mode", you can traverse a HyperList by using
" g<DOWN> or g<UP> to view only the current line and its ancestors.
" An alternative is <leader><DOWN> and <leader><UP> to open more levels down.
"
" To highlight the current part of a HyperList (the current item and all its
" children), press <leader>h. This will uncollapse the whole HyperList and dim
" the whole HyperList except the current item and its children. To remove the
" highlighting, simply press <leader>h again (the fold level is restored).
"
" Use "gr" when the cursor is on a reference to jump to the referenced item.
" A reference can be in the list or to a file by the use of
" <file:/pathto/filename>, <file:~/filename> or <file:filename>.
"
" Use <leader>u to toggle underlining of Transitions, States or no underlining.
"
" Use <leader>v to add a checkbox at start of item or to toggle a checkbox.
" Use <leader>V to add/toggle a checkbox with a date stamp for completion.
"
" Use <leader><SPACE> to go to the next open template element.
" (A template element is a HyperList item ending in an equal sign).
"
" Use <leader>L to convert the entire document to LaTaX.
" Use <leader>H to convert the entire document to HTML.
" Use <leader>T to convert the entire document to a basic TPP presentation.
"
" Use <leader>z encrypts the current line (including all sublevels if folded).
" Use <leader>Z encrypts the current file (all lines).
" Use <leader>x decrypts the current line.
" Use <leader>X decrypts the current file (all lines).
" <leader>z and <leader>x can be used with visual ranges.
"
" A dot file (file name starts with a "." such as .test.hl) is
" automatically encrypted on save and decrypted on opening.
"
" You can add item tagged with future dates as items in your Google calendar.
" Use <leader>G to automatically add all items with future dates to your
" default calendar. Your default calendar is set in your .vimrc file with
" g:calendar = "yourcalendar". If not set in your .vimrc, a set of icalendar
" files will be written to your working directory. If you also want past events
" added to your calendar, add this to your .vimrc: g:alldates = 1
"
" Syntax is updated at start and every time you leave Insert mode.
"
" Much more information is found in the documentation (:help hyperlist.txt)
" Initializing {{{1
if version < 600
syntax clear
elseif exists('b:current_syntax')
finish
endif
" Fast startup optimization
let s:file_size = line('$')
let s:large_file_threshold = exists('g:hyperlist_large_file_threshold') ? g:hyperlist_large_file_threshold : 2000
let s:is_large_file = s:file_size > s:large_file_threshold
" Performance mode for large files
if s:is_large_file
let g:hyperlist_performance_mode = 1
" Reduce features for large files
let s:max_fold_levels = 8
syn sync minlines=5
syn sync maxlines=50
else
let s:max_fold_levels = 15
endif
let b:current_syntax = "HyperList"
" OS specific settings
let s:UNIX = has("unix") || has("win32unix")
let s:MAC = has("macunix")
let s:MSWIN = has("win16") || has("win32") || has("win64") || has("win95")
if s:MSWIN
if mapcheck("\<c-a>","n") != ""
nunmap <c-a>
endif
endif
if !exists("g:alldates")
let g:alldates=0
endif
" Modern features configuration {{{2
" Enable/disable modern features (default: auto-detect)
if !exists("g:hyperlist_enable_floating_windows")
let g:hyperlist_enable_floating_windows = has('nvim-0.4.0') && exists('*nvim_open_win')
endif
if !exists("g:hyperlist_enable_lsp_completion")
let g:hyperlist_enable_lsp_completion = 1
endif
if !exists("g:hyperlist_enable_telescope")
let g:hyperlist_enable_telescope = exists(':Telescope')
endif
" Floating window appearance
if !exists("g:hyperlist_float_border")
let g:hyperlist_float_border = 'rounded'
endif
if !exists("g:hyperlist_float_max_width")
let g:hyperlist_float_max_width = 80
endif
if !exists("g:hyperlist_float_max_height")
let g:hyperlist_float_max_height = 20
endif
" Preview timeout (milliseconds)
if !exists("g:hyperlist_preview_timeout")
let g:hyperlist_preview_timeout = 4000
endif
" Enable breadcrumb display
if !exists("g:hyperlist_show_breadcrumbs")
let g:hyperlist_show_breadcrumbs = 1
endif
" Auto-completion trigger characters
if !exists("g:hyperlist_completion_triggers")
let g:hyperlist_completion_triggers = ['#', '<', ':', '[']
endif
" Export configuration {{{2
" Export format preferences
if !exists("g:hyperlist_export_include_metadata")
let g:hyperlist_export_include_metadata = 1
endif
if !exists("g:hyperlist_export_author")
let g:hyperlist_export_author = "HyperList User"
endif
if !exists("g:hyperlist_export_title_prefix")
let g:hyperlist_export_title_prefix = "HyperList Export"
endif
" HTML export settings
if !exists("g:hyperlist_html_theme")
let g:hyperlist_html_theme = "modern" " modern, classic, minimal
endif
if !exists("g:hyperlist_html_include_css")
let g:hyperlist_html_include_css = 1
endif
" LaTeX export settings
if !exists("g:hyperlist_latex_document_class")
let g:hyperlist_latex_document_class = "article"
endif
if !exists("g:hyperlist_latex_font_size")
let g:hyperlist_latex_font_size = "11pt"
endif
if !exists("g:hyperlist_latex_include_toc")
let g:hyperlist_latex_include_toc = 1
endif
" Markdown export settings
if !exists("g:hyperlist_markdown_include_yaml")
let g:hyperlist_markdown_include_yaml = 1
endif
if !exists("g:hyperlist_markdown_checkbox_style")
let g:hyperlist_markdown_checkbox_style = "github" " github, unicode
endif
" iCal export settings
if !exists("g:hyperlist_ical_include_categories")
let g:hyperlist_ical_include_categories = 1
endif
if !exists("g:hyperlist_ical_default_duration")
let g:hyperlist_ical_default_duration = 30 " minutes
endif
" Settings {{{1
" File opening settings {{{2
" You can override all of these by setting global variables in your vimrc
" file, like this (note the "g" in front of the program type):
" let g:imageprogram = "eog"
"
" The following are the default programs for opening files in various OSes.
" If you are running Linux/Unix/win32unix
if s:UNIX
let b:wordprocessingprogram = "libreoffice"
let b:spreadsheetprogram = "libreoffice"
let b:presentationprogram = "libreoffice"
let b:pdfprogram = "zathura"
let b:imageprogram = "feh"
let b:browserprogram = "qutebrowser"
endif
" If you are running MacOSX
if s:MAC
let b:wordprocessingprogram = "open"
let b:spreadsheetprogram = "open"
let b:presentationprogram = "open"
let b:pdfprogram = "open"
let b:imageprogram = "open"
let b:browserprogram = "open"
endif
" If you are running MS Windows:
if s:MSWIN
" Add the path to the programs if you don't want to mess around with a path variable
" ...such as: '/Program^ Files^ (x86)/Microsoft^ Office/root/Office16/'
let b:wordprocessingprogram = "winword"
let b:spreadsheetprogram = "excel"
let b:presentationprogram = "powerpnt"
let b:pdfprogram = "AcroRd32"
let b:imageprogram = "i_view32"
let b:browserprogram = "firefox"
endif
" You can add programs to open other file types - and add the opener to the
" function "OpenFile()" (see example there). Example::
" let b:scadprogram = "openscad"
" Calendar settings (in your .vimrc) {{{2
" To be able to post events to your Google calendar, you must add the
" global calendar variable to your vimrc file, like this:
" let g:calendar = "youremail@provider.com"
" Sync settings {{{2
" Dynamic sync values based on file size for optimal performance
let s:file_lines = line("$")
if s:file_lines > 5000
" Large files: reduce sync for performance
syn sync minlines=10
syn sync maxlines=100
elseif s:file_lines > 1000
" Medium files: balanced sync
syn sync minlines=20
syn sync maxlines=200
else
" Small files: more thorough sync
syn sync minlines=50
syn sync maxlines=300
endif
" General settings {{{2
setlocal autoindent
setlocal textwidth=0
setlocal shiftwidth=3
setlocal tabstop=3
setlocal softtabstop=3
setlocal noexpandtab
setlocal guioptions+=t
setlocal foldmethod=syntax
setlocal fillchars=fold:\
syn sync fromstart
autocmd InsertLeave * :syntax sync fromstart
" Set off with no highlighting - toggled with <leader>h
let b:highlight = "false"
" Functions {{{1
" Modern Vim/Neovim compatibility {{{2
" Lazy loading wrapper for performance
let s:modern_features_loaded = 0
function! s:ensure_modern_features()
if !s:modern_features_loaded
call s:load_modern_features()
let s:modern_features_loaded = 1
endif
endfunction
function! s:load_modern_features()
" Load modern features only when needed
if exists('g:hyperlist_performance_mode') && g:hyperlist_performance_mode
" Skip expensive features in performance mode
return
endif
" Modern features loaded on-demand
endfunction
" Check if we're running Neovim with floating window support
function! s:has_floating_windows()
return has('nvim-0.4.0') && exists('*nvim_open_win')
endfunction
" Create a floating window for content display
function! s:create_floating_window(content, title)
if !s:has_floating_windows()
" Fallback to preview window for older Vim
pedit __HyperList_Preview__
wincmd P
setlocal buftype=nofile bufhidden=wipe noswapfile
call setline(1, a:content)
wincmd p
return -1
endif
let width = min([max(map(copy(a:content), 'len(v:val)')), 80])
let height = min([len(a:content), 20])
let row = (winheight(0) - height) / 2
let col = (winwidth(0) - width) / 2
let buf = nvim_create_buf(v:false, v:true)
call nvim_buf_set_lines(buf, 0, -1, v:true, a:content)
let opts = {
\ 'relative': 'editor',
\ 'width': width,
\ 'height': height,
\ 'row': row,
\ 'col': col,
\ 'style': 'minimal',
\ 'border': 'rounded'
\ }
let win = nvim_open_win(buf, v:false, opts)
" Set title if supported
if !empty(a:title)
call nvim_win_set_option(win, 'winhl', 'Normal:Normal,FloatBorder:FloatBorder')
endif
return win
endfunction
" Close floating window
function! s:close_floating_window(win_id)
if a:win_id != -1 && s:has_floating_windows()
try
call nvim_win_close(a:win_id, v:true)
catch
endtry
else
" Close preview window
pclose
endif
endfunction
" Modern utility functions {{{2
" Enhanced item navigation with breadcrumbs
function! ShowHyperListBreadcrumb()
let current_line = line('.')
let current_indent = indent(current_line)
let breadcrumb = []
" Walk backwards to find parent items
for lnum in range(current_line - 1, 1, -1)
let line_indent = indent(lnum)
if line_indent < current_indent
let line_text = substitute(getline(lnum), '^\s*', '', '')
let line_text = substitute(line_text, '\s*$', '', '')
call insert(breadcrumb, line_text)
let current_indent = line_indent
if current_indent == 0
break
endif
endif
endfor
" Add current item
let current_text = substitute(getline('.'), '^\s*', '', '')
call add(breadcrumb, current_text)
if len(breadcrumb) > 1
echo join(breadcrumb, ' > ')
else
echo breadcrumb[0]
endif
endfunction
" Smart folding based on context
function! SmartFoldContext()
let current_indent = indent('.')
let target_level = current_indent / &tabstop + 1
execute 'setlocal foldlevel=' . target_level
normal! zv
endfunction
" Quick item insertion with template
function! InsertHyperListItem(type)
let indent_str = repeat("\t", indent('.') / &tabstop)
let templates = {
\ 'todo': '[_] ',
\ 'done': '[x] ',
\ 'inprogress': '[O] ',
\ 'state': 'S: ',
\ 'transition': 'T: ',
\ 'property': ': ',
\ 'reference': '<>',
\ 'comment': '()',
\ 'hash': '#'
\ }
if has_key(templates, a:type)
let template = templates[a:type]
execute "normal! o" . indent_str . template
if a:type == 'reference'
execute "normal! i"
elseif a:type == 'comment'
execute "normal! i"
else
execute "normal! A"
endif
endif
endfunction
" Export current item and children to quickfix
function! ExportItemToQuickfix()
let start_line = line('.')
let start_indent = indent(start_line)
let end_line = start_line
" Find end of current item and its children
for lnum in range(start_line + 1, line('$'))
if indent(lnum) <= start_indent && getline(lnum) =~# '\S'
break
endif
let end_line = lnum
endfor
let qf_list = []
for lnum in range(start_line, end_line)
let line_text = getline(lnum)
if line_text =~# '\S' " Non-empty line
call add(qf_list, {
\ 'bufnr': bufnr('%'),
\ 'lnum': lnum,
\ 'text': line_text,
\ 'type': 'I'
\ })
endif
endfor
call setqflist(qf_list)
copen
endfunction
" Folding {{{2
" Mapped to <SPACE> and <leader>0 - <leader>f
setlocal foldtext=HLFoldText()
function! HLFoldText()
let line = getline(v:foldstart)
let myindent = indent(v:foldstart)
let line = substitute(line, '^\s*', '', 'g')
while myindent != 0
let myindent = myindent - 1
let line = ' ' . line
endwhile
return line
endfunction
" Highlighting {{{2
" Simplified Limelight - thanks to Junegunn Choi for the inspiration
" (https://travis-ci.org/junegunn/limelight.vim.svg?branch=master)
function! HighLight()
if b:highlight=="false"
echo "Highlight ON"
let b:fl=&fdl
setlocal foldlevel=15
let b:highlight="true"
autocmd CursorMoved,CursorMovedI * call HighLightHL()
else
echo "Highlight OFF"
let &fdl=b:fl
autocmd!
autocmd InsertLeave * :syntax sync fromstart
let b:highlight="false"
execute 'syn clear HLdim0'
execute 'syn clear HLdim1'
endif
endfunction
function! HighLightHL()
let start_line_number = line('.')
let end_line_number = start_line_number + 1
let start_line_indent = indent('.')
while indent(end_line_number) > start_line_indent
let end_line_number += 1
endwhile
let start = start_line_number
let end = end_line_number - 1
execute 'syn clear HLdim0'
execute 'syn clear HLdim1'
execute 'syn match HLdim0 ".*\%<' . string(start) . 'l"'
execute 'syn match HLdim1 ".*\%>' . string(end) . 'l"'
endfunction
" AutoNumbering {{{2
" Mapped to <leader># and <leader>an
" When activated, <cr> increments the next item on the same level
" <c-t> indents the item and adds one level of numbering
" <c-d> de-indents the item and renumbers it.
let s:an = 0
function! ToggleAutonum()
if s:an == 0
echo "Autonumber ON"
imap <cr> <cr><esc><up>yypf D<left><c-a>gJ:s/\(.*\d.\)\s*/\1 /<cr>A
imap <c-t> <esc>>>f <left><left><c-x>a.1<esc><end>a
imap <c-d> <esc><<f <left>T.diw<left>x<left><c-a><end>a
let s:an = 1
else
echo "Autonumber OFF"
iunmap <cr>
iunmap <c-t>
iunmap <c-d>
let s:an = 0
endif
endfunction
" Renumber {{{2
" Mapped to <leader>R
function! Renumber() range
let l1 = a:firstline
let l2 = a:lastline
"If the first line is without a number, add a 1 in the front
try
if match(getline(l1),'^\t*\d\+') != 0
exe l1 's/\(^\t*\)\(.*\)/\11 \2'
endif
catch
endtry
"Get the indent and store it in 'tabs'
let tabs = substitute(getline(l1), '^\(\t*\).*', '\1', '')
"The first part of numbering (like 1.2.) in 'initnum'
let initnum = substitute(getline(l1), '^\t*\([0-9.]\+\)*\d\+\.* .*', '\1', '')
"The numbering after initnum starts with 1
let numx = substitute(getline(l1), '^\t*\([0-9.]\+\)*\(\d\+\)\.* .*', '\2', '')
"Get the last period"
let period = substitute(getline(l1), '^\t*\([0-9.]\+\)*\(\d\+\)\(\.*\) .*', '\3', '')
"Start from first line
let lx = l1 + 1
"Loop until the last line
while lx <= l2
"If the indent matches (we will not number lines with greater indentations)
if match(getline(lx),tabs."[a-zA-ZæøåÆØÅáéóúãõâêôçàÁÉÓÚÃÕÂÊÔÇÀü0-9<>#()\*:]") == 0
let numx += 1
silent! exe lx 's/\(^\t*\)[0-9.]* \(.*\)/\1\2'
let startline = substitute(getline(lx), '\(^\t*\).*', '\1', '')
let numline = initnum . numx . period
let endline = substitute(getline(lx), '^\t*\(.*\)', ' \1', '')
let wholeline = startline . numline . endline
call setline(lx, wholeline)
endif
let lx += 1
endwhile
endfunction
" Encryption {{{2
" Remove traces of secure info upon decrypting (part of) a HyperList
function! HLdecrypt()
setlocal viminfo=""
setlocal noswapfile
endfunction
" Enhanced encryption functions with clean prompts
function! HLencryptLine()
call HLdecrypt()
echo "Encrypting line..."
execute ".!openssl aes-256-cbc -e -pbkdf2 -a -salt 2>/dev/null"
redraw!
endfunction
function! HLencryptVisual() range
call HLdecrypt()
echo "Encrypting selection..."
execute a:firstline . "," . a:lastline . "!openssl aes-256-cbc -e -pbkdf2 -a -salt 2>/dev/null"
redraw!
endfunction
function! HLencryptAll()
call HLdecrypt()
echo "Encrypting entire file..."
execute '%!openssl aes-256-cbc -e -pbkdf2 -a -salt 2>/dev/null'
redraw!
endfunction
function! HLdecryptLine()
call HLdecrypt()
echo "Decrypting line..."
execute ".!openssl aes-256-cbc -d -pbkdf2 -a -salt 2>/dev/null"
redraw!
endfunction
function! HLdecryptVisual() range
call HLdecrypt()
echo "Decrypting selection..."
execute a:firstline . "," . a:lastline . "!openssl aes-256-cbc -d -pbkdf2 -a -salt 2>/dev/null"
redraw!
endfunction
function! HLdecryptAll()
call HLdecrypt()
echo "Decrypting entire file..."
execute '%!openssl aes-256-cbc -d -pbkdf2 -a -salt 2>/dev/null'
redraw!
endfunction
" Underlining States/Transitions {{{2
" Mapped to <leader>u
let g:STu=0
hi link HLstate NONE
hi link HLtrans NONE
function! STunderline()
if g:STu == 0
hi link HLtrans NONE
hi link HLstate underlined
let g:STu = 1
elseif g:STu == 1
hi link HLstate NONE
hi link HLtrans underlined
let g:STu = 2
elseif g:STu == 2
hi link HLstate NONE
hi link HLtrans NONE
let g:STu = 0
endif
endfunction
" Checkbox and timestamp {{{2
" Mapped to <leader>v and <leader>V
function! CheckItem (stamp)
let current_line = getline('.')
if a:stamp ==# 'inprogress'
if current_line =~# '\[O\]'
exe 's/\[O\]/[_]/'
else
if current_line !~# '\[_\]'
exe "normal ^i[_] "
endif
exe 's/\[_\]/[O]/'
endif
return
endif
if current_line =~# '\[O\]'
exe 's/\[O\]/[x]/'
return
endif
if match(current_line,'\V[_]') >= 0
let time = strftime("%Y-%m-%d %H.%M")
exe 's/\V[_]/[x]/'
if a:stamp == "stamped"
exe "normal 0f]a ".time.":"
endif
elseif match(current_line,'\V[x]') >= 0
exe 's/\V[x]/[_]/i'
exe 's/\V[_] \d\d\d\d-\d\d-\d\d \d\d\.\d\d:/[_]/e'
else
exe "normal ^i[_] "
endif
endfunction
" Modern reference preview (optional enhancement) {{{2
" Enhanced reference preview with floating window support
function! s:preview_reference()
let current_line = getline('.')
if match(current_line,'<.*>') >= 0
let ref_word = matchstr(current_line,"<.\\{-}>")
let ref_word = substitute(ref_word, "<", '', 'g')
let ref_word = substitute(ref_word, '>', '', 'g')
if match(ref_word,"^file:") >= 0
let file_path = substitute(ref_word, 'file:', '', 'g')
if filereadable(file_path)
let content = readfile(file_path, '', 10)
let title = "File: " . file_path
let s:preview_win = s:create_floating_window(content, title)
call timer_start(5000, {-> s:close_floating_window(s:preview_win)})
augroup HLPreviewClose
autocmd!
autocmd CursorMoved * call s:close_floating_window(s:preview_win) | autocmd! HLPreviewClose
augroup END
else
echo "File not found: " . file_path
endif
elseif match(ref_word,"^[-+][0-9]") >= 0
let offset = str2nr(ref_word)
let target_line = line(".") + offset
if target_line > 0 && target_line <= line("$")
let preview_start = max([1, target_line - 5])
let preview_end = min([line("$"), target_line + 5])
let content = getline(preview_start, preview_end)
let title = "Line " . target_line . " (offset " . ref_word . ")"
let s:preview_win = s:create_floating_window(content, title)
call timer_start(3000, {-> s:close_floating_window(s:preview_win)})
else
echo "Invalid line reference: " . ref_word
endif
else
let ref_dest = substitute(ref_word, '/', '\\_.\\{-}\\t', 'g')
let ref_dest = "\\s" . ref_dest
let save_pos = getpos('.')
normal gg
if search(ref_dest) > 0
let found_line = line('.')
let preview_start = max([1, found_line - 3])
let preview_end = min([line("$"), found_line + 7])
let content = getline(preview_start, preview_end)
let title = "Reference: " . ref_word
let s:preview_win = s:create_floating_window(content, title)
call timer_start(4000, {-> s:close_floating_window(s:preview_win)})
else
echo "Reference not found: " . ref_word
endif
call setpos('.', save_pos)
endif
else
echo "No reference in the HyperList item"
endif
endfunction
" Modern goto reference with enhanced features
function! GotoRefModern()
" First show preview, then navigate after a delay
call s:preview_reference()
call timer_start(1000, {-> GotoRef()})
endfunction
" LSP-style completion system {{{2
" Get completion items based on context
function! s:get_completion_items()
let line = getline('.')
let col = col('.')
let before_cursor = line[:col-2]
let items = []
" State/Transition completion
if before_cursor =~# '\(S:\|T:\|\|\|/\)\s*$'
let items += ['TODO', 'DONE', 'IN_PROGRESS', 'WAITING', 'CANCELLED']
endif
" Hashtag completion - collect existing hashtags
if before_cursor =~# '#\w*$'
let hashtags = []
for lnum in range(1, line('$'))
let line_text = getline(lnum)
let matches = []
let start = 0
while 1
let match_pos = match(line_text, '#\w\+', start)
if match_pos == -1 | break | endif
let match_end = matchend(line_text, '#\w\+', start)
let hashtag = line_text[match_pos:match_end-1]
if index(hashtags, hashtag) == -1
call add(hashtags, hashtag)
endif
let start = match_end
endwhile
endfor
let items += hashtags
endif
" Reference completion - collect existing items that can be referenced
if before_cursor =~# '<[^>]*$'
let refs = []
for lnum in range(1, line('$'))
let line_text = getline(lnum)
if line_text =~# '^\s*\d\+\.'
let ref_text = substitute(line_text, '^\s*\(\d\+\.[^:]*\).*', '\1', '')
call add(refs, ref_text)
elseif line_text =~# '^\s*[A-Z][A-Z_]*:'
let ref_text = substitute(line_text, '^\s*\([A-Z][A-Z_]*\):.*', '\1', '')
call add(refs, ref_text)
endif
endfor
let items += refs
endif
" Property completion
if before_cursor =~# '\w\+:\s*$'
let prop = matchstr(before_cursor, '\w\+:\s*$')
if prop =~# '^priority:'
let items += ['high', 'medium', 'low']
elseif prop =~# '^status:'
let items += ['todo', 'doing', 'done', 'blocked']
elseif prop =~# '^date:'
let items += [strftime('%Y-%m-%d'), 'today', 'tomorrow', '+1week']
elseif prop =~# '^time:'
let items += ['09:00', '10:00', '14:00', '15:30']
endif
endif
" Checkbox completion
if before_cursor =~# '\[\s*$'
let items += ['_] ', 'x] ', 'O] ']
endif
return items
endfunction
" Modern completion function with floating window
function! HyperListComplete()
let items = s:get_completion_items()
if empty(items)
echo "No completions available"
return
endif
if s:has_floating_windows() && len(items) > 1
" Show completion in floating window
let content = map(copy(items), 'string(v:key+1) . ". " . v:val')
let title = "HyperList Completions"
let s:completion_win = s:create_floating_window(content, title)
" Set up completion selection
echo "Select completion (1-" . len(items) . ") or press Esc:"
let choice = getchar()
call s:close_floating_window(s:completion_win)
if choice >= char2nr('1') && choice <= char2nr('9')
let idx = choice - char2nr('1')
if idx < len(items)
return items[idx]
endif
endif
else
" Fallback to simple completion
if len(items) == 1
return items[0]
else
let choice = inputlist(['Select completion:'] + map(copy(items), 'string(v:key+1) . ". " . v:val'))
if choice > 0 && choice <= len(items)
return items[choice-1]
endif
endif
endif
return ''
endfunction
" Insert completion at cursor
function! InsertHyperListCompletion()
let completion = HyperListComplete()
if !empty(completion)
execute "normal! a" . completion
endif
endfunction
" Telescope.nvim integration (optional) {{{2
" Check if telescope is available
function! s:has_telescope()
return exists(':Telescope') && luaeval('pcall(require, "telescope")')
endfunction
" Telescope picker for HyperList items
function! TelescopeHyperListItems()
if !s:has_telescope()
echo "Telescope.nvim not available. Install telescope.nvim for enhanced navigation."
return
endif
lua << EOF
local pickers = require('telescope.pickers')
local finders = require('telescope.finders')
local conf = require('telescope.config').values
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
-- Collect HyperList items
local items = {}
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for i, line in ipairs(lines) do
local indent_level = 0
local content = line
-- Count indentation
local indent_match = string.match(line, '^(\t*)')
if indent_match then
indent_level = string.len(indent_match)
end
-- Extract meaningful content
if string.match(line, '%S') then -- Non-empty line
local display = string.rep(' ', indent_level) .. string.gsub(line, '^%s*', '')
table.insert(items, {
display = display,
line_number = i,
content = line
})
end
end
pickers.new({}, {
prompt_title = "HyperList Items",
finder = finders.new_table {
results = items,
entry_maker = function(entry)
return {
value = entry,
display = entry.display,
ordinal = entry.content,
}
end,
},
sorter = conf.generic_sorter({}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
vim.api.nvim_win_set_cursor(0, {selection.value.line_number, 0})
vim.cmd('normal! zz')
end)
return true
end,
}):find()
EOF
endfunction
" Telescope picker for references
function! TelescopeHyperListReferences()
if !s:has_telescope()
echo "Telescope.nvim not available"
return
endif
lua << EOF
local pickers = require('telescope.pickers')
local finders = require('telescope.finders')
local conf = require('telescope.config').values
local actions = require('telescope.actions')
local action_state = require('telescope.actions.state')
-- Find all references in the document
local refs = {}
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
for i, line in ipairs(lines) do
for ref in string.gmatch(line, '<([^>]+)>') do
table.insert(refs, {
reference = ref,
line_number = i,
line_content = line
})
end
end
if #refs == 0 then
print("No references found in this HyperList")
return
end
pickers.new({}, {
prompt_title = "HyperList References",
finder = finders.new_table {
results = refs,
entry_maker = function(entry)
return {
value = entry,
display = string.format("<%s> (line %d)", entry.reference, entry.line_number),
ordinal = entry.reference,
}
end,
},
sorter = conf.generic_sorter({}),
attach_mappings = function(prompt_bufnr, map)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
vim.api.nvim_win_set_cursor(0, {selection.value.line_number, 0})
vim.cmd('normal! zz')
end)
return true
end,
}):find()