1 ;;; elide-head.el --- hide headers in files
3 ;; Copyright (C) 1999, 2002, 2003, 2004, 2005,
4 ;; 2006 Free Software Foundation, Inc.
6 ;; Author: Dave Love <fx@gnu.org>
7 ;; Keywords: outlines tools
9 ;; This file is part of GNU Emacs.
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
13 ;; the Free Software Foundation; either version 2, or (at your option)
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.
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
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
28 ;; Functionality for eliding boilerplate text (normally copyright
29 ;; notices) in file headers to avoid clutter when you know what it
32 ;; `elide-head-headers-to-hide' controls what is elided by the command
33 ;; `elide-head'. A buffer-local invisible overlay manages the
36 ;; You might add `elide-head' to appropriate major mode hooks or to
37 ;; `find-file-hook'. Please do not do this in site init files. If
38 ;; you do, information may be hidden from users who don't know it
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.
44 ;; Inspired by jwz's hide-copyleft.el, for which we don't have an
49 (defgroup elide-head nil
50 "Eliding copyright headers and the like in source files."
55 (defcustom elide-head-headers-to-hide
56 '(("is free software; you can redistribute it" .
; GNU boilerplate
57 "Boston, MA 0211\\(1-1307\\|0-1301\\), USA\\.")
58 ("The Regents of the University of California\\. All rights reserved\\." .
59 "SUCH DAMAGE\\.") ; BSD
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.
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
69 :type
'(alist :key-type
(string :tag
"Start regexp")
70 :value-type
(string :tag
"End regexp")))
72 (defvar elide-head-overlay nil
)
73 (make-variable-buffer-local 'elide-head-overlay
)
76 (defun elide-head (&optional arg
)
77 "Hide header material in buffer according to `elide-head-headers-to-hide'.
79 The header is made invisible with an overlay. With a prefix arg, show
80 an elided material again.
82 This is suitable as an entry on `find-file-hook' or appropriate mode hooks."
88 (let ((rest elide-head-headers-to-hide
)
91 (goto-char (point-min))
94 (when (re-search-forward (caar rest
) nil t
)
96 (when (re-search-forward (cdar rest
) nil t
)
97 (setq end
(point-marker)
99 (if rest
(setq rest
(cdr rest
))))
100 (if (not (and beg end
))
102 (message "No header found"))
105 (if (overlayp elide-head-overlay
)
106 (move-overlay elide-head-overlay
(point-marker) end
)
107 (setq elide-head-overlay
(make-overlay (point-marker) end
)))
108 (overlay-put elide-head-overlay
'invisible t
)
109 (overlay-put elide-head-overlay
'evaporate t
)
110 (overlay-put elide-head-overlay
'after-string
"...")))))))
112 (defun elide-head-show ()
113 "Show a header elided current buffer by \\[elide-head]."
115 (if (and (overlayp elide-head-overlay
)
116 (overlay-buffer elide-head-overlay
))
117 (delete-overlay elide-head-overlay
)
119 (message "No header hidden"))))
121 (provide 'elide-head
)
123 ;;; arch-tag: a00e6b5b-6aeb-45b1-b734-63e23df80928
124 ;;; elide-head.el ends here