(comment-style(s)): Replaces comment-extra-lines (and comment-multi-line).
[emacs.git] / lisp / elide-head.el
blobdb26eb8f9ea30d30c8064c768e8599bc7ad61328
1 ;;; elid-head.el --- hide headers in files
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
5 ;; Author: Dave Love <fx@gnu.org>
6 ;; Keywords: outlines tools
8 ;; This file is part of GNU Emacs.
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.
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.
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.
25 ;;; Commentary:
27 ;; Functionality for eliding boilerplate text (normally copyright
28 ;; notices) in file headers to avoid clutter when you know what it
29 ;; says.
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.
35 ;; Please don't turn this on in site init files so that information
36 ;; isn't hidden from users who may not know what it says.
38 ;; Inspired by jwz's hide-copyleft.el, for which we don't have an
39 ;; assignment.
41 ;;; Code:
43 (defgroup elide-head nil
44 "Eliding copyright headers and the like in source files."
45 :prefix "elide-head"
46 :group 'tools)
48 (defcustom elide-head-headers-to-hide
49 '(("is free software; you can redistribute it" . ; GNU boilerplate
50 "Boston, MA 02111-1307, USA\\.")
51 ("The Regents of the University of California\\. All rights reserved\\." .
52 "SUCH DAMAGE\\.") ; BSD
53 ("Permission is hereby granted, free of charge" . ; X11
54 "authorization from the X Consortium\\."))
55 "Alist of regexps defining start end end of text to elide.
57 The cars of elements of the list are searched for in order. Text is
58 elided with an invisible overlay from the end of the line where the
59 first match is found to the end of the match for the corresponding
60 cdr."
61 :group 'elide-head
62 :type '(alist :key-type (string :tag "Start regexp")
63 :value-type (string :tag "End regexp")))
65 (defvar elide-head-overlay nil)
66 (make-variable-buffer-local 'elide-head-overlay)
68 ;;;###autoload
69 (defun elide-head (&optional arg)
70 "Hide header material in buffer according to `elide-head-headers-to-hide'.
72 The header is made invisible with an overlay. With a prefix arg, show
73 an elided material again.
75 This is suitable as an entry on `find-file-hooks' or appropriate mode hooks."
76 (interactive "P")
77 (if arg
78 (elide-head-show)
79 (save-excursion
80 (save-restriction
81 (let ((rest elide-head-headers-to-hide)
82 beg end)
83 (widen)
84 (goto-char (point-min))
85 (while rest
86 (save-excursion
87 (when (re-search-forward (caar rest) nil t)
88 (setq beg (point))
89 (when (re-search-forward (cdar rest) nil t)
90 (setq end (point)
91 rest nil))))
92 (if rest (setq rest (cdr rest))))
93 (if (not (and beg end))
94 (if (interactive-p)
95 (error "No header found"))
96 (goto-char beg)
97 (end-of-line)
98 (if (overlayp elide-head-overlay)
99 (move-overlay elide-head-overlay (point) end)
100 (setq elide-head-overlay (make-overlay (point) end)))
101 (overlay-put elide-head-overlay 'invisible t)
102 (overlay-put elide-head-overlay 'intangible t)
103 (overlay-put elide-head-overlay 'after-string "...")))))))
105 (defun elide-head-show ()
106 "Show a header elided current buffer by \\[elide-head]."
107 (interactive)
108 (if (and (overlayp elide-head-overlay)
109 (overlay-buffer elide-head-overlay))
110 (delete-overlay elide-head-overlay)
111 (if (interactive-p)
112 (error "No header hidden"))))
114 (provide 'elide-head)
116 ;;; elide-head.el ends here