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