-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfolding.el
executable file
·5416 lines (4912 loc) · 210 KB
/
folding.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
;;; folding.el --- A folding-editor-like minor mode.
;; This file is not part of Emacs
;; Copyright (C) 2000-2010
;; Jari Aalto
;; Copyright (C) 1995, 1996, 1997, 1998, 1999
;; Jari Aalto, Anders Lindgren.
;; Copyright (C) 1994
;; Jari Aalto
;; Copyright (C) 1992, 1993
;; Jamie Lokier, All rights reserved.
;;
;; Author: Jamie Lokier <jamie A T imbolc.ucc dt ie>
;; Jari Aalto <jari aalto A T cante dt net>
;; Anders Lindgren <andersl A T csd.uu dt se>
;; Maintainer: Jari Aalto <jari aalto A T cante dt net>
;; Created: 1992
;; Keywords: tools
;;
;; [Latest XEmacs CVS tree commit and revision]
;; Vcs-Version: $Revision: 3.42 $
;; Vcs-Date: $Date: 2007/05/07 10:50:05 $
;;
;; [Latest devel version]
;; Vcs-URL: http://savannah.nongnu.org/projects/emacs-tiny-tools
(defconst folding-version-time "2010.0428.2238"
"Last edit time in format YYYY.MMDD.HHMM.")
;;{{{ GPL
;; 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,
;; or (at your option) any later version.
;;
;; GNU Emacs 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/>.
;;
;; Visit <http://www.gnu.org/copyleft/gpl.html> for more information
;;}}}
;;; Commentary:
;;{{{ Introduction
;; Preface
;;
;; This package provides a minor mode, compatible with all major
;; editing modes, for folding (hiding) parts of the edited text or
;; program.
;;
;; Folding mode handles a document as a tree, where each branch
;; is bounded by special markers `{{{' and `}}}'. A branch can be
;; placed inside another branch, creating a complete hierarchical
;; structure.
;;
;; Folding mode can CLOSE a fold, leaving only the initial `{{{'
;; and possibly a comment visible.
;;
;; It can also ENTER a fold, which means that only the current
;; fold will be visible, all text above `{{{' and below `}}}'
;; will be invisible.
;;
;; Please note, that the maintainers do not recommend to use only
;; folding for you your code layout and navigation. Folding.el is
;; on its best when it can "chunk" large sections of code inside
;; folds. The larger the chunks, the more the usability of
;; folding will increase. Folding.el is not meant to hide
;; individual functions: you may be better served by hideshow.el
;; or imenu.el (which can parse the function indexes)
;;}}}
;;{{{ Installation
;; Installation
;;
;; To install Folding mode, put this file (folding.el) on your
;; Emacs `load-path' (or extend the load path to include the
;; directory containing this file) and optionally byte compile it.
;;
;; The best way to install folding is the autoload installation,
;; so that folding is loaded into your emacs only when you turn on
;; `folding-mode'. This statement speeds up loading your .emacs
;;
;; (autoload 'folding-mode "folding" "Folding mode" t)
;; (autoload 'turn-off-folding-mode "folding" "Folding mode" t)
;; (autoload 'turn-on-folding-mode "folding" "Folding mode" t)
;;
;; But if you always use folding, then perhaps you want more
;; traditional installation. Here Folding mode starts
;; automatically when you load a folded file.
;;
;; ;; (setq folding-default-keys-function
;; ;; 'folding-bind-backward-compatible-keys)
;;
;; (if (load "folding" 'nomessage 'noerror)
;; (folding-mode-add-find-file-hook))
;;
;; Folding uses a keymap which conforms with the new Emacs
;; (started 19.29) style. The key bindings are prefixed with
;; "C-c@" instead of old "C-c". To use the old keyboard bindings,
;; uncomment the lines in the the above installation example
;;
;; The same folding marks can be used in `vim' editor command
;; "set fdm=marker".
;;
;; Uninstallation
;;
;; To remove folding, call `M-x' `folding-uninstall'.
;;
;; To read the manual
;;
;; At any point you can reach the manual with `M-x'
;; `finder-commentary' RET folding RET.
;;}}}
;;{{{ DOCUMENTATION
;; Compatibility
;;
;; Folding supports following Emacs flavors:
;;
;; Unix Emacs 19.28+ and Win32 Emacs 19.34+
;; Unix XEmacs 19.14+ and Win32 XEmacs 21.0+
;;
;; Compatibility not for old NT Emacs releases
;;
;; NOTE: folding version starting from 2.47 gets around this bug
;; by using adviced kill/yank functions. The advice functions are
;; only instantiated under problematic NT Emacs versions.
;;
;; Windows NT/9x 19.34 - 20.3.1 (i386-*-nt4.0) versions contained
;; a bug which affected using folding. At the time the bug was
;; reported by Trey Jackson <trey A T cs berkeley edu>
;;
;; If you kill folded area and yank it back, the ^M marks are
;; removed for some reason.
;;
;; Before kill
;; ;;{{{ fold...
;;
;; After yank
;; ;;{{{ fold all lines together }}}
;;
;; Relates packages or modes
;;
;; Folding.el was designed to be a content organizer and it is most
;; suitable for big files. Sometimes people misunderstand the
;; package's capabilities and try to use folding.el in wrong places,
;; where some other package would do a better job. Trying to wrap
;; individual functions inside fold-marks is not where folding is
;; it's best. Grouping several functions inside a logical fold-block
;; in the other is. So, to choose a best tool for your need,
;; here are some suggestions,:
;;
;; o Navigating between or hiding individual functions -
;; use combination of imenu.el, speedbar.el and
;; hideshow.el
;; o Organizing large blocks - use folding.el
;; o For text, `outline-mode' is more non-intrusive than folding.
;; Look at Emacs NEWS file (`C-x' `n') and you can see beatifully
;; laid content.
;;
;; Tutorial
;;
;; To start folding mode, give the command: `M-x' `folding-mode'
;; `RET'. The mode line should contain the string "Fld" indicating
;; that folding mode is activated.
;;
;; When loading a document containing fold marks, Folding mode is
;; automatically started and all folds are closed. For example when
;; loading my init file, only the following lines (plus a few lines
;; of comments) are visible:
;;
;; ;;{{{ General...
;; ;;{{{ Keyboard...
;; ;;{{{ Packages...
;; ;;{{{ Major modes...
;; ;;{{{ Minor modes...
;; ;;{{{ Debug...
;;
;; To enter a fold, use `C-c @ >'. To show it without entering,
;; use `C-c @ C-s', which produces this display:
;;
;; ;;{{{ Minor modes
;;
;; ;;{{{ Follow mode...
;; ;;{{{ Font-lock mode...
;; ;;{{{ Folding...
;;
;; ;;}}}
;;
;; To show everything, just as the file would look like if
;; Folding mode hadn't been activated, give the command `M-x'
;; `folding-open-buffer' `RET', normally bound to `C-c' `@'
;; `C-o'. To close all folds and go to the top level, the
;; command `folding-whole-buffer' could be used.
;;
;; Mouse support
;;
;; Folding mode v2.0 introduced mouse support. Folds can be shown
;; or hidden by simply clicking on a fold mark using mouse button
;; 3. The mouse routines have been designed to call the original
;; function bound to button 3 when the user didn't click on a
;; fold mark.
;;
;; The menu
;;
;; A menu is placed in the "Tools" menu. Should no Tools menu exist
;; (Emacs 19.28) the menu will be placed in the menu bar.
;;
;; ISearch
;;
;; When searching using the incremental search (C-s) facilities,
;; folds will be automagically entered and closed.
;;
;; Problems
;;
;; Uneven fold marks
;;
;; Oops, I just deleted some text, and a fold mark got deleted!
;; What should I do? Trust me, you will eventually do this
;; sometime. the easiest way is to open the buffer using
;; `folding-open-buffer' (C-c @ C-o) and add the fold mark by
;; hand. To find mismatching fold marks, the package `occur' is
;; useful. The command:
;;
;; M-x occur RET {{{\|}}} RET
;;
;; will extract all lines containing folding marks and present
;; them in a separate buffer.
;;
;; Even though all folding marks are correct, Folding mode
;; sometimes gets confused, especially when entering and leaving
;; folds very often. To get it back on track, press C-g a few
;; times and give the command `folding-open-buffer' (C-c @ C-o).
;;
;; Fold must have a label
;;
;; When you make a fold, be sure to write some text for the name
;; of the fold, otherwise there may be an error "extraneous fold
;; mark..." Write like this:
;;
;; ;;{{{ Note
;; ;;}}}
;;
;; instead of
;;
;; ;;{{{
;; ;;}}}
;;
;; folding-whole-buffer doesn't fold whole buffer
;;
;; If you call commands `folding-open-buffer' and
;; `folding-whole-buffer' and notice that there are open fold
;; sections in the buffer, then you have mismatch of folds
;; somewhere. Run ` M-x' `occur' and type regexp `{{{\|}}}' to
;; check where is the extra open or closing fold mark.
;;
;; Folding and outline modes
;;
;; Folding mode is not the same as Outline mode, a major and
;; minor mode which is part of the Emacs distribution. The two
;; packages do, however, resemble each other very much. The main
;; differences between the two packages are:
;;
;; o Folding mode uses explicit marks, `{{{' and `}}}', to
;; mark the beginning and the end of a branch.
;; Outline, on the other other hand, tries to use already
;; existing marks, like the `\section' string in a TeX
;; document.
;;
;; o Outline mode has no end marker which means that it is
;; impossible for text to follow a sub-branch.
;;
;; o Folding mode use the same markers for branches on all depths,
;; Outline mode requires that marks should be longer the
;; further, down in the tree you go, e.g `\chap', \section',
;; `\subsection', `\subsubsection'. This is needed to
;; distinguish the next mark at the current or higher levels
;; from a sub-branch, a problem caused by the lack of
;; end-markers.
;;
;; o Folding mode has mouse support, you can navigate through a
;; folded document by clicking on fold marks. (The XEmacs version
;; of Outline mode has mouse support.)
;;
;; o The Isearch facilities of Folding is capable of
;; automatically to open folds. Under Outline, the the entire
;; document must be opened prior isearch.
;;
;; In conclusion, Outline mode is useful when the document being
;; edited contains natural markers, like LaTeX. When writing code
;; natural markers are hard to find, except if you're happy with
;; one function per fold.
;;
;; Future development ideas
;;
;; The plan was from the beginning to rewrite the entire package.
;; Including replacing the core of the program, written using
;; old Emacs technology (selective display), and replace it with
;; modern equivalences, like overlays or text-properties for
;; Emacs and extents for XEmacs.
;;
;; It is not likely that any of this will come true considering
;; the time required to rewrite the core of the package. Since
;; the package, in it's current state, is much more powerful than
;; the original, it would be appropriate to write such package
;; from scratch instead of doing surgery on this one.
;;}}}
;;{{{ Customization
;; Customization: general
;;
;; The behavior of Folding mode is controlled mainly by a set of
;; Emacs Lisp variables. This section will discuss the most
;; useful ones, for more details please see the code. The
;; descriptions below assumes that you know a bit about how to
;; use simple Emacs Lisp and knows how to edit ~/.emacs, your
;; init file.
;;
;; Customization: hooks
;;
;; The normal procedure when customizing a package is to write a
;; function doing the customization. The function is then added
;; to a hook which is called at an appropriate time. (Please see
;; the example section below.) The following hooks are
;; available:
;;
;; o `folding-mode-hook'
;; Called when folding mode is activated.
;; o `<major mode>-folding-hook'
;; Called when starting folding mode in a buffer with major
;; mode set to <major mode>. (e.g. When editing C code
;; the hook `c-mode-folding-hook' is called.)
;; o `folding-load-hook'
;; Called when folding mode is loaded into Emacs.
;;
;; Customization: The Mouse
;;
;; The variable `folding-behave-table' contains the actions which
;; should be performed when the user clicks on an open fold, a
;; closed fold etc. For example, if you prefer to `enter' a fold
;; rather than `open' it you should rebind this variable.
;;
;; The variable `folding-default-mouse-keys-function' contains
;; the name of the function used to bind your mouse keys. To use
;; your own mouse bindings, create a function, say
;; `my-folding-bind-mouse', and set this variable to it.
;;
;; Customization: Keymaps
;;
;; When Emacs 19.29 was released, the keymap was divided into
;; strict parts. (This division existed before, but a lot of
;; packages, even the ones delivered with Emacs, ignored them.)
;;
;; C-c <letter> -- Reserved for the users private keymap.
;; C-c C-<letter> -- Major mode. (Some other keys are
;; reserved as well.)
;; C-c <Punctuation Char> <Whatever>
;; -- Reserved for minor modes.
;;
;; The reason why `C-c@' was chosen as the default prefix is that
;; it is used by outline-minor-mode. It is not likely that few
;; people will try to use folding and outline at the same time.
;;
;; However, old key bindings have been kept if possible. The
;; variable `folding-default-keys-function' specifies which
;; function should be called to bind the keys. There are various
;; function to choose from how user can select the keybindings.
;; To use the old key bindings, add the following line to your
;; init file:
;;
;; (setq folding-default-keys-function
;; 'folding-bind-backward-compatible-keys)
;;
;; To define keys similar to the keys used by Outline mode, use:
;;
;; (setq folding-default-keys-function
;; 'folding-bind-outline-compatible-keys)
;;
;; Customization: adding new major modes
;;
;; To add fold marks for a new major mode, use the function
;; `folding-add-to-marks-list'. The command also replaces
;; existing marks. An example:
;;
;; (folding-add-to-marks-list
;; 'c-mode "/* {{{ " "/* }}} */" " */" t)
;;
;; Customization: ISearch
;;
;; If you don't like the extension folding.el applies to isearch,
;; set the variable `folding-isearch-install' to nil before
;; loading this package.
;;}}}
;;{{{ Examples
;; Example: personal setup
;;
;; To define your own key binding instead of using the standard
;; ones, you can do like this:
;;
;; (setq folding-mode-prefix-key "\C-c")
;; ;;
;; (setq folding-default-keys-function
;; '(folding-bind-backward-compatible-keys))
;; ;;
;; (setq folding-load-hook 'my-folding-load-hook)
;;
;;
;; (defun my-folding-load-hook ()
;; "Folding setup."
;;
;; (folding-install) ;; just to be sure
;;
;; ;; ............................................... markers ...
;;
;; ;; Change text-mode fold marks. Handy for quick
;; ;; sh/perl/awk code
;;
;; (defvar folding-mode-marks-alist nil)
;;
;; (let* ((ptr (assq 'text-mode folding-mode-marks-alist)))
;; (setcdr ptr (list "# {{{" "# }}}")))
;;
;; ;; ........................................ bindings ...
;;
;; ;; Put `folding-whole-buffer' and `folding-open-buffer'
;; ;; close together.
;;
;; (defvar folding-mode-prefix-map nil)
;;
;; (define-key folding-mode-prefix-map "\C-w" nil)
;; (define-key folding-mode-prefix-map "\C-s"
;; 'folding-show-current-entry)
;; (define-key folding-mode-prefix-map "\C-p"
;; 'folding-whole-buffer))
;;
;; Example: changing default fold marks
;;
;; In case you're not happy with the default folding marks, you
;; can change them easily. Here is an example
;;
;; (setq folding-load-hook 'my-folding-load-hook)
;;
;; (defun my-folding-load-hook ()
;; "Folding vars setup."
;; ;; Change marks for 'text-mode'
;; (let* ((ptr (assq 'text-mode folding-mode-marks-alist)))
;; (setcdr ptr (list "# {{{" "# }}}"))))
;;
;; Example: choosing different fold marks for mode
;;
;; Suppose you sometimes want to use different fold marks for the
;; major mode: e.g. to alternate between "# {{{" and "{{{" in
;; `text-mode' Call `M-x' `my-folding-text-mode-setup' to change
;; the marks.
;;
;; (defun my-folding-text-mode-setup (&optional use-custom-folding-marks)
;; (interactive
;; (list (y-or-n-p "Use Custom fold marks now? ")))
;; (let* ((ptr (assq major-mode folding-mode-marks-alist))
;; (default-begin "# {{{")
;; (default-end "# }}}")
;; (begin "{{{")
;; (end "}}}"))
;; (when (eq major-mode 'text-mode)
;; (unless use-custom-folding-marks
;; (setq begin default-begin end default-end)))
;; (setcdr ptr (list begin end))
;; (folding-set-marks begin end)))
;;
;; Example: AucTex setup
;;
;; Suppose you're using comment.sty with AucTeX for editing
;; LaTeX2e documents and you have these comment types. You would
;; like to be able to set which of these 3 is to be folded at any
;; one time, using a simple key sequence: move back and forth
;; easily between the different comment types, e.g., "unfold
;; everything then fold on \x".
;;
;; \O ... \endO
;; \L ... \endL
;; \B ... \endB
;;
;; (setq folding-load-hook 'my-folding-load-hook)
;;
;; (defun my-folding-load-hook ()
;; "Folding vars setup."
;; (let ((ptr (assq 'text-mode folding-mode-marks-alist)))
;; (setcdr ptr (list "\\O" "\\endO"))
;; (define-key folding-mode-prefix-map "C"
;; 'my-folding-marks-change)))
;;
;; (defun my-folding-marks-change (&optional selection)
;; "Select folding marks: prefixes nil, C-u and C-u C-u."
;; (interactive "P")
;; (let ((ptr (assq major-mode folding-mode-marks-alist))
;; input)
;; (when (string-match "^\\(plain-\\|la\\|auc\\)?tex-"
;; (symbol-name major-mode))
;; (setq input
;; (read-string "Latex \\end(X) Marker (default O): "
;; nil nil "O" nil))
;; (setq input (upcase input))
;; (turn-off-folding-mode)
;; (folding-add-to-marks-list
;; major-mode
;; (concat "\\" input) (concat "\\end" input) nil nil t)
;; ;; (setcdr ptr (list (concat "\\" input) (concat "\\end" input)))
;; (turn-on-folding-mode))))
;; ;; End of example
;;
;; Bugs: Lazy-shot.el conflict in XEmacs
;;
;; [XEmacs 20.4 lazy-shot-mode]
;; 1998-05-28 Reported by Solofo Ramangalahy <solofo A T mpi-sb mpg de>
;;
;; % xemacs -q folding.el
;; M-x eval-buffer
;; M-x folding-mode
;; M-x font-lock-mode
;; M-x lazy-shot-mode
;; C-s mouse
;;
;; then search for mouse again and again. At some point you will
;; see "Deleting extent" in the minibuffer and XEmacs freezes.
;;
;; The strange point is that I have this bug only under Solaris
;; 2.5 sparc (binaries from ftp.xemacs.org) but not under Solaris
;; 2.6 x86. (XEmacs 20.4, folding 2.35). I will try to access
;; more machines to see if it's the same.
;;
;; I suspect that the culprit is lazy-shot as it is beta, but
;; maybe you will be able to describe the bug more precisely to
;; the XEmacs people I you can reproduce it.
;;}}}
;;{{{ Old Documentation
;; Old documentation
;;
;; The following text was written by Jamie Lokier for the release
;; of Folding V1.6. It is included here for no particular reason:
;;
;; Emacs 18:
;; Folding mode has been tested with versions 18.55 and
;; 18.58 of Emacs.
;;
;; Epoch:
;; Folding mode has been tested on Epoch 4.0p2.
;;
;; [X]Emacs:
;; There is code in here to handle some aspects of XEmacs.
;; However, up to version 19.6, there appears to be no way to
;; display folds. Selective-display does not work, and neither do
;; invisible extents, so Folding mode has no chance of
;; working. This is likely to change in future versions of
;; XEmacs.
;;
;; Emacs 19:
;; Tested on version 19.8, appears to be fine. Minor bug:
;; display the buffer in several different frames, then move in
;; and out of folds in the buffer. The frames are automatically
;; moved to the top of the stacking order.
;;
;; Some of the code is quite horrible, generally in order to
;; avoid some Emacs display "features". Some of it is specific to
;; certain versions of Emacs. By the time Emacs 19 is around and
;; everyone is using it, hopefully most of it won't be necessary.
;;
;; More known bugs
;;
;; *** Needs folding-fold-region to be more intelligent about
;; finding a good region. Check folding a whole current fold.
;;
;; *** Now works with 19! But check out what happens when you
;; exit a fold with the file displayed in two frames. Both
;; windows get fronted. Better fix that sometime.
;;
;; Future features
;;
;; *** I will add a `folding-next-error' sometime. It will only
;; work with Emacs versions later than 18.58, because compile.el
;; in earlier versions does not count line-numbers in the right
;; way, when selective display is active.
;;
;; *** Fold titles should be optionally allowed on the closing
;; fold marks, and `folding-tidy-inside' should check that the
;; opening title matches the closing title.
;;
;; *** `folded-file' set in the local variables at the end of a
;; file could encode the type of fold marks used in that file,
;; and other things, like the margins inside folds.
;;
;; *** I can see a lot of use for the newer features of Emacs 19:
;;
;; Using invisible text-properties (I hope they are intended to
;; make text invisible; it isn't implemented like that yet), it
;; will be possible to hide folded text without affecting the
;; text of the buffer. At the moment, Folding mode uses selective
;; display to hide text, which involves substituting
;; carriage-returns for line-feeds in the buffer. This isn't such
;; a good way. It may also be possible to display different folds
;; in different windows in Emacs 19.
;;
;; Using even more text-properties, it may be possible to track
;; pointer movements in and out of folds, and have Folding mode
;; automatically enter or exit folds as necessary to maintain a
;; sensible display. Because the text itself is not modified (if
;; overlays are used to hide text), this is quite safe. It would
;; make it unnecessary to provide functions like
;; `folding-forward-char', `folding-goto-line' or
;; `folding-next-error', and things like I-search would
;; automatically move in and out of folds as necessary.
;;
;; Yet more text-properties/overlays might make it possible to
;; avoid using narrowing. This might allow some major modes to
;; indent text properly, e.g., C++ mode.
;;}}}
;;; Change Log:
;;{{{ History
;; [person version] = developer and his revision tree number.
;;
;; Sep 20 2009 23.1 [jari git a80c2d6]
;; - Remove 'defmacro custom' for very old Emacs version that did
;; not have custom.
;; - Modernize all macros to use new backquote syntax,
;; - Move `folding-narrow-by-default' variable
;; definition before `folding-advice-instantiate' which
;; refers to it.
;;
;; Feb 20 2009 22.2.1 [jari git 51ada03..56b3089]
;; - Make XEmacs CVS and Savannah git revisions at header more clear
;; - Unify html-mode folds as in other modes: change [[[ ]]] to {{{ }}}
;;
;; Feb 09 2009 22.2.1 [jari git e0c2e92..6a3cff7]
;; - Minor documentaton fixes.
;; - Add new `python-mode' using `folding-add-to-marks-list'.
;; - Add new variable `folding-version-time' to record edit time.
;; Value is automatically updated by developer's Emacs setup.
;;
;; May 06 2007 21.4 [jari 3.38-3.41 2007.0506]
;; - Cleanup. Eol whitespaces removed, extra newlines cleaned.
;; Paren positions corrected.
;; - 'Personal reflections by Anders Lindgren' topic
;; rephrased 'Future development ideas'
;; - (folding-show-current-entry): Run `font-lock-fontify-region'
;; after opening the fold. Font-lock.el treated all closed folds
;; as comments.
;;
;; Nov 16 2006 21.4 [jari 3.36-3.37 2006.1118]
;; - Jeremy Hankins <nowan A T nowan org> sent a patch, which
;; adds variable `folding-narrow-by-default'. The patch affects
;; mostly `folding-shift-in'. This makes it possible to
;; advise viper-search to open folds. Thanks.
;; - Added VCS URL header to the beginning for canonnical location.
;; Updated maintainer section.
;; - Fixed Copyright years.
;;
;; Nov 25 2004 21.3 [jari 3.35 2004.1125]
;; - non-ascii character removed from bibtex-mode.
;; Changed bib-mode '@comment' => '%'. Closes Debian
;; Bug#282388
;;
;; Sep 10 2004 21.3 [jari 2.116 2004.0910]
;; - (folding-fold-region): caused to indent bottom fold
;; some 50 spaces forward in auctex:latex-mode. Disabled
;; running `indent-according-to-mode' while in latex-mode.
;; Bug reported by Uwe Brauer; oub A T mat dot ucm dot es
;; - Removed extra newlines from whole buffer.
;; - Changed version scheme to date based YYYY.MMDD
;; - Removed unnecessary 'all rights reserved'.
;; - (folding-check-folded): Added check for \r character, which
;; - protected all email addresses by removing AT-signs.
;;
;; Apr 01 2004 21.3 [jari 2.111-2.115]
;; - Merged in changes made by 2003-11-12 Adrian Aichner
;; from XEmacs tree 1.15; Typo fixes for docstrings and comments.
;; - Returned to old bug and solved it in a better way (preserve region) by
;; using different expansion macros for XEmacs and Emacs.
;; See See http://list-archive.xemacs.org/xemacs-beta/199810/msg00039.html
;; - (folding-forward-char-1): 2.112 Renamed.
;; Was `folding-forward-char'.
;; (folding-backward-char-1): 2.112 Renamed.
;; Was `folding-backward-char'.
;; (folding-forward-char-macro): 2.112 New. Fix XEmacs
;; region preservation with '_p' interactive spec.
;; (folding-backward-char-macro): 2.112 New. Fix XEmacs
;; region preservation with '_p' interactive spec.
;; (folding-interactive-spec-p): 2.112 New.
;;
;; Sep 11 2003 21.2 [jari 2.107-2.111]
;; - Added new sections "Uninstallation" and "To read the manual".
;; M-x finder can invoke folding too provided that patch to
;; lisp-mnt.el and finder.el is installed. Sent patch to XEmacs and
;; Emacs developers.
;; - Moved fold-mark ";;{{{ Introduction" after the Commentary:
;; tag to have it included in M-x finder-commentary.
;; - If called like this: `folding-uninstall' and immediately
;; `folding-mode', the keybindings were not there any more. Added
;; call to `folding-install' in `folding-mode'.
;; - Completely rewrote `folding-install'. It's now divided into
;; `folding-install-keymaps' and `folding-uninstall-keymaps'
;; - Added support for `php-mode', `javascript-mode',
;; `change-log-mode' and `finder-mode'.
;; - Documentation changes (fit all to 80 characters).
;;
;; Aug 21 2002 21.2 [jari 2.105-2.106]
;; - Added user function `folding-uninstall'.
;; - Removed `interactive' status: `folding-install-hooks' and
;; `folding-uninstall-hooks'
;;
;; Aug 02 2002 20.7 [jari 2.101-2.104]
;; - Added font lock support. Now beginning and end markers are
;; highlighted with user variables `folding-font-lock-begin-mark'
;; `folding-font-lock-end-mark'. Feature suggested by
;; <Claude BOUCHER A T astrium-space com>
;; - Removed LCD entry - unnecessary.
;;
;; Jan 24 2002 20.7 [jari 2.100]
;; - (folding-context-next-action):New user function.
;; Code by Scott Evans <gse A T antisleep com>
;; - (folding-bind-default-keys): Added
;; C-x . to run `folding-context-next-action'
;; - (folding-mouse-call-original): Added `car-safe' to read
;; EVENT, which may be nil.
;;
;; Jul 31 2001 20.7 [jari 2.98-2.99]
;; - Gleb Arshinov <gleb A T barsook com> fixed the broken XEmacs
;; isearch support and sent nice patch.
;;
;; Jul 19 2001 20.7 [jari 2.92-2.97]
;; - Beautified lisp code by removing parens that were alone.
;; - XEmacs latex-mode fix. The folds were strangely indented too
;; far right. The cause was `indent-according-to-mode' which is
;; now disabled in latex. bug reported by
;; Uwe Brauer; oub A T maraton sim ucm es
;; - 2.96 Erroneous `:' in `folding-mode-write-file'
;; when it should have been `;'. Bug reported by
;; Brand Michael; michael brand A T siemens com
;;
;; Apr 04 2001 20.7 [jari 2.89-2.91]
;; - Small corrections to find-func.el::find-function-search-for-symbol
;; implementation.
;;
;; Mar 08 2001 20.6 [jari 2.88]
;; - Dave Masterson <dmasters A T rational com> reported that jumping to a
;; url displayed by the C-h f FUNCTION which told where the function
;; was located died. The reason was that the buffer was folded and
;; find-func.el::find-function-search-for-symbol used regexps that
;; do not take into account folded buffers. The regexps used there
;; rely on syntax tables.
;; - Added two new advices to catch find-func.el and unfold the buffer
;; prior searching: (advice find-file-noselect after) and (advice
;; find-function-search-for-symbol around)
;;
;; Mar 04 2001 20.6 [jari 2.83-2.87]
;; - Added ###autoload statements, tidied up empty lines and lisp syntax.
;; - Run checkdoc.el 0.6.1 and corrected errors.
;;
;; Jan 04 2001 20.6 [jari 2.82]
;; - Added FOLD highlight feature for XEmacs:
;; `folding-mode-motion-highlight-fold'
;; and package `mode-motion' Suggested by
;; Thomas Ruhnau <thomas ruhnau A T intermetall de>
;; - (folding-bind-default-keys): 2.81 New binding C-k
;; `folding-marks-kill'
;; (fold-marks-kill): 2.81 New.
;;
;; Jan 03 2001 20.6 [jari 2.81]
;; - (folding-folding-region): 2.80 Renamed to `folding-fold-region'
;; - (folding-mark-look-at-top-mark-p): 2.80 New.
;; - (folding-mark-look-at-bottom-mark-p): 2.80 New.
;; - (folding-tidy-inside): 2.80 Use `folding-mark-look-at-top-mark-p'
;; and `folding-mark-look-at-bottom-mark-p'.
;; - Didn't accept spaces in front of fold markers.
;; - (folding-fold-region): 2.80 Added `indent-according-to-mode'
;; to indent folds as needed.
;;
;; Dec 16 2000 20.6 [jari 2.79-2.80]
;; - `folding-xemacs-p' now test (featurep 'xemacs)
;; - Added missing folding functions to the menubar
;; - `folding-package-url-location' new variable used by function
;; `folding-insert-advertise-folding-mode'
;; - `folding-keep-hooked' was commented out in `folding-mode'. Added
;; back.
;;
;; Jul 25 2000 20.6 [jari 2.76-2.78]
;; - 2.75 Added support for modes:
;; xrdb-mode, ksh-mode and sql-mode contributed by
;; Juhapekka Tolvanen <juhtolv A T st jyu fi>. Scanned systematically
;; all modes under Emacs 20.6 progmodes and added support for:
;; ada-mode, asm-mode, awk-mode, cperl-mode, fortran-mode, f90-mode,
;; icon-mode, m4-mode, meta-mode, pascal-mode, prolog-mode,
;; simula-mode, vhdl-mode, bibtex-mode, nroff-mode, scribe-mode(*),
;; sgml-mode
;; - Mode marked with (*) was not added.
;; - (folding-insert-advertise-folding-mode): 2.76 New. Suggested by
;; Juhapekka Tolvanen <juhtolv A T st jyu fi>
;; - (folding-bind-default-keys): 2.76
;; folding-insert-advertise-folding-mode Bound to key "I"
;;
;; Apr 24 1999 20.4 [jari 2.73-2.75]
;; - (folding-bind-terminal-keys): 2.74 New. Bind C-f and C-b only at
;; non-window system where they are really needed. Someone may use
;; C-f for `isearch-forward' in windowed Emacs.
;; - (folding-bind-default-keys): 2.74 Use `folding-bind-terminal-keys'
;; - (folding-bind-outline-compatible-keys): 2.74
;; Use `folding-bind-terminal-keys'
;;
;; Feb 13 1999 20.4 [jari 2.71-2.72]
;; - (folding-event-posn): 2.70 Wrong
;; place of paren and the following was malformed call:
;; (let* ((el (funcall (symbol-function 'event-start) event)))
;;
;; Jan 13 1999 20.4 [jari 2.70]
;; - 2.69 The `looking-at' is now smarter with
;; fold beginning marks. The tradition has been the the fold always
;; has a name, so the requirement to search fold is "{{{ ". Now
;; the " " is searched as " *", not requiring a space --> not requiring
;; a fold name.
;; - (folding-skip-folds): >>feature not not enabled<<
;; 2.69 Do not require trailing " " any more.'
;; (folding-tidy-inside): >>feature not not enabled<<
;; 2.69 Do not require trailing " " any more.
;; - (folding-install): 2.69 Fixed indentation.
;; - (folding-mark-look-at): 2.69 The "em" missed "*" and thus pressing
;; mouse-3 at the end-fold didn't collapse the whole fold.
;;
;; Jan 12 1999 20.4 [jari 2.69]
;; (folding-bind-default-mouse): 2.68
;; XEmacs and Emacs Mouse binding was different. Now use common
;; bindings: The S-mouse-2 was superfluous, because mouse-3 already
;; did that, so the binding was removed.
;; mouse-3 folding-mouse-context-sensitive
;; S-mouse-2 folding-hide-current-entry
;; C-S-mouse-2 folding-mouse-pick-move
;;
;;;; Jan 09 1999 20.4 [jari 2.67-2.68]
;; - (folding-event-posn): 2.66 Hide `event-start' From XEmacs
;; (byte compile silencer)
;;
;; Jan 07 1999 20.4 [jari 2.65-2.66]
;; - The Folding begin and AND mark was not case sensitive;
;; that's why a latex styles "\B" and "\endB" fold marks couldn't
;; be used. Added relevant `case-fold-search' settings. Not tested
;; very well, though.
;; - Added standard "turn-on" "turn-off" functions.
;; - (folding-whole-buffer): 2.65 Better
;; Error message. Show used folding-mark on error.
;; - (folding-skip-folds): 2.65 Moved docs in function.
;; - (turn-off-folding-mode): 2.65 New.
;; - (turn-on-folding-mode): 2.65 New.
;; - (folding-mark-look-at): 2.65 `case-fold-search'
;; - (folding-next-visible-heading): 2.65 `case-fold-search'
;; - (folding-find-folding-mark): 2.65 `case-fold-search'
;; - (folding-pick-move): 2.65 `case-fold-search'
;; - (folding-skip-folds): 2.65 `case-fold-search'
;; - (folding-tidy-inside): 2.65 `case-fold-search'
;; - (folding-convert-to-major-folds): 2.65 `case-fold-search'
;;
;; Jan 04 1999 20.4 [jari 2.62-2.64]
;; - (folding-set-local-variables): 2.61 New. Now it is possible to
;; change the folding marks dynamically.
;; - (folding-mode): 2.61 Call `folding-set-local-variables'
;; (folding-mode-marks-alist): 2.61 mention
;; - `folding-set-local-variables'
;; Added documentation section: "Example: AucTex setup"
;; - NT Emacs fix wrapped inside `eval-and-compile'. hs-discard-overlays
;; are now hidden from byte compiler (since the code is not
;; executed anyway)
;;
;; May 24 1999 19.34 [jari 2.59-2.61]
;; - New function `folding-all-comment-blocks-in-region'. Requested by
;; Uwe Brauer <oub A T eucmos sim ucm es>. Bound under "/" key.
;; - (folding-all-comment-blocks-in-region):
;; Check non-whitespace `comment-end'. Added `matlab-mode' to
;; fold list
;; - (folding-event-posn): 2.63 Got rid of the XEmacs/Emacs
;; posn-/event- byte compiler warnings
;; - (folding-mouse-call-original): 2.63 Got rid of the XEmacs
;; `event-button' byte compiler warning.
;;
;; Apr 15 1999 19.34 [jari 2.57]
;; - (folding-mouse-call-original): Samuel Mikes
;; <smikes A T alumni hmc edu> reported that the `concat' function was
;; used to add an integer to "button" event. Applied patch to use
;; `format' instead.
;;
;; Mar 03 1999 19.34 [andersl]
;; - (folding-install): had extra paren. Removed.
;;
;; Feb 22 1999 19.34 [jari 2.56]
;; - folding-install):
;; Check if `folding-mode-prefix-map' is nil and call
;;
;; Feb 19 1999 19.34 [jari 2.55]
;; - (folding-mode-hook-no-re):
;; Renamed to `folding-mode-hook-no-regexp'
;; - (fold-inside-mode-name): Renames to `folding-inside-mode-name'
;; (fold-mode-string): Renamed to `folding-mode-string'
;; - Renamed all `fold-' prefixes to `folding-'
;; - Rewrote chapter `Example: personal setup'
;;
;; Jan 01 1999 19.34 [jari 2.54]
;; - Byte compiler error fix: (folding-bind-outline-compatible-keys):
;; 'folding-show-all lacked the quote.
;;
;; Dec 30 1998 19.34 [jari 2.53]
;; - Jesper Pedersen <blackie A T imada ou dk> reported bug that hiding
;; subtree was broken. This turned out to be a bigger problem in fold
;; handling in general. This release has big relatively big error
;; fixes.
;; - Many of the folding functions were also renamed to mimic Emacs 20.3
;; allout.el names. Outline keybindings were rewritten too.
;; - folding.el (folding-mouse-yank-at-point): Renamed from
;; `folding-mouse-operate-at-point'. The name is similar to Emacs
;; standard variable name. The default value changed from nil --> t
;; according to suggestion by Jesper Pedersen <blackie A T imada ou dk>
;; Message "Info, Ignore [X]Emacs specific..." is now displayed only
;; while byte compiling file.
;; (folding-bind-outline-compatible-keys):
;; Checked the Emacs 20.3 allout.el outline bindings and made
;; folding mimic them
;; (folding-show-subtree): Renamed to `folding-show-current-subtree'
;; according to allout.el
;; (folding-hide-subtree): Renamed to `folding-hide-current-subtree'
;; according to allout.el
;; (folding-enter): Renamed to `folding-shift-in'
;; according to allout.el
;; (folding-exit): Renamed to `folding-shift-out'
;; according to allout.el
;; (folding-move-up): Renamed to `folding-previous-visible-heading'
;; according to allout.el
;; (folding-move): Renamed to `folding-next-visible-heading'
;; according to allout.el
;; (folding-top-level): Renamed to `folding-show-all'
;; according to allout.el
;; (folding-show): Renamed to `folding-show-current-entry'
;; according to allout.el
;; (folding-hide): Renamed to `folding-hide-current-entry'
;; according to allout.el
;; (folding-region-open-close): While loop rewritten so that if user
;; is already on a fold mark, then close current fold. This also
;; fixed the show/hide subtree problem.
;; (folding-hide-current-subtree): If use hide subtree that only had
;; one fold, then calling this function caused error. The reason was
;; error in `folding-pick-move' (folding-pick-move): Test that
;; `moved' variable is integer and only then move point. This is the
;; status indicator from `folding-find-folding-mark'
;; (folding-find-folding-mark): Fixed. mistakenly moved point when
;; checking TOP level marker, status 11. the point was permanently
;; moved to point-min.
;;
;; Dec 29 1998 19.34 [jari 2.51]
;; - Jesper Pedersen <blackie A T imada ou dk> reported that prefix key
;; cannot take vector notation [(key)]. This required changing the way
;; how folding maps the keys. Now uses intermediate keymap
;; `folding-mode-prefix-map'
;; - `folding-kbd' is new.
;; - `folding-mode' function description has better layout.
;; - `folding-get-mode-marks' is now defsubst.
;;
;; Dec 13 1998 19.34 [jari 2.49-2.50]
;; - Gleb Arshinov <gleb A T CS Stanford EDU> reported that the XEmacs 21.0
;; `concat' function won't accept integer argument any more and
;; provided patch for `folding-set-mode-line'.
;;
;; Nov 28 1998 19.34 [jari 2.49-2.50]
;; - Gleb Arshinov <gleb A T CS Stanford EDU> reported that the
;; zmacs-region-stays must not be set globally but in the functions
;; that need it. He tested the change on tested on XEmacs 21.0 beta
;; and FSF Emacs 19.34.6 on NT and sent a patch . Thank you.
;; - (folding-preserve-active-region): New macro to set
;; `zmacs-region-stays' to t in XEmacs.
;; - (folding-forward-char): Use `folding-preserve-active-region'
;; - (folding-backward-char): Use `folding-preserve-active-region'
;; - (folding-end-of-line): Use `folding-preserve-active-region'
;; - (folding-isearch-general): Variables `is-fold' and
;; `is narrowed' removed, because they were not used. (Byte
;; Compilation fix)
;; - Later: interestingly using `defmacro'
;; folding-preserve-active-region does not work in XEmacs 21.0 beta,