Hide long copyright messages at the top of all files

We have copyright messages 15 lines long at the top of all source code files.

When I open them in emacs, it takes up a lot of valuable space.
Is there a way to make emacs always hide a specific message, but leave it in a file?

+5
source share
3 answers

You can write a function that narrows your buffer to all but the first 15 lines.

(defun hide-copyright-note ()
  "Narrows the current buffer so that the first 15 lines are
hidden."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (forward-line 15)
    (narrow-to-region (point) (point-max))))

, , , , . , , . , .emacs:

(add-hook 'c-mode-hook 'hide-copyright-note)

"hide-copyright-note" , C.

, , , , , hide-copyright-note , ..

, C, :

(defun hide-copyright-note ()
  "Narrows the current buffer so that the first 15 lines are
hidden."
  (interactive)
  (when (copyright-message-p)
    (save-excursion
      (goto-char (point-min))
      (forward-line 15)
      (narrow-to-region (point) (point-max)))))

(defun copyright-message-p ()
  "Returns t when the current buffer starts with a Copyright
note inside a C-style comment"
  (save-excursion
    (goto-char (point-min))
    (looking-at "\\s */\\*\\(:?\\s \\|\\*\\)*Copyright\\b")))

:

emacs, .

... . , hide-copyright-note:

(defun scroll-on-copyright ()
  "Scrolls down to the 16th line when the current buffer starts
with a copyright note."
  (interactive)
  (when (copyright-message-p)
    (goto-char (point-min))
    (beginning-of-line 16)
    (recenter 0)))

, , , , , (M-<), . .

+3

hideshow, , hs-hide-initial-comment-block, , , . - , C:

(add-hook 'c-mode-common-hook 'hs-minor-mode t)
(add-hook 'c-mode-common-hook 'hs-hide-initial-comment-block t)

, , , .

+7

. , , , , , folding-top-mark folding-bottom-mark . , EMISS elisp, , .

+1

All Articles