38436
|
1 ;;; elide-head.el --- hide headers in files
|
26151
|
2
|
74439
|
3 ;; Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005,
|
75347
|
4 ;; 2006, 2007 Free Software Foundation, Inc.
|
26151
|
5
|
|
6 ;; Author: Dave Love <fx@gnu.org>
|
|
7 ;; Keywords: outlines tools
|
|
8
|
|
9 ;; This file is part of GNU Emacs.
|
|
10
|
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
12 ;; it under the terms of the GNU General Public License as published by
|
78236
|
13 ;; the Free Software Foundation; either version 3, or (at your option)
|
26151
|
14 ;; any later version.
|
|
15
|
|
16 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
19 ;; GNU General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
|
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
|
64091
|
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
24 ;; Boston, MA 02110-1301, USA.
|
26151
|
25
|
|
26 ;;; Commentary:
|
|
27
|
|
28 ;; Functionality for eliding boilerplate text (normally copyright
|
|
29 ;; notices) in file headers to avoid clutter when you know what it
|
|
30 ;; says.
|
|
31 ;;
|
|
32 ;; `elide-head-headers-to-hide' controls what is elided by the command
|
|
33 ;; `elide-head'. A buffer-local invisible overlay manages the
|
|
34 ;; elision.
|
|
35
|
26700
|
36 ;; You might add `elide-head' to appropriate major mode hooks or to
|
46899
|
37 ;; `find-file-hook'. Please do not do this in site init files. If
|
26703
|
38 ;; you do, information may be hidden from users who don't know it
|
|
39 ;; already.
|
26151
|
40
|
26925
|
41 ;; Note that `hs-minor-mode' will do a similar job by default, but
|
|
42 ;; it's not selective about what leading commentary it hides.
|
|
43
|
26151
|
44 ;; Inspired by jwz's hide-copyleft.el, for which we don't have an
|
|
45 ;; assignment.
|
|
46
|
|
47 ;;; Code:
|
|
48
|
|
49 (defgroup elide-head nil
|
|
50 "Eliding copyright headers and the like in source files."
|
27125
|
51 :version "21.1"
|
26151
|
52 :prefix "elide-head"
|
|
53 :group 'tools)
|
|
54
|
|
55 (defcustom elide-head-headers-to-hide
|
|
56 '(("is free software; you can redistribute it" . ; GNU boilerplate
|
64130
6e6a8d280410
(elide-head-headers-to-hide): Recognize the FSF's new address as well.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
57 "Boston, MA 0211\\(1-1307\\|0-1301\\), USA\\.")
|
26151
|
58 ("The Regents of the University of California\\. All rights reserved\\." .
|
64130
6e6a8d280410
(elide-head-headers-to-hide): Recognize the FSF's new address as well.
Lute Kamstra <lute@gnu.org>
diff
changeset
|
59 "SUCH DAMAGE\\.") ; BSD
|
26151
|
60 ("Permission is hereby granted, free of charge" . ; X11
|
|
61 "authorization from the X Consortium\\."))
|
|
62 "Alist of regexps defining start end end of text to elide.
|
|
63
|
|
64 The cars of elements of the list are searched for in order. Text is
|
|
65 elided with an invisible overlay from the end of the line where the
|
|
66 first match is found to the end of the match for the corresponding
|
|
67 cdr."
|
|
68 :group 'elide-head
|
|
69 :type '(alist :key-type (string :tag "Start regexp")
|
|
70 :value-type (string :tag "End regexp")))
|
|
71
|
|
72 (defvar elide-head-overlay nil)
|
|
73 (make-variable-buffer-local 'elide-head-overlay)
|
|
74
|
|
75 ;;;###autoload
|
|
76 (defun elide-head (&optional arg)
|
|
77 "Hide header material in buffer according to `elide-head-headers-to-hide'.
|
|
78
|
|
79 The header is made invisible with an overlay. With a prefix arg, show
|
|
80 an elided material again.
|
|
81
|
46899
|
82 This is suitable as an entry on `find-file-hook' or appropriate mode hooks."
|
26151
|
83 (interactive "P")
|
|
84 (if arg
|
|
85 (elide-head-show)
|
|
86 (save-excursion
|
|
87 (save-restriction
|
|
88 (let ((rest elide-head-headers-to-hide)
|
|
89 beg end)
|
|
90 (widen)
|
|
91 (goto-char (point-min))
|
|
92 (while rest
|
|
93 (save-excursion
|
|
94 (when (re-search-forward (caar rest) nil t)
|
|
95 (setq beg (point))
|
|
96 (when (re-search-forward (cdar rest) nil t)
|
27264
|
97 (setq end (point-marker)
|
26151
|
98 rest nil))))
|
|
99 (if rest (setq rest (cdr rest))))
|
|
100 (if (not (and beg end))
|
|
101 (if (interactive-p)
|
57751
|
102 (message "No header found"))
|
26151
|
103 (goto-char beg)
|
|
104 (end-of-line)
|
|
105 (if (overlayp elide-head-overlay)
|
27264
|
106 (move-overlay elide-head-overlay (point-marker) end)
|
27578
|
107 (setq elide-head-overlay (make-overlay (point-marker) end)))
|
26151
|
108 (overlay-put elide-head-overlay 'invisible t)
|
35701
|
109 (overlay-put elide-head-overlay 'evaporate t)
|
26151
|
110 (overlay-put elide-head-overlay 'after-string "...")))))))
|
|
111
|
|
112 (defun elide-head-show ()
|
|
113 "Show a header elided current buffer by \\[elide-head]."
|
|
114 (interactive)
|
|
115 (if (and (overlayp elide-head-overlay)
|
|
116 (overlay-buffer elide-head-overlay))
|
|
117 (delete-overlay elide-head-overlay)
|
|
118 (if (interactive-p)
|
57751
|
119 (message "No header hidden"))))
|
26151
|
120
|
|
121 (provide 'elide-head)
|
|
122
|
52401
|
123 ;;; arch-tag: a00e6b5b-6aeb-45b1-b734-63e23df80928
|
26151
|
124 ;;; elide-head.el ends here
|