forked from tj64/outshine
-
Notifications
You must be signed in to change notification settings - Fork 23
/
outshine.el
2458 lines (2173 loc) · 90.3 KB
/
outshine.el
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
;;; outshine.el --- outline with outshine outshines outline
;; Copyright (c) 2013-2019 Thorsten Jolitz and contributors.
;; Author: Thorsten Jolitz
;; Maintainer: Thibault Polge <[email protected]>
;; Maintainer: Adam Porter <[email protected]>
;; Version: 3.1-pre
;; URL: https://github.com/alphapapa/outshine
;; Package-Requires: ((outorg "2.0") (cl-lib "0.5"))
;; Licence: GPL2+
;; Keywords: convenience, outlines, Org
;;; License:
;; This file is not part of GNU Emacs.
;; 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, either version 2 of the License, or
;; (at your option) any later version.
;;
;; 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 for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Outshine attempts to bring the look & feel of Org-mode to the (GNU
;; Emacs) world outside of the Org major-mode. For more information,
;; please see the readme file in the git repo.
;;; Code:
;;;; Requirements
(eval-when-compile
;; FIXME: Remove
(require 'cl))
(require 'outline)
(require 'outorg)
(require 'outshine-org-cmds)
;; necessary before Emacs 24.3 FIXME: Remove
(require 'newcomment)
(require 'cl-lib)
;;;; Declarations
(declare-function outorg-edit-as-org "outorg")
(declare-function outorg-copy-edits-and-exit "outorg")
(declare-function navi-map-keyboard-to-key "navi-mode")
(declare-function navi-search-and-switch "navi-mode")
(declare-function navi-get-regexp "navi-mode")
(declare-function idomenu "idomenu")
(declare-function imenu-choose-buffer-index "imenu")
(declare-function org-agenda-remove-restriction-lock "org-agenda")
;;;; Constants
(defconst outshine-max-level 8
"Maximal level of headlines recognized.")
;; copied from org-source.el
(defconst outshine-level-faces
'(outshine-level-1 outshine-level-2 outshine-level-3 outshine-level-4
outshine-level-5 outshine-level-6 outshine-level-7
outshine-level-8))
(defconst outshine-protected-variables
'(outline-regexp outline-level outline-heading-end-regexp)
"Variables to save and restore around `outshine-mode'.
Please report a bug if this needs to be changed.")
(defconst outshine-oldschool-elisp-outline-regexp-base
(format "[;]\\{1,%d\\}" outshine-max-level)
;; FIXME: Remove if possible.
"Oldschool Emacs Lisp base for calculating `outline-regexp'.")
(defconst outshine-speed-commands-default
'(
("Outline Navigation")
;; [X]
("n" . (outshine-speed-move-safe
'outline-next-visible-heading))
;; [X]
("p" . (outshine-speed-move-safe
'outline-previous-visible-heading))
;; [X]
("f" . (outshine-speed-move-safe
'outline-forward-same-level))
;; [X]
("u" . (outshine-speed-move-safe
'outline-up-heading))
;; [X]
("b" . (outshine-speed-move-safe
'outline-backward-same-level))
;; [X] similar semantics
("F" . outshine-next-block)
;; [X] similar semantics
("B" . outshine-previous-block)
;; [X] similar semantics org-goto
("j" . outshine-navi)
;; [X] similar semantics org-goto
("J" . outshine-imenu)
;; [X] similar semantics (org-refile t)
;; ("g" . outshine-refile)
("g" . outshine-imenu)
("Outline Visibility")
;; [X]
("c" . outshine-cycle)
;; [X]
("C" . outshine-cycle-buffer)
;; [X]
(" " . (outshine-use-outorg
'org-display-outline-path
'WHOLE-BUFFER-P))
;; [X]
("r" . outshine-narrow-to-subtree)
;; [X]
("w" . widen)
;; ;; [ ]
;; ("=" . outshine-columns)
("Outline Structure Editing")
;; [X] FIXME error with oldschool elisp headers
("U" . outline-move-subtree-up)
;; [X] FIXME error with oldschool elisp headers
("D" . outline-move-subtree-down)
;; [X]
("+" . outline-demote)
;; [X]
("-" . outline-promote)
;; [X]
("i" . outshine-insert-heading)
;; [X] FIXME handle markers, special cases
("^" . outshine-sort-entries)
;; ;; [ ]
;; ("a" . (outshine-use-outorg
;; 'org-archive-subtree-default-with-confirmation))
;; [X]
("m" . outline-mark-subtree)
;; [X]
("#" . outshine-toggle-comment)
("Clock Commands")
;; FIXME need improvements!
;; [X]
("I" . outshine-clock-in)
;; [X]
("O" . outshine-clock-out)
("Date & Time Commands")
;; [X]
("." . outshine-time-stamp)
;; [X]
("!" . outshine-time-stamp-inactive)
;; [X] TODO add up/down(day)
("d" . outshine-deadline)
;; [X]
("s" . outshine-schedule)
("Exporting")
;; [X]
("x" . outshine-export-dispatch)
("Meta Data Editing")
;; [X]
("t" . outshine-todo)
;; [X]
("," . outshine-priority)
;; [X]
("0" . (outshine-use-outorg
(lambda () (interactive) (org-priority ?\ ))))
;; [X]
("1" . (outshine-use-outorg
(lambda () (interactive) (org-priority ?A))))
;; [X]
("2" . (outshine-use-outorg
(lambda () (interactive) (org-priority ?B))))
;; [X]
("3" . (outshine-use-outorg
(lambda () (interactive) (org-priority ?C))))
;; [X]
(":" . outshine-set-tags-command)
;; ;; [ ]
;; ("W" . (lambda(m) (interactive "sMinutes before warning: ")
;; (outshine-entry-put (point) "APPT_WARNTIME" m)))
("Properties and Effort")
;; [X]
("y" . outshine-set-property)
;; [X]
("Y" . outshine-set-property-and-value)
;; [X]
("e" . outshine-set-effort)
;; [X]
("E" . outshine-inc-effort)
;; ("Agenda Views etc")
;; [X]
("v" . outshine-agenda)
;; [X]
("<" . (outshine-agenda-set-restriction-lock))
;; [X]
(">" . (outshine-agenda-remove-restriction-lock))
;; ;; CANCELLED makes no sense
;; ("/" . outshine-sparse-tree)
("Misc")
;; [X]
("o" . outshine-open-at-point)
;; [X]
("?" . outshine-speed-command-help)
)
"Default speed commands.")
(defconst outshine-comment-tag "comment"
"Tag that marks subtrees as commented.
Commented subtrees do not open during visibility cycling.")
(defconst outshine-latex-documentclass-regexp
"^[[:space:]]*\\\\documentclass\\(?:\\[.+]\\)?{\\(.+\\)}"
"Regexp matching the document class in a LaTeX doc.")
;;;; Variables
(defvar outshine-mode-map
(make-sparse-keymap)
"The keymap for `outshine-mode'.")
(defvar-local outshine-protected-variables-values nil
"The values of variables defined by `outshine-protected-variables'.")
(defvar-local outshine-font-lock-keywords nil
"Font locking keywords defined in the current buffer.")
;; from `outline-magic'
(defvar-local outshine-promotion-headings nil
"A sorted list of headings used for promotion/demotion commands.
Set this to a list of headings as they are matched by `outline-regexp',
top-level heading first. If a mode or document needs several sets of
outline headings (for example numbered and unnumbered sections), list
them set by set, separated by a nil element. See the example for
`texinfo-mode' in the file commentary.")
(defvar-local outshine-delete-leading-whitespace-from-outline-regexp-base-p nil
"If non-nil, delete leading whitespace from outline-regexp-base.")
(defvar-local outshine-enforce-no-comment-padding-p nil
"If non-nil, make sure no comment-padding is used in heading.")
(defvar outshine-regexp-base ""
"Actual base for calculating the outline-regexp")
(defvar-local outshine-normalized-comment-start ""
"Comment-start regexp without leading and trailing whitespace")
(defvar-local outshine-normalized-comment-end ""
"Comment-end regexp without leading and trailing whitespace")
(defvar-local outshine-normalized-outline-regexp-base ""
"Outline-regex-base without leading and trailing whitespace")
;; show number of hidden lines in folded subtree
(defvar outshine-show-hidden-lines-cookies-p nil
"If non-nil, commands for hidden-lines cookies are activated.")
;; remember if hidden-lines cookies are shown or hidden
(defvar outshine-hidden-lines-cookies-on-p nil
"If non-nil, hidden-lines cookies are shown, otherwise hidden.")
(defvar-local outshine-imenu-default-generic-expression nil
"Expression assigned by default to `imenu-generic-expression'.")
(defvar-local outshine-imenu-generic-expression nil
"Expression assigned to `imenu-generic-expression'.")
(defvar outshine-self-insert-command-undo-counter 0
"Used for outshine speed-commands.")
(defvar outshine-speed-command nil
"Used for outshine speed-commands.")
(defvar outshine-open-comment-trees nil
"Cycle comment-subtrees anyway when non-nil.")
(defvar outshine-current-buffer-visibility-state nil
"Stores current visibility state of buffer.")
(defvar-local outshine-use-outorg-last-headline-marker (make-marker)
"Marker for last headline edited with outorg.")
(defvar outshine-imenu-preliminary-generic-expression nil
"Imenu variable.")
(defvar outshine-agenda-files ()
"List of absolute file names of outshine-agenda-files.")
(defvar outshine-agenda-include-org-agenda-p nil
"Include Org Agenda files in Outshine Agenda when non-nil.")
(defvar outshine-agenda-old-org-agenda-files nil
"Storage for old value of `org-agenda-files'")
;;;; Faces
(defgroup outshine-faces nil
"Faces in Outshine."
:tag "Outshine Faces"
:group 'outshine
:group 'faces)
;; from `org-compat.el'
(defun outshine-compatible-face (inherits specs)
;; FIXME: Remove this function. Shouldn't be necessary anymore.
"Make a compatible face specification.
If INHERITS is an existing face and if the Emacs version supports it,
just inherit the face. If INHERITS is set and the Emacs version does
not support it, copy the face specification from the inheritance face.
If INHERITS is not given and SPECS is, use SPECS to define the face.
XEmacs and Emacs 21 do not know about the `min-colors' attribute.
For them we convert a (min-colors 8) entry to a `tty' entry and move it
to the top of the list. The `min-colors' attribute will be removed from
any other entries, and any resulting duplicates will be removed entirely."
(when (and inherits
(facep inherits)
(not specs))
(setq specs (or specs
(get inherits 'saved-face)
(get inherits 'face-defface-spec))))
(cond ((and inherits
(facep inherits)
(not (featurep 'xemacs))
;; FIXME: Remove version checks, or move elsewhere.
(>= emacs-major-version 22)
;; do not inherit outline faces before Emacs 23
(or (>= emacs-major-version 23)
(not (string-match "\\`outline-[0-9]+"
(symbol-name inherits)))))
(list (list t :inherit inherits)))
((or (featurep 'xemacs)
(< emacs-major-version 22))
;; These do not understand the `min-colors' attribute.
;; FIXME: Rename variables meaningfully.
;; FIXME: Convert to `cl-loop'.
(let (r e a)
(while (setq e (pop specs))
(cond ((memq (car e) '(t default))
(push e r))
((setq a (member '(min-colors 8) (car e)))
(nconc r (list (cons (cons '(type tty)
(delq (car a) (car e)))
(cdr e)))))
((setq a (assq 'min-colors (car e)))
(setq e (cons (delq a (car e))
(cdr e)))
(unless (assoc (car e) r)
(push e r)))
(t (when (assoc (car e) r)
(push e r)))))
(nreverse r)))
(t specs)))
(put 'outshine-compatible-face 'lisp-indent-function 1)
;; The following face definitions are from `org-faces.el'
;; originally copied from font-lock-function-name-face
(defface outshine-level-1
(outshine-compatible-face 'outline-1
'((((class color) (min-colors 88)
(background light)) (:foreground "Blue1"))
(((class color) (min-colors 88)
(background dark)) (:foreground "LightSkyBlue"))
(((class color) (min-colors 16)
(background light)) (:foreground "Blue"))
(((class color) (min-colors 16)
(background dark)) (:foreground "LightSkyBlue"))
(((class color) (min-colors 8)) (:foreground "blue" :bold t))
(t (:bold t))))
"Face used for level 1 headlines."
:group 'outshine-faces)
;; originally copied from font-lock-variable-name-face
(defface outshine-level-2
(outshine-compatible-face 'outline-2
'((((class color) (min-colors 16)
(background light)) (:foreground "DarkGoldenrod"))
(((class color) (min-colors 16)
(background dark)) (:foreground "LightGoldenrod"))
(((class color) (min-colors 8)
(background light)) (:foreground "yellow"))
(((class color) (min-colors 8)
(background dark)) (:foreground "yellow" :bold t))
(t (:bold t))))
"Face used for level 2 headlines."
:group 'outshine-faces)
;; originally copied from font-lock-keyword-face
(defface outshine-level-3
(outshine-compatible-face 'outline-3
'((((class color) (min-colors 88)
(background light)) (:foreground "Purple"))
(((class color) (min-colors 88)
(background dark)) (:foreground "Cyan1"))
(((class color) (min-colors 16)
(background light)) (:foreground "Purple"))
(((class color) (min-colors 16)
(background dark)) (:foreground "Cyan"))
(((class color) (min-colors 8)
(background light)) (:foreground "purple" :bold t))
(((class color) (min-colors 8)
(background dark)) (:foreground "cyan" :bold t))
(t (:bold t))))
"Face used for level 3 headlines."
:group 'outshine-faces)
;; originally copied from font-lock-comment-face
(defface outshine-level-4
(outshine-compatible-face 'outline-4
'((((class color) (min-colors 88)
(background light)) (:foreground "Firebrick"))
(((class color) (min-colors 88)
(background dark)) (:foreground "chocolate1"))
(((class color) (min-colors 16)
(background light)) (:foreground "red"))
(((class color) (min-colors 16)
(background dark)) (:foreground "red1"))
(((class color) (min-colors 8)
(background light)) (:foreground "red" :bold t))
(((class color) (min-colors 8)
(background dark)) (:foreground "red" :bold t))
(t (:bold t))))
"Face used for level 4 headlines."
:group 'outshine-faces)
;; originally copied from font-lock-type-face
(defface outshine-level-5
(outshine-compatible-face 'outline-5
'((((class color) (min-colors 16)
(background light)) (:foreground "ForestGreen"))
(((class color) (min-colors 16)
(background dark)) (:foreground "PaleGreen"))
(((class color) (min-colors 8)) (:foreground "green"))))
"Face used for level 5 headlines."
:group 'outshine-faces)
;; originally copied from font-lock-constant-face
(defface outshine-level-6
(outshine-compatible-face 'outline-6
'((((class color) (min-colors 16)
(background light)) (:foreground "CadetBlue"))
(((class color) (min-colors 16)
(background dark)) (:foreground "Aquamarine"))
(((class color) (min-colors 8)) (:foreground "magenta")))) "Face used for level 6 headlines."
:group 'outshine-faces)
;; originally copied from font-lock-builtin-face
(defface outshine-level-7
(outshine-compatible-face 'outline-7
'((((class color) (min-colors 16)
(background light)) (:foreground "Orchid"))
(((class color) (min-colors 16)
(background dark)) (:foreground "LightSteelBlue"))
(((class color) (min-colors 8)) (:foreground "blue"))))
"Face used for level 7 headlines."
:group 'outshine-faces)
;; originally copied from font-lock-string-face
(defface outshine-level-8
(outshine-compatible-face 'outline-8
'((((class color) (min-colors 16)
(background light)) (:foreground "RosyBrown"))
(((class color) (min-colors 16)
(background dark)) (:foreground "LightSalmon"))
(((class color) (min-colors 8)) (:foreground "green"))))
"Face used for level 8 headlines."
:group 'outshine-faces)
;;;; Customization
;;;;; Custom Groups
(defgroup outshine nil
"Enhanced library for outline navigation in source code buffers."
:prefix "outshine-"
;; MAYBE: Change parent group.
:group 'lisp)
;;;;; Custom Vars
;; FIXME: Remove unnecessary `:group' from customs.
(defcustom outshine-imenu-show-headlines-p t
"Non-nil means use calculated outline-regexp for imenu."
:group 'outshine
:type 'boolean)
(defcustom outshine-fontify t
;; `quote' instead of ' to avoid conversion of ' in for example C-h v
;; (`describe-variable').
"When to fontify the outshine headings in a buffer.
Possible values are:
`t' Always (the default).
`nil' Never.
function A Lisp predicate function with no arguments. For example
`(lambda () (not (derived-mode-p (quote prog-mode))))'
fontifies only when not in a programming mode.
`t' and `nil' can be used for a file local variable to make an
exception for certain files or to be independent of the user's
customization."
:group 'outshine
:type '(choice :value ""
(const :tag "Always (the default)" t)
(const :tag "Never" nil)
(function :tag "Function"))
:safe (lambda (v) (memq v '(t nil))))
;; from `org'
(defcustom outshine-fontify-whole-heading-line nil
"Non-nil means fontify the whole line for headings.
This is useful when setting a background color for the
poutshine-level-* faces."
:group 'outshine
:type 'boolean)
(defcustom outshine-regexp-outcommented-p t
"Non-nil if regexp-base is outcommented to calculate outline-regexp."
:group 'outshine
:type 'boolean)
;; was "[][+]"
(defcustom outshine-regexp-special-chars
"[][}{,+[:digit:]\\]"
"Regexp for detecting (special) characters in outline-regexp.
These special chars will be stripped when the outline-regexp is
transformed into a string, e.g. when the outline-string for a
certain level is calculated. "
:group 'outshine
:type 'regexp)
;; from `outline-magic'
(defcustom outshine-cycle-emulate-tab nil
"Where should `outshine-cycle' emulate TAB.
nil Never
white Only in completely white lines
t Everywhere except in headlines"
:group 'outshine
:type '(choice (const :tag "Never" nil)
(const :tag "Only in completely white lines" white)
(const :tag "Everywhere except in headlines" t)
))
;; startup options
(defcustom outshine-startup-folded-p nil
"Non-nil means files will be opened with all but top level headers folded."
:group 'outshine
:type 'boolean)
(defcustom outshine-hidden-lines-cookie-left-delimiter "["
"Left delimiter of cookie that shows number of hidden lines."
:group 'outshine
:type 'string)
(defcustom outshine-hidden-lines-cookie-right-delimiter "]"
"Left delimiter of cookie that shows number of hidden lines."
:group 'outshine
:type 'string)
(defcustom outshine-hidden-lines-cookie-left-signal-char "#"
"Left signal character of cookie that shows number of hidden lines."
:group 'outshine
:type 'string)
(defcustom outshine-hidden-lines-cookie-right-signal-char ""
"Right signal character of cookie that shows number of hidden lines."
:group 'outshine
:type 'string)
(defcustom outshine-regexp-base-char "*"
"Character used in outline-regexp base."
:group 'outshine
:type 'string)
;; old regexp: "[*]+"
(defvar outshine-default-outline-regexp-base
;; MAYBE: Define this with a custom setter.
(format "[%s]\\{1,%d\\}"
outshine-regexp-base-char outshine-max-level)
"Default base for calculating the outline-regexp")
(defvar outshine-hidden-lines-cookie-format-regexp
(concat
"\\( "
(regexp-quote outshine-hidden-lines-cookie-left-delimiter)
(regexp-quote outshine-hidden-lines-cookie-left-signal-char)
"\\)"
"\\([[:digit:]]+\\)"
"\\("
(regexp-quote outshine-hidden-lines-cookie-right-signal-char)
;; FIXME robust enough?
(format "\\%s" outshine-hidden-lines-cookie-right-delimiter)
"\\)")
"Matches cookies that show number of hidden lines for folded subtrees.")
(defvar outshine-cycle-silently nil
"Suppress visibility-state-change messages when non-nil.")
(defcustom outshine-org-style-global-cycling-at-bob-p nil
"Configure the behavior of `outshine-cycle` on beginning of buffer.
When the point is on a heading and at the beginning of the
buffer (that is, when the first character of the buffer is the
start of a headline, and the point is on it), the behavior of
`outshine-cycle' is controlled by this variable:
- If nil, cycle the heading normally like in Org mode.
- Otherwise, cycle the entire buffer, ignoring the heading at point."
:group 'outshine
:type 'boolean)
(defcustom outshine-use-speed-commands nil
"Non-nil means activate single letter commands at beginning of a headline.
This may also be a function to test for appropriate locations
where speed commands should be active, e.g.:
(setq outshine-use-speed-commands
(lambda () ( ...your code here ... ))"
:group 'outshine
:type '(choice
(const :tag "Never" nil)
(const :tag "At beginning of headline stars" t)
(function)))
(defcustom outshine-speed-commands-user nil
"Alist of additional speed commands.
This list will be checked before `outshine-speed-commands-default'
when the variable `outshine-use-speed-commands' is non-nil
and when the cursor is at the beginning of a headline.
The car if each entry is a string with a single letter, which must
be assigned to `self-insert-command' in the global map.
The cdr is either a command to be called interactively, a function
to be called, or a form to be evaluated.
An entry that is just a list with a single string will be interpreted
as a descriptive headline that will be added when listing the speed
commands in the Help buffer using the `?' speed command."
:group 'outshine
:type '(repeat :value ("k" . ignore)
(choice :value ("k" . ignore)
(list :tag "Descriptive Headline" (string :tag "Headline"))
(cons :tag "Letter and Command"
(string :tag "Command letter")
(choice (function)
(sexp))))))
(defcustom outshine-speed-command-hook
'(outshine-speed-command-activate)
"Hook for activating speed commands at strategic locations.
Hook functions are called in sequence until a valid handler is
found.
Each hook takes a single argument, a user-pressed command key
which is also a `self-insert-command' from the global map.
Within the hook, examine the cursor position and the command key
and return nil or a valid handler as appropriate. Handler could
be one of an interactive command, a function, or a form.
Set `outshine-use-speed-commands' to non-nil value to enable this
hook. The default setting is `outshine-speed-command-activate'."
:group 'outshine
:version "24.1"
:type 'hook)
(defcustom outshine-self-insert-cluster-for-undo
(or (featurep 'xemacs) (version<= emacs-version "24.1"))
"Non-nil means cluster self-insert commands for undo when possible.
If this is set, then, like in the Emacs command loop, 20 consecutive
characters will be undone together.
This is configurable, because there is some impact on typing performance."
:group 'outshine
:type 'boolean)
(defcustom outshine-latex-classes
'(("scrbook" . ((1 . "^[[:space:]]*\\\\part\\*?{\\(.+\\)}")
(2 . "^[[:space:]]*\\\\chapter\\*?{\\(.+\\)}")
(3 . "^[[:space:]]*\\\\section\\*?{\\(.+\\)}")
(4 . "^[[:space:]]*\\\\subsection\\*?{\\(.+\\)}")
(5 . "^[[:space:]]*\\\\subsubsection\\*?{\\(.+\\)}")
(6 . "^[[:space:]]*\\\\paragraph\\*?{\\(.+\\)}")
(7 . "^[[:space:]]*\\\\subparagraph\\*?{\\(.+\\)}")))
("book" . ((1 . "^[[:space:]]*\\\\part\\*?{\\(.+\\)}")
(2 . "^[[:space:]]*\\\\chapter\\*?{\\(.+\\)}")
(3 . "^[[:space:]]*\\\\section\\*?{\\(.+\\)}")
(4 . "^[[:space:]]*\\\\subsection\\*?{\\(.+\\)}")
(5 . "^[[:space:]]*\\\\subsubsection\\*?{\\(.+\\)}")))
("report" . ((1 . "^[[:space:]]*\\\\part\\*?{\\(.+\\)}")
(2 . "^[[:space:]]*\\\\chapter\\*?{\\(.+\\)}")
(3 . "^[[:space:]]*\\\\section\\*?{\\(.+\\)}")
(4 . "^[[:space:]]*\\\\subsection\\*?{\\(.+\\)}")
(5 . "^[[:space:]]*\\\\subsubsection\\*?{\\(.+\\)}")))
("scrartcl" . ((1 . "^[[:space:]]*\\\\section\\*?{\\(.+\\)}")
(2 . "^[[:space:]]*\\\\subsection\\*?{\\(.+\\)}")
(3 . "^[[:space:]]*\\\\subsubsection\\*?{\\(.+\\)}")
(4 . "^[[:space:]]*\\\\paragraph\\*?{\\(.+\\)}")
(5 . "^[[:space:]]*\\\\subparagraph\\*?{\\(.+\\)}")))
("article" . ((1 . "^[[:space:]]*\\\\section\\*?{\\(.+\\)}")
(2 . "^[[:space:]]*\\\\subsection\\*?{\\(.+\\)}")
(3 . "^[[:space:]]*\\\\subsubsection\\*?{\\(.+\\)}")
(4 . "^[[:space:]]*\\\\paragraph\\*?{\\(.+\\)}")
(5 . "^[[:space:]]*\\\\subparagraph\\*?{\\(.+\\)}"))))
"Sectioning structure of LaTeX classes.
For each class, the outline level and a regexp matching the latex
section are given (with section title in submatch 1)."
:group 'outshine
:type '(alist :key-type string
:value-type alist))
(defcustom outshine-preserve-delimiter-whitespace nil
"Non-nil means that whitespace present at the start or end of
`comment-start' is preserved when matching headline syntax. By
default, such space is removed to support language modes which
erroneously include it in `comment-start', but for other
languages, such as Haskell, the trailing whitespace is
significant."
:group 'outshine
:type 'boolean)
;;;; Minor mode
;;;###autoload
(define-minor-mode outshine-mode
"Outshine brings the look&feel of Org-mode to the (GNU Emacs)
world outside of the Org major-mode."
:init-value nil
:lighter " Outshine"
(if outshine-mode
(outshine--minor-mode-activate)
(outshine--minor-mode-deactivate)))
(defun outshine--minor-mode-activate ()
"Activate Outshine.
Don't use this function, the public interface is
`outshine-mode'."
;; Ensure outline is on
(unless outline-minor-mode
(outline-minor-mode 1))
;; Save variables
(setq outshine-protected-variables-values (mapcar 'symbol-value outshine-protected-variables))
;; Install deactivation hook
(add-hook 'outline-minor-mode-hook 'outshine--outline-minor-mode-hook)
;; Advise org-store-log-note
(defadvice org-store-log-note (around org-store-log-note-around activate)
;; FIXME: Try to use `outshine-use-outorg' to do this instead of advice.
"Outcomment inserted log-note in Outshine buffers."
(let ((outshine-log-note-beg-marker
;; stay before inserted text
(copy-marker (outshine-mimic-org-log-note-marker) nil))
(outshine-log-note-end-marker
;; stay after inserted text
(copy-marker (outshine-mimic-org-log-note-marker) t)))
ad-do-it
(unless (derived-mode-p 'org-mode 'org-agenda-mode)
(outshine-comment-region outshine-log-note-beg-marker
outshine-log-note-end-marker))
(move-marker outshine-log-note-beg-marker nil)
(move-marker outshine-log-note-end-marker nil)))
;; Compute basic outline regular expressions
(outshine-set-outline-regexp-base)
(outshine-normalize-regexps)
(let ((out-regexp (outshine-calc-outline-regexp)))
(outshine-set-local-outline-regexp-and-level
out-regexp
'outshine-calc-outline-level
outline-heading-end-regexp)
(setq outshine-promotion-headings
(outshine-make-promotion-headings-list 8))
;; imenu preparation
(and outshine-imenu-show-headlines-p
(set (make-local-variable
'outshine-imenu-preliminary-generic-expression)
`((nil ,(concat out-regexp "\\(.*$\\)") 1)))
(if imenu-generic-expression
(add-to-list 'imenu-generic-expression
(car outshine-imenu-preliminary-generic-expression))
(setq imenu-generic-expression
outshine-imenu-preliminary-generic-expression)))
(when outshine-startup-folded-p
(condition-case error-data
(outline-hide-sublevels 1)
('error (message "No outline structure detected"))))
(when (pcase outshine-fontify
(`t t)
(`nil nil)
((pred functionp) (funcall outshine-fontify))
(_ (user-error "Invalid value for variable `outshine-fontify'")))
(outshine-fontify-headlines out-regexp))))
(defun outshine--minor-mode-deactivate ()
"Deactivate Outshine.
Don't use this function, the public interface is
`outshine-mode'."
;; Restore variables
(cl-mapc 'set outshine-protected-variables outshine-protected-variables-values)
;; Show everything
(outline-show-all)
;; Deactivate font-lock
(outshine-unfontify))
;;;###autoload
(defun outshine-hook-function ()
"DEPRECATED, use `outshine-mode'."
(warn "`outshine-hook-function' has been deprecated, use `outshine-mode'")
(outshine-mode 1))
(defun outshine--outline-minor-mode-hook ()
"Deactivate `outshine-mode' if `outshine-mode' but not `outline-minor-mode'.
This function will be hooked to `outline-minor-mode'."
(when (and outshine-mode
(not outline-minor-mode))
(outshine-mode 0)))
;;;; Functions
(defun outshine-mimic-org-log-note-marker ()
(if (version< (org-version) "8.3")
;; `org-log-beginning' added in Org 8.3
org-log-note-marker
(with-current-buffer (marker-buffer org-log-note-marker)
(goto-char org-log-note-marker)
(copy-marker (org-log-beginning)))))
;;;;; Define keys with fallback
;; copied and adapted from Alexander Vorobiev
;; http://www.mail-archive.com/[email protected]/msg70648.html
(defmacro outshine-define-key (keymap key def condition &optional mode)
"Define key with fallback.
Binds KEY to definition DEF in keymap KEYMAP, the binding is
active when the CONDITION is true. Otherwise turns MODE off and
re-enables previous definition for KEY. If MODE is nil, tries to
recover it by stripping off \"-map\" from KEYMAP name.
DEF must be a quoted symbol of an interactive command.
This interns a named function `outshine-kbd-[key-name]' with the
appropriate docstring so that calling `describe-key' on KEY
produces a more informative output."
(declare (indent defun))
(let ((fn-name
(intern (format "outshine-kbd-%s"
(if (eq (car-safe key) 'kbd)
(cadr key)
key))))
(docstring
(format "Run the interactive command `%s' if the following condition \
is satisfied:\n\n %s\n
Otherwise, fallback to the original binding of %s in the current mode."
(cadr def) ;; def is a quoted symbol (quote sym)
condition key))
(mode-name
(cond (mode mode)
((string-match
(rx (group (1+ any)) "-map" eol) (symbol-name keymap))
(intern (match-string 1 (symbol-name keymap))))
(t (error "Could not deduce mode name from keymap name")))))
`(progn
(defun ,fn-name ()
,docstring
(interactive)
(call-interactively
(if ,condition
,def
;; turn mode off and recover the original function
(let ((,mode-name nil))
(or (key-binding ,key)
,(if (equal (kbd "<tab>") key)
(key-binding (kbd "TAB")))
(lambda nil (interactive) (message "`%s' can do nothing useful here." (key-description ,key))))))))
(define-key ,keymap ,key (quote ,fn-name)))))
;;;;;; original macro (obsolete)
;; Note: the new macro uses a quoted symbol for the binding DEF, matching
;; the signature of `define-key'.
(make-obsolete 'outshine-define-key-with-fallback 'outshine-define-key "3.0")
(defmacro outshine-define-key-with-fallback
(keymap key def condition &optional mode)
"Define key with fallback.
Binds KEY to definition DEF in keymap KEYMAP, the binding is
active when the CONDITION is true. Otherwise turns MODE off and
re-enables previous definition for KEY. If MODE is nil, tries to
recover it by stripping off \"-map\" from KEYMAP name."
(declare (indent 2))
`(define-key
,keymap
,key
(lambda (&optional arg)
(interactive "P")
(if ,condition ,def
(let* ((,(if mode mode
(let* ((keymap-str (symbol-name keymap))
(mode-name-end
(- (string-width keymap-str) 4)))
(if (string=
"-map"
(substring keymap-str mode-name-end))
(intern (substring keymap-str 0 mode-name-end))
(message
"Could not deduce mode name from keymap name")
(intern "dummy-sym"))
)) nil)
;; Check for `<tab>'. It translates to `TAB' which
;; will prevent `(key-binding ...)' from finding the
;; original binding.
(original-func (if (equal (kbd "<tab>") ,key)
(or (key-binding ,key)
(key-binding (kbd "TAB")))
(key-binding ,key))))
(condition-case nil
(call-interactively original-func)
(error nil)))))))
;;;;; Normalize regexps
;; from http://emacswiki.org/emacs/ElispCookbook#toc6
(defun outshine-chomp (str)
"Chomp leading and trailing whitespace from STR."
(save-excursion
(save-match-data
(while (string-match
"\\`\n+\\|^\\s-+\\|\\s-+$\\|\n+\\'"
str)
(setq str (replace-match "" t t str)))
str)))
(defun outshine-set-outline-regexp-base ()
"Return the actual outline-regexp-base."
(if (and
(not (outshine-modern-header-style-in-elisp-p))
(eq major-mode 'emacs-lisp-mode))
(progn
(setq outshine-enforce-no-comment-padding-p t)
(setq outshine-regexp-base
outshine-oldschool-elisp-outline-regexp-base))
(setq outshine-enforce-no-comment-padding-p nil)
(setq outshine-regexp-base
outshine-default-outline-regexp-base)))
(defun outshine-normalize-regexps ()
"Chomp leading and trailing whitespace from outline regexps."
(and comment-start
(setq outshine-normalized-comment-start
(if outshine-preserve-delimiter-whitespace
comment-start
(outshine-chomp comment-start))))
(and comment-end
(setq outshine-normalized-comment-end
(outshine-chomp comment-end)))
(and outshine-regexp-base
(setq outshine-normalized-outline-regexp-base
(outshine-chomp outshine-regexp-base))))
;;;;; Calculate outline-regexp and outline-level
;; dealing with special case of oldschool headers in elisp (;;;+)
(defun outshine-modern-header-style-in-elisp-p (&optional buffer)
"Return nil, if there is no match for a outshine-style header.
Searches in BUFFER if given, otherwise in current buffer."
(let ((buf (or buffer (current-buffer))))
(with-current-buffer buf
(save-excursion
(goto-char (point-min))
(re-search-forward
;; (format "^;; [%s]+ " outshine-regexp-base-char)
(format "^;; [%s]\\{1,%d\\} "
outshine-regexp-base-char outshine-max-level)
nil 'NOERROR)))))
(defun outshine-calc-comment-region-starter ()
"Return comment-region starter as string.
Based on `comment-start' and `comment-add'."
(if (or (not comment-add) (eq comment-add 0))
outshine-normalized-comment-start
(let ((comment-add-string outshine-normalized-comment-start))
(dotimes (i comment-add comment-add-string)
(setq comment-add-string