/
org.vim
8436 lines (7920 loc) · 299 KB
/
org.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
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
" org.vim - VimOrganizer plugin for Vim
" -------------------------------------------------------------
" Version: 0.30
" Maintainer: Herbert Sitz <hesitz@gmail.com>
" Last Change: 2011 Nov 02
"
" Script: http://www.vim.org/scripts/script.php?script_id=3342
" Github page: http://github.com/hsitz/VimOrganizer
" Copyright: (c) 2010, 2011 by Herbert Sitz
" The VIM LICENSE applies to all files in the
" VimOrganizer plugin.
" (See the Vim copyright except read "VimOrganizer"
" in places where that copyright refers to "Vim".)
" http://vimdoc.sourceforge.net/htmldoc/uganda.html#license
" No warranty, express or implied.
" *** *** Use At-Your-Own-Risk *** ***
"
"Section Setup
"if !exists('g:v')
" let g:v={}
"endif
" Calendar plugin at:
"http://www.vim.org/scripts/script.php?script_id=52
let b:v={}
set foldmethod=manual
let w:v={}
let b:v.prevlev = 0
let b:v.org_loaded=0
let b:v.lasttext_lev=''
let maplocalleader = "," " Org key mappings prepend single comma
let b:v.dateMatch = '\(\d\d\d\d-\d\d-\d\d\)'
let b:v.headMatch = '^\*\+\s'
let b:v.tableMatch = '^\(\s*|.*|\s*$\|#+TBLFM\)'
let b:v.taglineMatch = '^\s*:\S\+:\s*$'
let b:v.headMatchLevel = '^\(\*\)\{level}\s'
let b:v.propMatch = '^\s*:\s*\(PROPERTIES\)'
let b:v.propvalMatch = '^\s*:\s*\(\S*\)\s*:\s*\(\S.*\)\s*$'
let b:v.drawerMatch = '^\s*:\(PROPERTIES\|LOGBOOK\)'
let b:v.levelstars = 1
let b:v.effort=['0:05','0:10','0:15','0:30','0:45','1:00','1:30','2:00','4:00']
let b:v.tagMatch = '\(:\S*:\)\s*$'
let b:v.mytags = ['buy','home','work','URGENT']
let b:v.foldhi = ''
let b:v.org_inherited_properties = ['COLUMNS']
let b:v.org_inherited_defaults = {'CATEGORY':expand('%:t:r'),'COLUMNS':'%40ITEM %30TAGS'}
let b:v.heading_marks = []
let b:v.heading_marks_dict = {}
let w:v.total_columns_width = 30
let w:v.columnview = 0
let w:v.org_item_len = 100
let w:v.org_colview_list = []
let w:v.org_current_columns = ''
let w:v.org_column_item_head = ''
let b:v.chosen_agenda_heading = 0
let b:v.prop_all_dict = {}
let b:v.buf_tags_static_spec = ''
let b:v.buffer_category = ''
if !exists('g:org_agenda_default_search_spec')
let g:org_agenda_default_search_spec = 'ANY_TODO'
endif
if exists('g:global_column_defaults')
let b:v.buffer_columns = g:global_column_defaults
else
let b:v.buffer_columns = '%40ITEM %30TAGS'
endif
let w:sparse_on = 0
"if exists('g:global_column_view') && g:global_column_view==1
" let w:v.columnview = 1
"else
" let w:v.columnview = 0
"endif
let b:v.last_dict_time = 0
let b:v.last_idict_time = 0
let b:v.last_idict_type = 0
let b:v.clock_to_logbook = 1
let b:v.messages = []
let b:v.global_cycle_levels_to_show=4
let b:v.src_fold=0
let b:v.foldhilines = []
let b:v.cycle_with_text=1
let b:v.foldcolors=['Normal','SparseSkip','Folded','WarningMsg','WildMenu','DiffAdd','DiffChange','Normal','Normal','Normal','Normal']
let b:v.cols = []
setlocal cfu=Mycfu
set noswapfile
hi MatchGroup guibg=yellow guifg=black
setlocal ignorecase " searches ignore case
setlocal smartcase " searches use smart case
setlocal autoindent
setlocal fileformat=unix
setlocal backspace=2
setlocal nowrap
setlocal tw=78
setlocal expandtab
setlocal nosmarttab
setlocal softtabstop=0
setlocal foldcolumn=1
setlocal tabstop=4
setlocal shiftwidth=4
setlocal formatlistpat=^\\s*\\d\\+\\.\\s\\+\\\|^\\s*\\-\\s\\+
if has("conceal")
set conceallevel=3
set concealcursor=nc
endif
setlocal indentexpr=
setlocal foldexpr=OrgFoldLevel(v:lnum)
"setlocal iskeyword+=<
setlocal nocindent
setlocal iskeyword=@,39,45,48-57,_,129-255
let b:v.basedate = strftime("%Y-%m-%d %a")
let b:v.sparse_list = []
let b:v.fold_list = []
let b:v.suppress_indent=0
let b:v.suppress_list_indent=0
" LINE BELOW IS MAJOR IF THAT ENCOMPASSES MOST OF org.vim
" endif is near bottom of document
" everything in between is executed only the first time an
" org file is opened
if !exists('g:org_loaded')
" Load the checkbox plugin
execute "runtime ftplugins/vo_checkbox.vim"
function! s:SID()
return matchstr(expand('<sfile>'), '<SNR>\zs\d\+\ze_SID$')
endfun
let g:org_sid = s:SID()
let sid='<SNR>' . g:org_sid . '_'
function! OrgSID(func)
execute 'call <SNR>'.s:SID().'_'.a:func
endfunction
if !exists('g:org_custom_column_options')
let g:org_custom_column_options = ['%ITEM %15DEADLINE %35TAGS', '%ITEM %35TAGS']
endif
if !exists('g:org_command_for_emacsclient') && (has('unix') || has('macunix'))
let g:org_command_for_emacsclient = 'emacsclient'
endif
if !exists('g:org_custom_colors')
let g:org_custom_colors=[]
endif
if !exists('g:org_tags_persistent_alist')
let g:org_tags_persistent_alist = ''
endif
if !exists('g:org_save_when_searched')
let g:org_save_when_searched = 0
endif
if !exists('g:org_capture_file')
let g:org_capture_file = ''
endif
if !exists('g:org_sort_with_todo_words')
let g:org_sort_with_todo_words=1
endif
if !exists('g:org_tags_alist')
let g:org_tags_alist = ''
endif
if !exists('g:org_agenda_include_clocktable')
let g:org_agenda_include_clocktable = 0
endif
if !exists('g:org_confirm_babel_evaluate')
let g:org_confirm_babel_evaluate = 0
endif
if !exists('g:org_agenda_window_position')
let g:org_agenda_window_position = 'bottom'
endif
if has('win32') || has('win64')
let s:cmd_line_quote_fix = '^'
else
let s:cmd_line_quote_fix = ''
endif
let g:org_filename_wildcards = ['*.org']
let s:sfile = expand("<sfile>:p:h")
let s:last_refile_point = []
let g:org_todos_done_dict = {}
let g:org_todos_notdone_dict = {}
let g:org_agenda_todos_done_pattern = ''
let g:org_agenda_todos_notdone_pattern = ''
let g:org_clock_history=[]
let g:org_reverse_note_order = 0
let g:org_html_app=''
let g:org_pdf_app=''
let s:org_headMatch = '^\*\+\s'
let s:org_cal_date = '2000-01-01'
let g:org_export_babel_evaluate = 1
let g:org_tag_group_arrange = 0
let g:org_first_sparse=1
let g:org_clocks_in_agenda = 0
let s:remstring = '^\s*:\S'
let s:block_line = '^\s*\(:\|DEADLINE\|SCHEDULED\|CLOSED\|<\d\d\d\d-\|[\d\d\d\d-\)'
"let s:remstring = '^\s*\(:\|DEADLINE:\|SCHEDULED:\|CLOSED:\|<\d\d\d\d-\)'
let g:org_use_calendar = 1
let g:org_todoitems=[]
let s:headline = ''
let g:org_ColumnHead = 'Lines'
let g:org_gray_agenda = 0
let g:org_sparse_lines_after = 10
let g:org_log_todos=0
let g:org_timegrid=[8,20,2]
let w:v.org_colview_list = []
let s:firsttext = ''
let g:org_supported_link_types = '\(http\|file\|mailto\)'
let g:org_unsupported_link_types = '\(vm\|wl\|mhe\|rmail\|gnus\|bbdb\|irc\|info\|shell\|elisp\)'
let w:v.org_item_len=100
let w:sparse_on = 0
let g:org_folds = 1
let g:org_show_fold_lines = 1
let g:org_columns_default_width = 15
let s:org_columns_master_heading = 0
let w:v.org_colview_list=[]
let g:org_show_fold_dots = 0
let g:org_show_matches_folded=1
let g:org_indent_from_head = 0
let g:org_agenda_skip_gap = 2
let g:org_agenda_days=7
let g:org_agenda_minforskip = 8
let g:org_show_balloon_tips=1
let g:org_datelist = []
let g:org_search_spec = ''
let g:org_deadline_warning_days = 3
let s:org_weekdays = ['mon','tue','wed','thu','fri','sat','sun']
let s:org_weekdaystring = '\cmon\|tue\|wed\|thu\|fri\|sat\|sun'
let s:org_months = ['jan','feb','mar','apr','may','jun','jul','aug','sep','oct','nov','dec']
let s:org_monthstring = '\c\(jan\|feb\|mar\|apr\|may\|jun\|jul\|aug\|sep\|oct\|nov\|dec\)\S*'
let s:include_inherited_props=0
let s:AgendaBufferName = "__Agenda__"
let s:sparse_lines = {}
let s:search_list = []
let s:last_search_list = []
"testing stuff
function! CustomSearchesSetup()
let g:org_custom_searches = [
\ { 'name':"Next week's agenda", 'type':'agenda',
\ 'agenda_date':'+1w','agenda_duration':'w'}
\ ,{ 'name':"Next week's TODOS", 'type':'agenda',
\ 'agenda_date':'+1w','agenda_duration':'w','spec':'+UNFINISHED_TODOS'}
\ , { 'name':'Home tags', 'type':'tags', 'spec':'+HOME'}
\ , { 'name':'Home tags', 'type':'sparse_tree', 'spec':'+HOME'}
\ , [ { 'name':"Next week's agenda", 'type':'agenda',
\ 'agenda_date':'+1w','agenda_duration':'w'}
\ ,{ 'name':'Home tags', 'type':'tags', 'spec':'+HOME'}
\ ]
\ , [ { 'name':'Home tags', 'type':'tags', 'spec':'+HOME'}
\ ,{ 'name':"Next week's agenda", 'type':'agenda',
\ 'agenda_date':'+1w','agenda_duration':'w'}
\ ]
\ ]
endfunction
function! s:RunCustom(search)
" search arg is either number of predefined custom search,
" or full spec for search from agenda dashboard
if type(a:search) == type(1)
let search_spec = g:org_custom_searches[a:search]
else
let search_spec = a:search
endif
if !exists("g:agenda_files") || (g:agenda_files == [])
if has('dialog_con') || has('dialog_gui')
unsilent call confirm("No agenda files defined. Will add current file to agenda files.")
endif
call s:CurfileAgenda()
endif
if type(search_spec) == type({})
"single spec
let s:search_list = [ search_spec ]
else
" block agenda specs
let s:search_list = search_spec
endif
let this_time_list = s:search_list
if this_time_list[0].type !~ 'sparse_tree'
let curfile = expand("%:p")
let curtab = tabpagenr()
let curwin = winnr()
:AAgenda
" delete redo block (always just one) if any
if get(this_time_list[0],'redo_num') > 0
"redo_num is block in agenda to redo
let redo_num = s:AgendaBlockNum(this_time_list[0].redo_num)
normal gg
if redo_num > 1
for i in range(1,redo_num - 1)
call search('^==============','','')
endfor
endif
let start_line = (line('.') == 1) ? 1 : line('.') + 1
let test_end = search('^=========','W','')
let end_line = test_end > 0 ? test_end - 1 : line('$')
silent exec start_line . ',' . end_line . 'delete'
call append(start_line - 1,['','']) " append to agenda buf
let s:agenda_insert_point = start_line
elseif len(this_time_list) == 1
silent exec '%d'
let s:agenda_insert_point = 1
else
let s:agenda_insert_point = line('$')
endif
endif
let i = 0
for item in this_time_list
if i > 0
call append(line('$'),['',repeat('=',70),'','']) " append to agenda buf
let s:agenda_insert_point = line('$')
endif
let mydict = item
if mydict.type ==? 'agenda'
let mydate = DateCueResult( get(mydict,'agenda_date',''), s:Today())
let mydur = get(mydict, 'agenda_duration','w')
let mydur = (mydur == 'w') ? '7' : (mydur == 'd' ? '1' : mydur)
call OrgRunAgenda( mydate,
\ get(mydict, 'agenda_duration', 'w'),
\ get(mydict, 'spec','') )
let save_line = line('.')
let last_line = search('^============','W','') - 1
exec (last_line <= 0) ? line('$') : last_line
if (g:org_agenda_include_clocktable == 1)
call append(line('.'),OrgGetClocktable(g:agenda_files,' :narrow 40! :tstart ' . '"<' . mydate . ' xxx 00:00>" :tend "<' . calutil#cal(calutil#jul(mydate) + mydur ) . ' xxx 00:00>" :link ')[3:-3])
endif
exec save_line
elseif mydict.type ==? 'sparse_tree'
call OrgRunSearch( mydict.spec, 1 )
elseif mydict.type ==? 'sparse_tree_regex'
silent call s:SparseTreeRun(mydict.spec)
elseif mydict.type ==? 'tags'
call OrgRunSearch( mydict.spec )
elseif mydict.type ==? 'tags-todo'
" add todos to spec
call OrgRunSearch( mydict.spec,'agenda_todo' )
endif
let i += 1
endfor
set foldlevel=999
execute s:agenda_insert_point
nohl
endfunction
"Section Tag and Todo Funcs
function! OrgProcessConfigLines()
let b:v.org_config_lines = []
let b:v.todoitems = []
silent g/^#+/call add( b:v.org_config_lines, getline(line('.')) )
" clear out for new tag settings
let b:v.tagdict = {}
let b:v.buf_tags_static_spec = ''
let b:v.tagchars=''
let b:v.tags_order = []
if g:org_tags_alist ==# ''
let b:v.dynamic_tags=1
else
let b:v.dynamic_tags=0
endif
for line in b:v.org_config_lines
if line =~ '^#+CATEGORY'
let b:v.buffer_category = matchstr( line ,'^#+CATEGORY:\s*\zs.*')
let b:v.org_inherited_defaults['CATEGORY'] = b:v.buffer_category
elseif line =~ '^#+COLUMNS'
let b:v.buffer_columns = matchstr( line ,'^#+COLUMNS:\s*\zs.*')
let b:v.org_inherited_defaults['COLUMNS'] = b:v.buffer_columns
"let w:v.org_current_columns = b:v.buffer_columns
elseif line =~ '#+STARTUP:'
let startup_list = split(matchstr( line, '#+STARTUP:\s*\zs.*') )
for item in startup_list
silent! exec "let b:v." . item . "=1"
endfor
elseif line =~ '#+TAGS:'
let newtags = matchstr( line, '#+TAGS:\s*\zs.*')
if newtags ==# ''
let b:v.dynamic_tags = 1
else
let b:v.buf_tags_static_spec .= newtags . ' \n '
endif
elseif line =~ '\(#+TODO:\|#+SEQ_TODO:\)'
call OrgTodoSetup(matchstr(line,'\(#+TODO:\|#+SEQ_TODO:\)\s*\zs.*'))
elseif line =~ '#+PROPERTY:'
let m = matchlist(line,'.\{-}:\s*\(.\{-}\)_ALL \(.*\)')
if m[2] ># ''
let b:v.prop_all_dict[toupper(m[1])] = m[2]
endif
endif
endfor
if empty(b:v.todoitems)
call OrgTodoSetup(g:org_todo_setup)
endif
call OrgTagSetup( b:v.buf_tags_static_spec )
" get rid of b:v.buffer_category (and columns also) and just use o_i_d var???
if b:v.buffer_category ==# ''
let b:v.buffer_category = expand("%:t:r")
endif
normal gg
endfunction
function! s:EditProp(property)
let s:edit_prop = toupper(a:property)
let propval = get(s:GetProperties(line('.'),0), s:edit_prop,'')
function! s:PropCompleteFunc(arghead, sd, gf)
let prop = matchstr(a:sd,'^.\{-}\ze:')
let valuelist = split(get(b:v.prop_all_dict, s:edit_prop, ''))
let matches = filter(valuelist, 'v:val =~ a:arghead')
return join(matches, "\n")
endfunction
let myfunc = '<SNR>' . s:SID() . '_PropCompleteFunc'
let newval = input("Enter value for " . s:edit_prop . ": ", propval, 'custom,' . myfunc)
if newval != propval
call s:SetProp(s:edit_prop, newval)
echo s:edit_prop . " changed to: " newval
else
echo s:edit_prop . " not changed."
endif
endfunction
function! OrgTodoConvert(orgtodo)
let todolist = []
let sublist = []
let b:v.tododict = {}
" let templist = []
let temp_list = split(a:orgtodo,'\s\+')
for item in temp_list
if item == '|'
continue
endif
let b:v.tododict[item] = {}
if matchstr(item,'.*(.)') ==# ''
let b:v.tododict[item].todotext = item
let b:v.tododict[item].todochar = ''
else
let b:v.tododict[item].todotext = matchstr(item,'.*\ze(.)')
let b:v.tododict[item].todochar = matchstr(item,'.*(\zs.\ze)')
endif
endfor
" count '|' chars in list, if 0 or 1 then
" it is like Org-mode format, otherwise
" sublists are used in non-done slot"
let bar_count = count(split(a:orgtodo,'\zs'),'|')
let after_bar = 0
if bar_count >= 2
for item in temp_list
if item != '|'
call add(sublist,item)
elseif (item ==? '|')
call add(todolist,sublist)
let sublist = []
endif
endfor
else
for item in temp_list
if (item != '|') && (after_bar == 1)
call add(sublist,item)
elseif (item != '|') && (after_bar == 0)
call add(todolist,item)
elseif (item ==? '|')
let sublist = []
let after_bar = 1
endif
endfor
endif
if sublist != []
call add(todolist,sublist)
endif
return todolist
endfunction
function! OrgTodoSetup(todolist_str)
let todolist = OrgTodoConvert(a:todolist_str)
let b:v.todo_setup = a:todolist_str
"set up list and patterns for use throughout
let b:v.todoitems=[]
let b:v.todo_first_letters = ''
"let b:v.fulltodos=todolist
let b:v.todocycle=[]
let b:v.todoMatch=''
let b:v.todoNotDoneMatch=''
let b:v.todoDoneMatch=''
let i = 0
while i < len(todolist)
if type(todolist[i]) == type('abc')
let thistodo = matchstr(todolist[i],'.*ze(.)')
let thistodo = b:v.tododict[todolist[i]].todotext
let todolist[i] = substitute(todolist[i],'(.)','','')
call add(b:v.todoitems,thistodo)
call add(b:v.todocycle,thistodo)
" add to patterns
"let newtodo = b:v.todoitems[len(b:v.todoitems)-1]
let newtodo = thistodo
let b:v.todoMatch .= newtodo . '\|'
if i < len(todolist) - 1
let b:v.todoNotDoneMatch .= newtodo . '\|'
let g:org_todos_notdone_dict[newtodo] = 1
else
let b:v.todoDoneMatch .= newtodo . '\|'
let g:org_todos_done_dict[newtodo] = 1
endif
else
"item is itself a list
let j = 0
while j < len(todolist[i])
let thisitem = b:v.tododict[todolist[i][j]].todotext
let todolist[i][j] = substitute(todolist[i][j],'(.)','','')
call add(b:v.todoitems,thisitem )
if j == 0
call add(b:v.todocycle,thisitem)
endif
" add to patterns
let b:v.todoMatch .= thisitem . '\|'
if i < len(todolist) - 1
let b:v.todoNotDoneMatch .= thisitem . '\|'
let g:org_todos_notdone_dict[thisitem] = 1
else
let b:v.todoDoneMatch .= thisitem . '\|'
let g:org_todos_done_dict[thisitem] = 1
endif
let j += 1
endwhile
endif
let i += 1
endwhile
let b:v.todoMatch = '^\*\+\s*\zs\('.b:v.todoMatch[:-2] . ')'
let b:v.todoDoneMatch = '^\*\+\s*\zs\('.b:v.todoDoneMatch[:-2] . ')'
let b:v.todoNotDoneMatch = '^\*\+\s*\zs\('.b:v.todoNotDoneMatch[:-2] . ')'
let b:v.fulltodos = todolist
syntax clear DONETODO
exec 'syntax match DONETODO /' . b:v.todoDoneMatch . '/ containedin=OL1,OL2,OL3,OL4,OL5,OL6'
syntax clear NOTDONETODO
exec 'syntax match NOTDONETODO /' . b:v.todoNotDoneMatch . '/ containedin=OL1,OL2,OL3,OL4,OL5,OL6'
for item in keys( b:v.tododict )
let item_char = tolower( b:v.tododict[item].todochar)
if item_char ==# ''
let item_char = tolower(item[0])
endif
endfor
endfunction
function! s:CurfileAgenda()
exec "let g:agenda_files=['".expand("%:p")."']"
endfunction
function! OrgTagSetup(tagspec)
let b:v.tags = split(tr(a:tagspec,'{}',' '),'\s\+')
for item in b:v.tags
if item =~ '('
let char = matchstr(item,'(\zs.\ze)')
let tag = matchstr(item,'.*\ze(')
else
"find an unused character
let char = ''
let tag = item
let i = 0
while i < len(item)
"if !has_key(chardict, item[i])
" find char that isn't in tagchars yet
if b:v.tagchars !~ item[i]
let char = item[i]
"let chardict[item[i]] = 1
break
endif
let i += 1
endwhile
if char ==# ''
for i in range(65,90)
if b:v.tagchars !~ nr2char(i)
let char = nr2char(i)
break
endif
endfor
endif
endif
let b:v.tagdict[item] = {'char':char, 'tag':tag, 'exclude':'', 'exgroup':0}
call add(b:v.tags_order,item)
if char != ''
let b:v.tagchars .= char
endif
endfor
let templist = a:tagspec
let i = 1
while templist =~ '{.\{}}'
"cycle through groups and add exclude chars for any group members
let strikeout = matchstr(templist,'{.\{-}}')
let exclusive = matchstr(templist,'{\zs.\{-}\ze}')
let templist = substitute(templist,strikeout,'','')
let xlist = split(exclusive,'\s\+')
for item in xlist
let b:v.tagdict[item].exgroup = i
for x in xlist
if x != item
let b:v.tagdict[item].exclude .= b:v.tagdict[x].char
endif
endfor
endfor
let i += 1
endwhile
endfunction
function! OrgTagsEdit(...)
let line_file_str = ''
let lineno=line('.')
let file = expand("%")
if bufname("%") ==? ('__Agenda__')
" new file and lineno below to test with new line marker in agenda
let file = s:filedict[str2nr(matchstr(getline(line('.')), '^\d\d\d'))]
let lineno = str2nr(matchstr(getline(line('.')),'^\d\d\d\zs\d*'))
call org#SaveLocation()
call org#LocateFile(file)
call s:SetDynamicTags()
call org#RestoreLocation()
let b:v.tagdict = getbufvar(file,'v').tagdict
let b:v.tags_order = getbufvar(file,'v').tags_order
else
call s:SetDynamicTags()
endif
let heading_tags = get(s:GetProperties(lineno,0,file),'TAGS','')
let new_heading_tags = s:TagMenu(heading_tags)
if new_heading_tags != heading_tags
silent call s:SetProp('tags',new_heading_tags,lineno, file)
endif
endfunction
function! s:TagMenu(heading_tags)
let heading_tags = a:heading_tags
let tagstring = ''
let tagchars = ''
for item in b:v.tags_order
let tagchars .= b:v.tagdict[item].char
if match(heading_tags,':'.b:v.tagdict[item].tag .':') >= 0
let tagstring .= b:v.tagdict[item].char
endif
endfor
hi Cursor guibg=black
let cue = ''
set nomore
while 1
echo repeat('-',winwidth(0)-1)
echohl Title | echo 'Choose tags: ' | echohl None | echon '( <enter> to accept, <esc> to cancel )'
echo '------------'
let oldgroup = 0
let items_in_row = 1
for item in b:v.tags_order
if item ==? '\n'
continue
endif
let curindex = index(b:v.tags_order,item)
let newgroup = b:v.tagdict[item].exgroup
let select = ' '
if match(tagstring,b:v.tagdict[item].char) >= 0
let select = 'X'
echohl Question
else
echohl None
endif
"if (g:org_tag_group_arrange == 0) || (newgroup != oldgroup) || (newgroup == 0 ) || (b:v.tags_order[curindex+1] ==? '\n')
if (curindex == 0) || (b:v.tags_order[curindex-1] ==? '\n') || (winwidth(0) - (items_in_row*20) < 20)
echo repeat(' ',3) . '[' | echohl Question | echon select | echohl None | echon '] '
echohl None | echon b:v.tagdict[item].tag | echohl Title | echon '('.b:v.tagdict[item].char.')' | echohl None
let nextindent = repeat(' ',12-len(b:v.tagdict[item].tag))
let items_in_row = 1
else
"echon repeat(' ',3) .
echon nextindent
echon '[' | echohl Question | echon select | echohl None | echon '] '
echohl None | echon b:v.tagdict[item].tag | echohl Title | echon '('.b:v.tagdict[item].char.')' | echohl None
let nextindent = repeat(' ',12-len(b:v.tagdict[item].tag))
let items_in_row += 1
"echon repeat(' ', 12-len(b:v.tagdict[item]))
endif
let oldgroup = b:v.tagdict[item].exgroup
endfor
echo ""
"echohl LineNr | echon 'Date+time ['.basedate . ' '.basetime.']: '
"echohl None | echon cue.'_ =>' | echohl WildMenu | echon ' '.newdate.' '.newtime
let nchar = getchar()
let newchar = nr2char(nchar)
if (nchar ==? "\<BS>") && (len(cue)>0)
let cue = cue[:-2]
elseif nchar ==? "\<s-c-up>"
let cue = ((curdif-365>=0) ?'+':'').(curdif-365).'d'
elseif newchar ==? "\<s-cr>"
" add new tag . . . todo . . .
elseif newchar ==? "\<cr>"
break
elseif newchar ==? "\<Esc>"
hi Cursor guibg=gray
redraw
return a:heading_tags
elseif (match(tagchars,newchar) >= 0)
if (match(tagstring,newchar) == -1)
let tagstring .= newchar
" check for mutually exclusve tags
for item in keys(b:v.tagdict)
if b:v.tagdict[item].char ==? newchar
let exclude_str = b:v.tagdict[item].exclude
let tagstring = tr(tagstring,exclude_str,repeat(' ',len(exclude_str)))
break
endif
endfor
else
let tagstring = tr(tagstring,newchar,' ')
endif
endif
call substitute(tagstring,' ','','')
echon repeat(' ',72)
redraw
endwhile
hi Cursor guibg=gray
redraw
echo
set more
let heading_tags = ''
for item in keys(b:v.tagdict)
if (item!='\n') && (match(tagstring, b:v.tagdict[item].char) >= 0)
let heading_tags .= b:v.tagdict[item].tag . ':'
endif
endfor
if heading_tags ># '' | let heading_tags = ':' . heading_tags | endif
return heading_tags
endfunction
function! s:SetDynamicTags()
let taglist = s:GetBufferTags()
let chardict = {}
let b:v.tagdict = {}
let b:v.tagchars = ''
let b:v.tags_order = []
if b:v.buf_tags_static_spec ==# ''
let static_tags = g:org_tags_alist . ' ' . g:org_tags_persistent_alist
if static_tags ==# ''
let b:v.dynamic_tags_only = 1
endif
elseif exists('b:v.noptags')
let static_tags = b:v.buf_tags_static_spec
else
let static_tags = b:v.buf_tags_static_spec . ' ' . g:org_tags_persistent_alist
endif
if exists('b:v.dynamic_tags_only') && (b:v.dynamic_tags_only == 1)
let setup_string = join(taglist)
elseif exists('b:v.dynamic_tags') && (b:v.dynamic_tags == 1)
"first need to remove dups in dynamic taglist
let temp_list = split(static_tags)
for i in range(0,len(temp_list)-1)
if temp_list[i] =~ '(.)'
let temp_list[i] = matchstr(temp_list[i],'^.*\ze(')
endif
endfor
let dup_list = s:Intersect( temp_list, taglist )
for item in dup_list
call remove( taglist, index(taglist, item) )
endfor
let setup_string = static_tags . ' ' . join(taglist)
else
let setup_string = static_tags
endif
call OrgTagSetup( setup_string )
endfunction
function! s:GetBufferTags()
let save_cursor = getpos(".")
let b:v.buftagdict = {}
" call addtags for each headline in buffer
g/^\*/call s:AddTagsToDict(line("."))
call setpos('.',save_cursor)
return sort(keys(b:v.buftagdict))
endfunction
inoremap <F5> <C-R>=OrgEffort()<CR>
noremap <F5> A<C-R>=OrgEffort()<CR>
function! OrgEffort()
if getline(line('.'))=~':Effort:'
call setline(line('.'), substitute(getline(line('.')),'ort:\zs.*','',''))
normal A
call complete(col('.'),b:v.effort)
endif
return ''
endfunction
function! s:AddTagsToDict(line)
let taglist = s:GetTagList(a:line)
if !empty(taglist)
for item in taglist
execute "let b:v.buftagdict['" . item . "'] = 1"
endfor
endif
endfunction
function! s:GetTagList(line)
let text = getline(a:line+1)
if (text !~ b:v.drawerMatch) && (text !~ b:v.dateMatch) && (text =~ s:remstring)
let tags = matchlist(text,':\(\S*\):\s*$')
" include replacement of mistaken double colons with single colon
let tagstr = substitute(tags[1],'::',':','g')
if !empty(tags)
return split(tagstr,':')
else
return []
endif
else
return []
endif
endfunction
function! s:IsTagLine(line)
let text = getline(a:line)
return (text !~ b:v.drawerMatch) && (text !~ b:v.dateMatch) && (text =~ s:remstring)
endfunction
function! s:GetTags(line)
if s:IsTagLine(a:line+1)
return matchstr(getline(a:line+1),':.*$')
else
return ''
endif
endfunction
function! s:AddTag(tag,line)
if s:IsTagLine(a:line + 1)
if matchstr(getline(a:line+1),':'.a:tag.':') ==# ''
call setline(a:line+1,getline(a:line+1) . ':' .a:tag. ':')
endif
else
call append(a:line, ' :' . a:tag . ':')
endif
endfunction
function! s:TagInput(line)
let linetags = s:GetTagList(a:line)
if empty(linetags)
call append(a:line,':')
endif
let buftags = s:GetBufferTags()
let displaytags = deepcopy(buftags)
call insert(displaytags,' Exit Menu')
while 1
let curstatus = []
call add(curstatus,0)
let i = 1
let linetags = s:GetTagList(a:line)
while i < len(buftags) + 1
if index(linetags, buftags[i-1]) >= 0
let cbox = '[ X ]'
call add(curstatus,1)
else
let cbox = ' '
call add(curstatus,0)
endif
let displaytags[i] = cbox . s:PrePad('&'.buftags[i-1],28)
let i += 1
endwhile
let @/=''
if foldclosed(a:line) > 0
let b:v.sparse_list = [a:line]
else
normal V
endif
redraw
if foldclosed(a:line) > 0
let b:v.sparse_list = []
else
normal V
endif
"call insert(displaytags,'Choose tags below:')
"let key = inputlist(displaytags) - 1
let taglist = join(displaytags,"\n")
set guioptions+=v
let key = confirm('Choose tags:',taglist)-1
set guioptions-=v
"call remove(displaytags,0)
if (key == 0) " || (key == 1)
" need setline for final redraw
call setline(a:line+1,getline(a:line+1))
redraw
break
endif
let curstatus[key] = 1 - curstatus[key]
let newtags = ''
let i = 1
while i < len(curstatus)
if curstatus[i] == 1
let newtags .= ':' . buftags[i-1] . ':'
endif
let i += 1
endwhile
let newtags = substitute(newtags, '::',':','g')
call setline(a:line+1, repeat(' ',s:Starcount(a:line)+1) . newtags)
endwhile
if empty(s:GetTagList(a:line))
execute a:line+1 .'d'
execute a:line
endif
endfunction
function! s:UnconvertTags(line)
if s:IsTagLine(a:line+1)
normal J
endif
endfunction
function! <SID>GlobalUnconvertTags(state)
if exists('g:org_emacs_autoconvert') && (g:org_emacs_autoconvert != 0)
let s:save_cursor = getpos(".")
let s:last_changenr = a:state
mkview
normal A
g/^\*\+\s/call s:UnconvertTags(line("."))
silent! %s/^\(\s*\):\(DEADLINE\|SCHEDULED\|CLOSED\|CLOCK\|<\d\d\d\d-\d\d-\d\d\)/\1\2/
endif
endfunction
function! <SID>UndoUnconvertTags()
if exists('g:org_emacs_autoconvert') && (g:org_emacs_autoconvert != 0)
silent exec 'undo ' . s:last_changenr
silent undo
loadview
call setpos(".",s:save_cursor)
endif
endfunction
function! s:ConvertTags(line)
let tags = matchstr(getline(a:line), '\(:\S*:\)\s*$')
if tags ># ''
s/\s\+:.*:\s*$//
call append(a:line, repeat(' ',s:Starcount(a:line)+1) . tags)
endif
endfunction
function! <SID>GlobalConvertTags()
"if exists('g:org_emacs_autoconvert') && (g:org_emacs_autoconvert != 0)
let save_cursor = getpos(".")
g/^\*\+\s/call s:ConvertTags(line("."))
silent! %s/^\(\s*\)\(DEADLINE:\|SCHEDULED:\|CLOSED:\|CLOCK:\|<\d\d\d\d-\d\d-\d\d\)/\1:\2/
call setpos(".",save_cursor)
"endif
endfunction
function! s:GlobalFormatTags()
let save_cursor = getpos(".")
g/^\*\+\s/call s:FormatTags(line("."))
call setpos(".",save_cursor)
endfunction
function! s:FormatTags(line)
let tagmatch = matchlist(getline(a:line),'\(:\S*:\)\s*$')
if !empty(tagmatch)
let linetags = tagmatch[1]
s/\s\+:.*:\s*$//
" add newtags back in, including new tag
call setline(a:line,getline(a:line) . ' '
\ . repeat(' ', winwidth(0) - len(getline(a:line)) - len(linetags) - 15)
\ . linetags)
endif
endfunction
function! s:FCTest(line)
if foldclosed(a:line) != a:line
return a:line . ' --- ' . foldclosed(a:line)
endif
endfunction
function! OrgSequenceTodo(line,...)
if a:0 == 1
if a:1 ==? 'x'
let newtodo = ''
else
for item in b:v.todoitems
if item[0] ==? a:1
let newtodo = item
endif
endfor
endif
endif
let linetext = getline(a:line)
if (linetext =~ s:org_headMatch)
" get first word in line and its index in todoitems
let tword = matchstr(linetext,'\*\+\s\+\zs\S\+\ze')
if a:0 == 1
call s:ReplaceTodo(newtodo)
else
call s:ReplaceTodo()
endif
endif
endfunction