annotate lisp/utils/hide-copyleft.el @ 200:f0deb0c0e6be

Added tag r20-3b26 for changeset 169c0442b401
author cvs
date Mon, 13 Aug 2007 10:00:35 +0200
parents 538048ae2ab8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
1 ;;; hide-copyleft.el --- hide obnoxious copyright prologs
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
2
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
3 ;; Copyright (C) 1997 Sun Microsystems.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
4
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
5 ;; This file is part of XEmacs.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
6
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
7 ;; XEmacs is free software; you can redistribute it and/or modify it
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
8 ;; under the terms of the GNU General Public License as published by
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
10 ;; any later version.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
11
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
12 ;; XEmacs is distributed in the hope that it will be useful, but
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
15 ;; General Public License for more details.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
16
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
17 ;; You should have received a copy of the GNU General Public License
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
18 ;; along with XEmacs; see the file COPYING. If not, write to the Free
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
19 ;; Software Foundation, Inc. 59 Temple Place - Suite 330, Boston, MA
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
20 ;; 02111-1307, USA.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
21
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
22 ;;; Commentary:
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
24 ;; Written by Jamie Zawinski <jwz@netscape.com>, 19-jan-91.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
25 ;; Minor fixes by Martin Buchholz, 14-may-97.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
26 ;; Last modified 14-may-97.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
27 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
28 ;; I sometimes find it tiresome to have fifteen lines of copyright notice at
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
29 ;; the beginning of each file. Meta-< does not take you to the beginning of
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
30 ;; the code, it takes you a windowfull or two away, which can be tedious on
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
31 ;; slow terminal lines.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
32 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
33 ;; I know what the copyright notice says; so this code makes all but the first
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
34 ;; line of it be invisible, by using Emacs's selective-display feature. The
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
35 ;; text is still present and unmodified, but it is invisible.
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
36 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
37 ;; Elide the copyright notice with "Meta-X hide-copyleft-region". Make it
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
38 ;; visible again with "Control-U Meta-X hide-copyleft-region". Or, if you're
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
39 ;; sure you're not gonna get sued, you can do something like this in your
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
40 ;; .emacs file:
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
41 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
42 ;; (autoload 'hide-copyleft-region "hide-copyleft" nil t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
43 ;; (autoload 'unhide-copyleft-region "hide-copyleft" nil t)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
44 ;; (add-hook 'emacs-lisp-mode-hook 'hide-copyleft-region)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
45 ;; (add-hook 'c-mode-hook 'hide-copyleft-region)
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
46 ;;
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
47 ;; This code (obviously) has quite specific knowledge of the wording of the
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
48 ;; various copyrights I've run across. Let me know if you find one on which
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
49 ;; it fails.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defvar copylefts-to-hide
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; There are some extra backslashes in these strings to prevent this code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;; from matching the definition of this list as the copyright notice!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 '(;; GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ("free software\; you can redistribute it" .
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
56 "notice must be\ preserved on all")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ("free software\; you can redistribute it" .
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
58 "copy of the GNU General Public License.*\n?.*\n?.*\n?.*\n?.*\\(02139,\\|02111-1307\\)")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ("distributed in the hope that it will be useful\," .
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
60 "notice must be\ preserved on all")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ("free software\; you can redistribute it" .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 "General Public License for more details\\.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; X11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ("Permission to use\, copy, modify," .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "WITH THE USE OR PERFORMANCE")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ("Permission to use\, copy, modify," .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "without express or implied warranty")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; Motif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ("Copyright.*OPEN\ SOFTWARE FOUNDATION" .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 "X Window System is a trademark of the")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ("THIS SOFTWARE\ IS FURNISHED UNDER A LICENSE" .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 "X Window System is a trademark of the")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;; UPenn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 ("Permission to use\, copy, and distribute" .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 " provided \"as is\" without")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 ;; Evans & Sutherland, Solbourne.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ("Copyright 19[0-9][0-9] by " .
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 "OR PERFORMANCE OF THIS SOFTWARE\\.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 ;; TI Explorer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 ("RESTRICTED RIGHTS LEGEND" . "All rights reserved\\.\\(\n;;; ?$\\)?")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 ("^%%BeginDocumentation" . "^%%EndDocumentation")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 "An alist of pairs of regexps which delimit copyright notices to hide.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 The first one found is hidden, so order is significant.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
87 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun hide-copyleft-region (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Make the legal drivel at the front of this file invisible. Unhide it again
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 with C-u \\[hide-copyleft-region]."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (if arg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (unhide-copyleft-region)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (if selective-display (error "selective-display is already on."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (catch 'Abort
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 (let ((mod-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (rest copylefts-to-hide)
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
101 pair start end)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (while (and rest (not pair))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (and (re-search-forward (car (car rest)) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (setq start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (re-search-forward (cdr (car rest)) nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (setq end (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 pair (car rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 (setq x pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (or pair
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if (interactive-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (error "Couldn't find a CopyLeft to hide.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (throw 'Abort nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 ;; If the last line of the notice closes a C comment, don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 ;; hide that line (to avoid confusion...)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (if (save-excursion (forward-char -3) (looking-at "\\*/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (goto-char start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (while (< (point) end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (insert "\^M")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (setq selective-display t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (set-buffer-modified-p mod-p)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
149
538048ae2ab8 Import from CVS: tag r20-3b1
cvs
parents: 0
diff changeset
133 ;;;###autoload
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defun unhide-copyleft-region ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 "If the legal nonsense at the top of this file is elided, make it visible again."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (let ((mod-p (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (buffer-read-only nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (or (search-forward "\^M" nil t) (error "Nothing hidden here, dude."))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (while (search-forward "\^M" end t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (delete-char -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (insert "\^J"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (set-buffer-modified-p mod-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (setq selective-display nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152