forked from tj64/outshine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outshine.el
4326 lines (3820 loc) · 157 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
;; Author: Thorsten Jolitz <tjolitz AT gmail DOT com>
;; Version: 2.0
;; URL: https://github.com/tj64/outshine
;; Package-Requires: ((outorg "2.0"))
;;;; MetaData
;; :PROPERTIES:
;; :copyright: Thorsten_Jolitz
;; :copyright-from: 2013+
;; :version: 2.0
;; :licence: GPL 2 or later (free software)
;; :licence-url: http://www.gnu.org/licenses/
;; :part-of-emacs: no
;; :authors: Thorsten_Jolitz Carsten_Dominik Per_Abrahamsen
;; :author_email: tjolitz AT gmail DOT com
;; :credits: Fabrice_Niessen Alexander_Vorobiev Jonas_Bernoulli
;; :inspiration: outline-magic outxxtra out-xtra
;; :keywords: emacs outlines file_structuring
;; :git-repo: https://github.com/tj64/outshine.git
;; :git-clone: git://github.com/tj64/outshine.git
;; :END:
;;;; Commentary
;;;;; About outshine
;; Outshine attempts to bring the look&feel of Org-mode to the (GNU
;; Emacs) world outside of the Org major-mode. It is an extension of
;; outline-minor-mode (Org-mode itself derives from outline-mode), so
;; there is no such thing like an 'outshine mode', only
;; `outline-minor-mode' with outshine extensions loaded.
;; Outshine is major-mode agnostic. At least in theory, it should work
;; out-of-the-box with all major-modes, even those not yet written, as
;; long as these modes have comment syntax defined. In real life there
;; are some major-modes where outshine just works, others that need
;; some minor tweaks to make outshine work, and a few that need
;; special handling.
;; An outshine file is structured just like an org file, only that the
;; headlines are outcommented with the current major-mode's comment
;; syntax. We call these outcommented org headers 'outshine
;; headers'. The different headline levels are fontified like in
;; Org-mode, and many of the outline-navigation, visibility cycling
;; and structure editing commands known from Org-mode work in outshine
;; too. An Org-mode user will feel right at home in an outshine
;; buffer, the look&feel should be pretty similar, only the
;; keybindings differ. Since outshine extends a minor-mode it has to
;; avoid conflicts with major-mode keymaps by using a rather unusual
;; prefix that is still easy to type (M-#). But the Org-mode
;; speed-commands have been ported to outshine too, and they use
;; exactly the same (one-key) bindings like in Org-mode.
;; There is a distinction between the library 'outshine.el' and the
;; 'Outshine Project' (or 'Outshine Suite') which contains 3
;; libraries:
;; - outshine.el :: The core library. The `outshine-hook-function'
;; must be added to the `outline-minor-mode-hook' to
;; activate its extensions when outline-minor-mode
;; is loaded.
;; - outorg.el :: Major-mode for toggling between the
;; programming-mode view and the org-mode view of
;; outshine buffers, i.e. buffers structured with
;; outshine headers that have outline-minor-mode with
;; outshine extensions activated.
;; - navi-mode.el :: Occur-based major-mode for super-fast
;; buffer-navigation and buffer-remote-control with
;; one-key-bindings from an associated read-only
;; *Navi* buffer. Navi-mode allows to have the
;; (outshine- or org-) buffer overview side by side
;; with the buffer details, and it gives many
;; different kinds of overviews (these views are
;; actually customizable). With point in the *Navi*
;; overview buffer, many actions in the associated
;; original (outshine- or org-) buffer can be
;; triggered without leaving the *Navi* buffer.
;; Note that there is a fourth library 'poporg.el' from François
;; Pinard, which allows to edit function docstrings in temporary
;; Org-mode buffers and thus nicely complements 'outorg.el'.
;; Together these libraries enable a lightweight kind of 'literate
;; programming' that turns the usual implementation of the concept
;; upside-down: instead of using a text-mode as default and taking
;; extra action to edit and execute source-code, with Outshine the
;; programming-mode is the default mode and the text-mode
;; (i.e. Org-mode) only called when needed. This is much simpler, it
;; treats Org-mode and Programming-mode simply as two different views
;; on the same (outshine) file while making it easy to switch between
;; these views.
;;;;; History and Credits
;; The outshine.el library merges, modifies and extends two existing
;; extension-libraries for `outline' (minor) mode: `outline-magic' (by
;; Carsten Dominik) and `out-xtra' (by Per Abrahamsen). It offers all the
;; functionality of `outline-magic' (with some tiny changes and fixes)
;; and parts of the functionality of `out-xtra', together with many new
;; features and ideas.
;; See `outline-magic.el' (https://github.com/tj64/outline-magic) for
;; detailled instructions on the usage of the additional outline
;; functions introduced by `outline-magic'.
;; Furthermore, `outshine.el' includes some functions and keybindings
;; from `outline-mode-easy-bindings'
;; (http://emacswiki.org/emacs/OutlineMinorMode). Unfortunately, no
;; author is given for that library, so I cannot credit the person who
;; wrote it.
;;;;; Installation
;; There are three ways to get outshine.el (and the other Outshine
;; libraries):
;; 1. Clone the git repos or fork them on github
;; (https://github.com/tj64)
;; 2. Use the package manager to install them (from MELPA).
;; 3. Simply download the raw .el files from github and copy them to a
;; location where Emacs can find. This is not really recommended,
;; since easy updating is not possible this way.
;; Note that since version 2.0, outshine.el depends on outorg.el and
;; navi-mode.el depends on both, outshine.el and outorg.el. So the order
;; of installation should be
;; 1. outorg
;; 2. outshine
;; 3. navi-mode (optional)
;; Put this in your init.el or '.emacs' to get started:
;; : #+begin_src emacs-lisp
;; : (require 'outshine)
;; : (add-hook 'outline-minor-mode-hook 'outshine-hook-function)
;; : #+end_src
;; Add this to your init file if you always want outshine for emacs-lisp
;; buffers (recommended):
;; : #+begin_src emacs-lisp
;; : (add-hook 'emacs-lisp-mode-hook 'outline-minor-mode)
;; : #+end_src
;; It makes sense to add 'outline-minor-mode' to the hooks of other
;; major-modes too, e.g.
;; : #+begin_src emacs-lisp
;; : (add-hook 'LaTeX-mode-hook 'outline-minor-mode)
;; : (add-hook 'picolisp-mode-hook 'outline-minor-mode)
;; : (add-hook 'clojure-mode-hook 'outline-minor-mode)
;; : (add-hook 'ess-mode-hook 'outline-minor-mode)
;; : (add-hook 'ledger-mode-hook 'outline-minor-mode)
;; : (add-hook 'message-mode-hook 'outline-minor-mode)
;; : #+end_src
;; or whatever your favorite Emacs modes are. Then you can structure and
;; handle all your source-files just like Org files, allowing for a
;; uniform approach to file structuring independent from the (text or
;; programming) mode.
;; Outline(-minor)-mode comes with a rather unusable prefix key
;; out-of-the-box. You need to set the outshine prefix (M-#) in your init
;; file before (!) outline-mode is loaded to enable the outshine
;; keybindings:
;; : #+begin_src emacs-lisp
;; : (defvar outline-minor-mode-prefix "\M-#")
;; : #+end_src
;;;;; Usage
;;;;;; Basic Usage
;; The outshine.el extensions to outline-minor-mode aim to make its
;; use more similar to Org-mode. Given a correctly structured outshine
;; buffer, outline-navigation, structure-editing and visibility
;; cycling with outshine should make an Org-mode user feel right at
;; home.
;; Try C-h m (describe-mode) and C-h b (describe-bindings) in an
;; outshine buffer to find out more about the available functions and
;; their keybindings.
;; The very useful Org speed-commands have been ported to outshine,
;; here a quote from the
;; [[http://orgmode.org/manual/Speed-keys.html][Org-mode manual]] that
;; describes what they do:
;; #+BEGIN_QUOTE
;; Single keys can be made to execute commands when the cursor is at
;; the beginning of a headline, i.e., before the first star.
;; #+END_QUOTE
;; To activate speed-keys, put this in your init-file:
;; : #+BEGIN_SRC emacs-lisp
;; : (setq outshine-use-speed-commands t)
;; : #+END_SRC
;; Call `outshine-speed-command-help' to get an overview over the
;; available functionality and the keybindings.
;; Note that outshine works with 'imenu' (`outshine-imenu') and has
;; extra functionality to show the number of hidden lines in folded
;; headlines (`outshine-show-hidden-lines-cookies'). There are a few
;; utility commands for latex-mode too
;; (`outshine-latex-insert-header',
;; `outshine-latex-insert-headers-in-buffer' and
;; `outshine-TeX-command-region-on-subtree')
;;;;;; Extended Usage (outshine-use-outorg)
;; Outshine's basic usage is mostly based on its own implementation,
;; i.e. code from existing extensions to outline-minor-mode, new code
;; written for outshine, as well as code ported from Org-mode to
;; outshine.
;; Its extended use aims to make outshine headers more 'intelligent',
;; i.e. make them know about TODO items, tags, properties, dates and
;; times. This is done via the `outshine-use-outorg' function that
;; uses outorg to first convert an outshine buffer/subtree to
;; org-mode, then call an Org function on it, and finally convert the
;; edited buffer/subtree back to outshine. The outshine-use-outorg
;; concept turns outshine into a kind of org-minor-mode without
;; actually reimplementing Org functionality, just by reusing it with
;; the help of outorg.
;; This is still work in progress. Not all Org commands make sense in
;; an outshine buffer. Not all work out-of-the-box. Since there are
;; many Org commands, it will take some time to check them one-by-one
;; and filter out those that make sense with outshine (and fix them if
;; neccessary).
;;;;; Emacs Version
;; Outshine works with GNU Emacs 24 or later. No attempts of testing
;; with older versions or other types of Emacs have been made (yet).
;;;; ChangeLog
;; | date | author(s) | version |
;; |-----------------+-----------------+---------|
;; | <2014-09-20 Sa> | Thorsten Jolitz | 2.0 |
;; | <2013-05-03 Fr> | Thorsten Jolitz | 1.0 |
;; | <2013-02-20 Mi> | Thorsten Jolitz | 0.9 |
;;; Requires
(require 'outline)
(require 'outorg)
;; necessary before Emacs 24.3
(require 'newcomment)
;; (require 'easymenu)
;;; 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")
;;; Variables
;;;; Consts
(defconst outshine-version "2.0"
"outshine version number.")
(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-outline-heading-end-regexp "\n"
"Global default value of `outline-heading-end-regexp'.
Used to override any major-mode specific file-local settings")
;; was "[;]+"
(defconst outshine-oldschool-elisp-outline-regexp-base
(format "[;]\\{1,%d\\}" outshine-max-level)
"Oldschool Emacs Lisp base for calculating the 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" . outline-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)
)
"The default speed commands.")
(defconst outshine-comment-tag "comment"
"The tag that marks a subtree as comment.
A comment subtree does not open during visibility cycling.")
(defconst outshine-latex-documentclass-regexp
"^[[:space:]]*\\\\documentclass\\(?:\\[.+]\\)?{\\(.+\\)}"
"Regexp matching the document class in a latex doc (in submatch
1)")
;;;; Vars
;; "\C-c" conflicts with other modes like e.g. ESS
(defvar outline-minor-mode-prefix "\M-#"
"New outline-minor-mode prefix.
Does not really take effect when set in the `outshine' library.
Instead, it must be set in your init file *before* the `outline'
library is loaded, see the installation tips in the comment
section of `outshine'.")
;; from `outline-magic'
(defvar outline-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.")
(make-variable-buffer-local 'outline-promotion-headings)
(defvar outshine-delete-leading-whitespace-from-outline-regexp-base-p nil
"If non-nil, delete leading whitespace from outline-regexp-base.")
(make-variable-buffer-local
'outshine-delete-leading-whitespace-from-outline-regexp-base-p)
(defvar outshine-enforce-no-comment-padding-p nil
"If non-nil, make sure no comment-padding is used in heading.")
(make-variable-buffer-local
'outshine-enforce-no-comment-padding-p)
(defvar outshine-outline-regexp-base ""
"Actual base for calculating the outline-regexp")
(defvar outshine-normalized-comment-start ""
"Comment-start regexp without leading and trailing whitespace")
(make-variable-buffer-local
'outshine-normalized-comment-start)
(defvar outshine-normalized-comment-end ""
"Comment-end regexp without leading and trailing whitespace")
(make-variable-buffer-local
'outshine-normalized-comment-end)
(defvar outshine-normalized-outline-regexp-base ""
"Outline-regex-base without leading and trailing whitespace")
(make-variable-buffer-local
'outshine-normalized-outline-regexp-base)
;; 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 outshine-imenu-default-generic-expression nil
"Expression assigned by default to `imenu-generic-expression'.")
(make-variable-buffer-local
'outshine-imenu-default-generic-expression)
(defvar outshine-imenu-generic-expression nil
"Expression assigned to `imenu-generic-expression'.")
(make-variable-buffer-local
'outshine-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 outshine-use-outorg-last-headline-marker (make-marker)
"Marker for last headline edited with outorg.")
(make-variable-buffer-local
'outshine-use-outorg-last-headline-marker)
(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'")
;; copied and adapted from ob-core.el
(defvar outshine-temporary-directory)
(unless (or noninteractive (boundp 'outshine-temporary-directory))
;; FIXME why this duplication?
(defvar outshine-temporary-directory
(or (and (boundp 'outshine-temporary-directory)
(file-exists-p outshine-temporary-directory)
outshine-temporary-directory)
(make-temp-file "outshine-" t))
"Directory to hold outshine's temporary files.
This directory will be removed on Emacs shutdown."))
;;;; Hooks
(defvar outshine-hook nil
"Functions to run after `outshine' is loaded.")
;;;; Faces
;; from `org-compat.el'
(defun outshine-compatible-face (inherits specs)
"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))
(>= 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.
(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)))
(or (assoc (car e) r) (push e r)))
(t (or (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)
;;;; Customs
;;;;; Custom Groups
(defgroup outshine nil
"Enhanced library for outline navigation in source code buffers."
:prefix "outshine-"
:group 'lisp)
(defgroup outshine-faces nil
"Faces in Outshine."
:tag "Outshine Faces"
:group 'outshine)
;;;;; Custom Vars
(defcustom outshine-imenu-show-headlines-p t
"Non-nil means use calculated outline-regexp for imenu."
:group 'outshine
:type 'boolean)
;; 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-outline-regexp-outcommented-p t
"Non-nil if regexp-base is outcommented to calculate outline-regexp."
:group 'outshine
:type 'boolean)
;; was "[][+]"
(defcustom outshine-outline-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 outline-cycle-emulate-tab nil
"Where should `outline-cycle' emulate TAB.
nil Never
white Only in completely white lines
t Everywhere except in headlines"
:group 'outlines
:type '(choice (const :tag "Never" nil)
(const :tag "Only in completely white lines" white)
(const :tag "Everywhere except in headlines" t)
))
;; from `outline-magic'
(defcustom outline-structedit-modifiers '(meta)
"List of modifiers for outline structure editing with the arrow keys."
:group 'outlines
:type '(repeat symbol))
;; 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
(format "[%s]\\{1,%d\\}"
outshine-regexp-base-char outshine-max-level)
"Default base for calculating the outline-regexp")
;; TODO delete this line "\\(\\[\\)\\([[:digit:]+]\\)\\( L\\]\\)"
(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
"Cycle globally if cursor is at beginning of buffer and not at a headline.
This makes it possible to do global cycling without having to use
S-TAB or C-u TAB. For this special case to work, the first line
of the buffer must not be a headline -- it may be empty or some
other text. When this option is nil, don't do anything special at
the beginning of the buffer."
: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)
;;; Defuns
;;;; Advices
(defadvice org-store-log-note (around org-store-log-note-around activate)
"Outcomment inserted log-note in Outshine buffers."
(let ((outshine-log-note-beg-marker
;; stay before inserted text
(copy-marker org-log-note-marker nil))
(outshine-log-note-end-marker
;; stay after inserted text
(copy-marker org-log-note-marker t)))
ad-do-it
(unless (derived-mode-p 'org-mode 'org-agenda-mode)
(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)))
;;;; Functions
;;;;; Define keys with fallback
;; copied and adapted from Alexander Vorobiev
;; http://www.mail-archive.com/[email protected]/msg70648.html
(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."
`(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)