annotate lisp/elide-head.el @ 26813:da094b0ffe3c

Fix for when font-lock mode is active. (sh-font-lock-unfontify-region-function): New function.
author Gerd Moellmann <gerd@gnu.org>
date Sun, 12 Dec 1999 13:18:54 +0000
parents b8145f3d528e
children 4364c74ee502
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26151
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
1 ;;; elid-head.el --- hide headers in files
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
2
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
3 ;; Copyright (C) 1999 Free Software Foundation, Inc.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
4
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
5 ;; Author: Dave Love <fx@gnu.org>
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
6 ;; Keywords: outlines tools
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
7
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
9
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
10 ;; GNU Emacs is free software; you can redistribute it and/or modify
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
11 ;; 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
12 ;; the Free Software Foundation; either version 2, or (at your option)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
13 ;; any later version.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
14
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
18 ;; GNU General Public License for more details.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
19
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
23 ;; Boston, MA 02111-1307, USA.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
24
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
25 ;;; Commentary:
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
26
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
27 ;; Functionality for eliding boilerplate text (normally copyright
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
28 ;; notices) in file headers to avoid clutter when you know what it
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
29 ;; says.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
30 ;;
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
31 ;; `elide-head-headers-to-hide' controls what is elided by the command
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
32 ;; `elide-head'. A buffer-local invisible overlay manages the
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
33 ;; elision.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
34
26700
61f2605f9e41 Comments only.
Dave Love <fx@gnu.org>
parents: 26151
diff changeset
35 ;; You might add `elide-head' to appropriate major mode hooks or to
26703
b8145f3d528e Fix commentary.
Dave Love <fx@gnu.org>
parents: 26700
diff changeset
36 ;; `find-file-hooks'. Please do not do this in site init files. If
b8145f3d528e Fix commentary.
Dave Love <fx@gnu.org>
parents: 26700
diff changeset
37 ;; 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
38 ;; already.
26151
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
39
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
40 ;; 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
41 ;; assignment.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
42
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
43 ;;; Code:
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
44
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
45 (defgroup elide-head nil
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
46 "Eliding copyright headers and the like in source files."
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
47 :prefix "elide-head"
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
48 :group 'tools)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
49
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
50 (defcustom elide-head-headers-to-hide
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
51 '(("is free software; you can redistribute it" . ; GNU boilerplate
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
52 "Boston, MA 02111-1307, USA\\.")
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
53 ("The Regents of the University of California\\. All rights reserved\\." .
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
54 "SUCH DAMAGE\\.") ; BSD
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
55 ("Permission is hereby granted, free of charge" . ; X11
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
56 "authorization from the X Consortium\\."))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
57 "Alist of regexps defining start end end of text to elide.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
58
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
59 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
60 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
61 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
62 cdr."
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
63 :group 'elide-head
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
64 :type '(alist :key-type (string :tag "Start regexp")
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
65 :value-type (string :tag "End regexp")))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
66
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
67 (defvar elide-head-overlay nil)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
68 (make-variable-buffer-local 'elide-head-overlay)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
69
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
70 ;;;###autoload
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
71 (defun elide-head (&optional arg)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
72 "Hide header material in buffer according to `elide-head-headers-to-hide'.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
73
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
74 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
75 an elided material again.
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
76
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
77 This is suitable as an entry on `find-file-hooks' or appropriate mode hooks."
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
78 (interactive "P")
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
79 (if arg
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
80 (elide-head-show)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
81 (save-excursion
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
82 (save-restriction
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
83 (let ((rest elide-head-headers-to-hide)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
84 beg end)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
85 (widen)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
86 (goto-char (point-min))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
87 (while rest
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
88 (save-excursion
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
89 (when (re-search-forward (caar rest) nil t)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
90 (setq beg (point))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
91 (when (re-search-forward (cdar rest) nil t)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
92 (setq end (point)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
93 rest nil))))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
94 (if rest (setq rest (cdr rest))))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
95 (if (not (and beg end))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
96 (if (interactive-p)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
97 (error "No header found"))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
98 (goto-char beg)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
99 (end-of-line)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
100 (if (overlayp elide-head-overlay)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
101 (move-overlay elide-head-overlay (point) end)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
102 (setq elide-head-overlay (make-overlay (point) end)))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
103 (overlay-put elide-head-overlay 'invisible t)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
104 (overlay-put elide-head-overlay 'intangible t)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
105 (overlay-put elide-head-overlay 'after-string "...")))))))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
106
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
107 (defun elide-head-show ()
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
108 "Show a header elided current buffer by \\[elide-head]."
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
109 (interactive)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
110 (if (and (overlayp elide-head-overlay)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
111 (overlay-buffer elide-head-overlay))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
112 (delete-overlay elide-head-overlay)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
113 (if (interactive-p)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
114 (error "No header hidden"))))
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
115
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
116 (provide 'elide-head)
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
117
983ad33e1d97 *** empty log message ***
Dave Love <fx@gnu.org>
parents:
diff changeset
118 ;;; elide-head.el ends here