2020-04-19 08:03:21 +02:00
|
|
|
|
;;; elide-head.el --- hide headers in files -*- lexical-binding: t; -*-
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
2022-01-01 02:45:51 -05:00
|
|
|
|
;; Copyright (C) 1999, 2001-2022 Free Software Foundation, Inc.
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
|
|
|
|
;; Author: Dave Love <fx@gnu.org>
|
|
|
|
|
;; Keywords: outlines tools
|
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1999-10-23 18:18:03 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 08:06:51 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
|
|
|
|
;; GNU Emacs is distributed in the hope that it will be useful,
|
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
2017-09-13 15:52:52 -07:00
|
|
|
|
;; along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;; Functionality for eliding boilerplate text (normally copyright
|
|
|
|
|
;; notices) in file headers to avoid clutter when you know what it
|
|
|
|
|
;; says.
|
|
|
|
|
;;
|
2022-01-09 11:11:47 +01:00
|
|
|
|
;; `elide-head-headers-to-hide' controls what is elided by the minor
|
|
|
|
|
;; mode `elide-head-mode'. A buffer-local invisible overlay manages
|
|
|
|
|
;; the elision.
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
2022-01-09 11:11:47 +01:00
|
|
|
|
;; You might add `elide-head-mode' to appropriate major mode hooks or
|
|
|
|
|
;; to `find-file-hook'. Please do not do this in site init files. If
|
1999-12-04 13:25:08 +00:00
|
|
|
|
;; you do, information may be hidden from users who don't know it
|
|
|
|
|
;; already.
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
1999-12-16 19:16:19 +00:00
|
|
|
|
;; Note that `hs-minor-mode' will do a similar job by default, but
|
|
|
|
|
;; it's not selective about what leading commentary it hides.
|
|
|
|
|
|
1999-10-23 18:18:03 +00:00
|
|
|
|
;; Inspired by jwz's hide-copyleft.el, for which we don't have an
|
|
|
|
|
;; assignment.
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
|
|
(defgroup elide-head nil
|
|
|
|
|
"Eliding copyright headers and the like in source files."
|
2000-01-04 00:11:00 +00:00
|
|
|
|
:version "21.1"
|
1999-10-23 18:18:03 +00:00
|
|
|
|
:prefix "elide-head"
|
|
|
|
|
:group 'tools)
|
|
|
|
|
|
|
|
|
|
(defcustom elide-head-headers-to-hide
|
2022-01-02 19:25:02 +01:00
|
|
|
|
`(;; GNU GPL
|
|
|
|
|
("is free software[:;] you can redistribute it" .
|
2022-01-03 09:02:29 +01:00
|
|
|
|
,(rx (or (seq "If not, see " (? "<")
|
|
|
|
|
"http" (? "s") "://www.gnu.org/licenses/"
|
|
|
|
|
(? ">") (? " "))
|
|
|
|
|
(seq "Boston, MA " (? " ")
|
|
|
|
|
"0211" (or "1-1307" "0-1301")
|
|
|
|
|
(or " " ", ") "USA")
|
|
|
|
|
"675 Mass Ave, Cambridge, MA 02139, USA")
|
|
|
|
|
(? ".")))
|
2022-01-03 07:52:55 +01:00
|
|
|
|
;; FreeBSD license / Modified BSD license (3-clause)
|
2022-01-01 14:23:11 +01:00
|
|
|
|
(,(rx (or "The Regents of the University of California. All rights reserved."
|
|
|
|
|
"Redistribution and use in source and binary"))
|
2022-01-03 07:52:55 +01:00
|
|
|
|
. "POSSIBILITY OF SUCH DAMAGE\\.")
|
2022-01-02 19:25:02 +01:00
|
|
|
|
;; X11 and Expat
|
2022-01-01 14:23:11 +01:00
|
|
|
|
("Permission is hereby granted, free of charge" .
|
2022-01-03 07:52:55 +01:00
|
|
|
|
,(rx (or "authorization from the X Consortium." ; X11
|
|
|
|
|
"THE USE OR OTHER DEALINGS IN THE SOFTWARE.")))) ; Expat
|
2017-10-09 22:53:19 -07:00
|
|
|
|
"Alist of regexps defining start and end of text to elide.
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
|
|
|
|
The cars of elements of the list are searched for in order. Text is
|
|
|
|
|
elided with an invisible overlay from the end of the line where the
|
|
|
|
|
first match is found to the end of the match for the corresponding
|
2022-01-09 11:11:47 +01:00
|
|
|
|
cdr.
|
|
|
|
|
|
|
|
|
|
This affects `elide-head-mode'."
|
2019-12-21 18:52:06 +01:00
|
|
|
|
:type '(alist :key-type (regexp :tag "Start regexp")
|
2022-01-01 14:23:11 +01:00
|
|
|
|
:value-type (regexp :tag "End regexp"))
|
|
|
|
|
:version "29.1")
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
2020-04-19 08:03:21 +02:00
|
|
|
|
(defvar-local elide-head-overlay nil)
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
2022-01-09 11:11:47 +01:00
|
|
|
|
(defun elide-head--delete-overlay ()
|
|
|
|
|
"Delete the overlay in `elide-head-overlay'."
|
|
|
|
|
(when (overlayp elide-head-overlay)
|
|
|
|
|
(delete-overlay elide-head-overlay)))
|
|
|
|
|
|
|
|
|
|
(defun elide-head--hide ()
|
|
|
|
|
"Hide elided (hidden) headers."
|
|
|
|
|
(save-excursion
|
|
|
|
|
(save-restriction
|
|
|
|
|
(let ((rest elide-head-headers-to-hide)
|
|
|
|
|
beg end)
|
|
|
|
|
(widen)
|
|
|
|
|
(goto-char (point-min))
|
|
|
|
|
(while rest
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when (re-search-forward (caar rest) nil t)
|
|
|
|
|
(setq beg (point))
|
|
|
|
|
(when (re-search-forward (cdar rest) nil t)
|
|
|
|
|
(setq end (point-marker)
|
|
|
|
|
rest nil))))
|
|
|
|
|
(if rest (setq rest (cdr rest))))
|
|
|
|
|
(if (not (and beg end))
|
|
|
|
|
(if (called-interactively-p 'interactive)
|
|
|
|
|
(message "No header found"))
|
|
|
|
|
(goto-char beg)
|
|
|
|
|
(end-of-line)
|
|
|
|
|
(if (overlayp elide-head-overlay)
|
|
|
|
|
(move-overlay elide-head-overlay (point-marker) end)
|
|
|
|
|
(setq elide-head-overlay (make-overlay (point-marker) end)))
|
|
|
|
|
(overlay-put elide-head-overlay 'invisible t)
|
|
|
|
|
(overlay-put elide-head-overlay 'evaporate t)
|
|
|
|
|
(overlay-put elide-head-overlay 'after-string "..."))))))
|
|
|
|
|
|
|
|
|
|
(defun elide-head--show ()
|
|
|
|
|
"Show elided (hidden) headers."
|
|
|
|
|
(if (and (overlayp elide-head-overlay)
|
|
|
|
|
(overlay-buffer elide-head-overlay))
|
|
|
|
|
(elide-head--delete-overlay)
|
|
|
|
|
(if (called-interactively-p 'interactive)
|
|
|
|
|
(message "No header hidden"))))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
|
|
|
|
(define-minor-mode elide-head-mode
|
|
|
|
|
"Toggle eliding (hiding) header material in the current buffer.
|
|
|
|
|
|
|
|
|
|
When Elide Header mode is enabled, headers are hidden according
|
|
|
|
|
to `elide-head-headers-to-hide'.
|
|
|
|
|
|
|
|
|
|
This is suitable as an entry on `find-file-hook' or appropriate
|
|
|
|
|
mode hooks."
|
|
|
|
|
:group 'elide-head
|
|
|
|
|
(if elide-head-mode
|
|
|
|
|
(progn
|
|
|
|
|
(elide-head--hide)
|
|
|
|
|
(add-hook 'change-major-mode-hook 'elide-head--delete-overlay nil 'local))
|
|
|
|
|
(elide-head--show)
|
|
|
|
|
(remove-hook 'change-major-mode-hook 'elide-head--delete-overlay 'local)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;; Obsolete
|
|
|
|
|
|
1999-10-23 18:18:03 +00:00
|
|
|
|
;;;###autoload
|
|
|
|
|
(defun elide-head (&optional arg)
|
|
|
|
|
"Hide header material in buffer according to `elide-head-headers-to-hide'.
|
|
|
|
|
|
|
|
|
|
The header is made invisible with an overlay. With a prefix arg, show
|
|
|
|
|
an elided material again.
|
|
|
|
|
|
2002-08-15 00:48:20 +00:00
|
|
|
|
This is suitable as an entry on `find-file-hook' or appropriate mode hooks."
|
2022-01-09 11:11:47 +01:00
|
|
|
|
(declare (obsolete elide-head-mode "29.1"))
|
1999-10-23 18:18:03 +00:00
|
|
|
|
(interactive "P")
|
|
|
|
|
(if arg
|
2022-01-10 04:28:33 +01:00
|
|
|
|
(elide-head-mode -1)
|
|
|
|
|
(elide-head-mode 1)))
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
|
|
|
|
(defun elide-head-show ()
|
2020-04-19 08:03:21 +02:00
|
|
|
|
"Show a header in the current buffer elided by \\[elide-head]."
|
2022-01-09 11:11:47 +01:00
|
|
|
|
(declare (obsolete elide-head-mode "29.1"))
|
1999-10-23 18:18:03 +00:00
|
|
|
|
(interactive)
|
2022-01-10 04:28:33 +01:00
|
|
|
|
(elide-head-mode -1))
|
1999-10-23 18:18:03 +00:00
|
|
|
|
|
|
|
|
|
(provide 'elide-head)
|
|
|
|
|
|
|
|
|
|
;;; elide-head.el ends here
|