annotate lisp/elide-head.el @ 72950:5023bc85eb16

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