Mercurial > emacs
annotate lisp/elide-head.el @ 94847:5e64dca662f0
Remove assumption about what nil means as a first arument to vc-do-command.
author | Eric S. Raymond <esr@snark.thyrsus.com> |
---|---|
date | Sat, 10 May 2008 13:27:16 +0000 |
parents | ee5932bf781d |
children | e7c3af7f57eb |
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 | 2 |
74439 | 3 ;; Copyright (C) 1999, 2001, 2002, 2003, 2004, 2005, |
79721 | 4 ;; 2006, 2007, 2008 Free Software Foundation, Inc. |
26151 | 5 |
6 ;; Author: Dave Love <fx@gnu.org> | |
7 ;; Keywords: outlines tools | |
8 | |
9 ;; This file is part of GNU Emacs. | |
10 | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
26151 | 12 ;; it under the terms of the GNU General Public License as published by |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
26151 | 15 |
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. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94678
ee5932bf781d
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
26151 | 23 |
24 ;;; Commentary: | |
25 | |
26 ;; Functionality for eliding boilerplate text (normally copyright | |
27 ;; notices) in file headers to avoid clutter when you know what it | |
28 ;; says. | |
29 ;; | |
30 ;; `elide-head-headers-to-hide' controls what is elided by the command | |
31 ;; `elide-head'. A buffer-local invisible overlay manages the | |
32 ;; elision. | |
33 | |
26700 | 34 ;; 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
|
35 ;; `find-file-hook'. Please do not do this in site init files. If |
26703 | 36 ;; you do, information may be hidden from users who don't know it |
37 ;; already. | |
26151 | 38 |
26925 | 39 ;; Note that `hs-minor-mode' will do a similar job by default, but |
40 ;; it's not selective about what leading commentary it hides. | |
41 | |
26151 | 42 ;; Inspired by jwz's hide-copyleft.el, for which we don't have an |
43 ;; assignment. | |
44 | |
45 ;;; Code: | |
46 | |
47 (defgroup elide-head nil | |
48 "Eliding copyright headers and the like in source files." | |
27125 | 49 :version "21.1" |
26151 | 50 :prefix "elide-head" |
51 :group 'tools) | |
52 | |
53 (defcustom elide-head-headers-to-hide | |
54 '(("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
|
55 "Boston, MA 0211\\(1-1307\\|0-1301\\), USA\\.") |
26151 | 56 ("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
|
57 "SUCH DAMAGE\\.") ; BSD |
26151 | 58 ("Permission is hereby granted, free of charge" . ; X11 |
59 "authorization from the X Consortium\\.")) | |
60 "Alist of regexps defining start end end of text to elide. | |
61 | |
62 The cars of elements of the list are searched for in order. Text is | |
63 elided with an invisible overlay from the end of the line where the | |
64 first match is found to the end of the match for the corresponding | |
65 cdr." | |
66 :group 'elide-head | |
67 :type '(alist :key-type (string :tag "Start regexp") | |
68 :value-type (string :tag "End regexp"))) | |
69 | |
70 (defvar elide-head-overlay nil) | |
71 (make-variable-buffer-local 'elide-head-overlay) | |
72 | |
73 ;;;###autoload | |
74 (defun elide-head (&optional arg) | |
75 "Hide header material in buffer according to `elide-head-headers-to-hide'. | |
76 | |
77 The header is made invisible with an overlay. With a prefix arg, show | |
78 an elided material again. | |
79 | |
46899
f00337f04e78
Use find-file-hook instead of find-file-hooks.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38436
diff
changeset
|
80 This is suitable as an entry on `find-file-hook' or appropriate mode hooks." |
26151 | 81 (interactive "P") |
82 (if arg | |
83 (elide-head-show) | |
84 (save-excursion | |
85 (save-restriction | |
86 (let ((rest elide-head-headers-to-hide) | |
87 beg end) | |
88 (widen) | |
89 (goto-char (point-min)) | |
90 (while rest | |
91 (save-excursion | |
92 (when (re-search-forward (caar rest) nil t) | |
93 (setq beg (point)) | |
94 (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
|
95 (setq end (point-marker) |
26151 | 96 rest nil)))) |
97 (if rest (setq rest (cdr rest)))) | |
98 (if (not (and beg end)) | |
99 (if (interactive-p) | |
57751
d2b6a6d18cc9
(elide-head): Change error to message.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
100 (message "No header found")) |
26151 | 101 (goto-char beg) |
102 (end-of-line) | |
103 (if (overlayp elide-head-overlay) | |
27264
7c1aca21377a
(elide-head): Use point-marker, not point.
Dave Love <fx@gnu.org>
parents:
27125
diff
changeset
|
104 (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
|
105 (setq elide-head-overlay (make-overlay (point-marker) end))) |
26151 | 106 (overlay-put elide-head-overlay 'invisible t) |
35701
96fb197c6aff
(elide-head): Make overlay evaporate.
Dave Love <fx@gnu.org>
parents:
27578
diff
changeset
|
107 (overlay-put elide-head-overlay 'evaporate t) |
26151 | 108 (overlay-put elide-head-overlay 'after-string "..."))))))) |
109 | |
110 (defun elide-head-show () | |
111 "Show a header elided current buffer by \\[elide-head]." | |
112 (interactive) | |
113 (if (and (overlayp elide-head-overlay) | |
114 (overlay-buffer elide-head-overlay)) | |
115 (delete-overlay elide-head-overlay) | |
116 (if (interactive-p) | |
57751
d2b6a6d18cc9
(elide-head): Change error to message.
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
117 (message "No header hidden")))) |
26151 | 118 |
119 (provide 'elide-head) | |
120 | |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
79721
diff
changeset
|
121 ;; arch-tag: a00e6b5b-6aeb-45b1-b734-63e23df80928 |
26151 | 122 ;;; elide-head.el ends here |