We have 15 line long copyright messages at the top of all our source-code files.
When I have them open in emacs, that wastes a lot of valuable space.
Is there any way to get emacs to always a hide a certain message but still leave it in the file?
We have 15 line long copyright messages at the top of all our source-code files.
When I have them open in emacs, that wastes a lot of valuable space.
Is there any way to get emacs to always a hide a certain message but still leave it in the file?
Have a look at folding-mode. Basically, all you need is a way to identify the parts to be folded, and then use folding-top-mark
and folding-bottom-mark
to mark them. There are hacks to do that with EMACS elisp code by the way, so you should be easily able to find code that can be adapted.
Emacs comes with elide-head
, specifically for that, since Emacs-21.
In Emacs-29 we rename it to elide-head-mode
.
You can use hideshow minor mode which is a standard built-in package that has a generalized command called hs-hide-initial-comment-block
that will do what you want without having to know how long the top comment section is. You can add it to the mode-hook of any language, but here's an example using C:
(add-hook 'c-mode-common-hook 'hs-minor-mode t)
(add-hook 'c-mode-common-hook 'hs-hide-initial-comment-block t)
Note, it does not hide specifically just the copyrights, but the full initial comment block which may hide useful documentation, as well.
You could write a function that narrows your buffer to everything but the first 15 lines.
Then all you need to do is make sure that this function is called for every file that contains a copyright note. This can be done by adding a hook, preferably to the major mode of your file. For instance you could add the above function definition and the following line to your .emacs file:
This would call the function 'hide-copyright-note whenever you open a C file.
In practice, you would probably want to make your hook-function more clever, either by checking if a copyright note to hide actually exists or by running hide-copyright-note only if a file is in a certain directory etc.
For instance, to stick with the C example, you could insert the following test into the above function:
As for your other concern:
...or you could just scroll down. To achieve this automatically, we could use the following function instead of
hide-copyright-note
:However, the reason I recommended the first variation is that if you merely scroll down automatically, then whenever you jump to the beginning of the buffer (
M-<
) you'll have to scroll down again manually. This problem does not occur with the narrowing solution.