1

I've been a pretty adamant user of nano as my text editor for quite awhile for sake of simplicity. However, now I'm becoming a bit more "seasoned" and wanted to step up to a big-boy editor like emacs.

I know that emacs is highly customizable, and thought of something that I'd like to do. Is there a way to create a generic heading for files created of a certain filetype?

For example, if I make a .* file, could I generate something similar to Xcode's generated "heading"?

//*************************************************************
//
//  filename.*
//
//  Created by some_static_user on MM/DD/YY.
//  Copyright (c) YYYY some_static_user. All rights reserved.
//
//*************************************************************

It would be lovely and save me some time. Besides, I know there are some emacs apologists who would love to make an emac user out of me.

Thanks for your time and I hope this isn't too trivial.

erip

erip
  • 27
  • 5
  • A ".*" file? As in, a file whose name literally ends with a period and an asterisk? – Sean May 18 '14 at 21:22
  • Sean, I mean any generic filetype. If it type 'emacs helloworld.c', I want it to read 'helloworld.c' instead of 'filename.*' – erip May 18 '14 at 21:24
  • 2
    http://www.emacswiki.org/emacs/AutomaticFileHeaders – itsjeyd May 18 '14 at 21:29
  • A search at S.O. for AutomaticFileHeaders also turns up [License banners for Scala when using ENSIME](http://stackoverflow.com/questions/3981544/license-banners-for-scala-when-using-ensime/4910996). – phils May 18 '14 at 22:05
  • FWIW there's a related blog on that at [emacsworld.blogspot.com](http://emacsworld.blogspot.com/2008/12/generating-automatic-file-headers.html). itsjeyd, you should add your link as a proper answer so it can be accepted. – phils May 18 '14 at 22:10
  • @erip I'm glad you were able to come up with a solution based on my input, and thanks for taking the time to describe your solution. For future reference, instead of posting the solution as a comment, consider [adding an actual answer](https://stackoverflow.com/help/self-answer). After 48 hours, you will even be able to [accept it](https://stackoverflow.com/help/accepted-answer) to make it stand out as the correct one for future visitors. (The reason why I posted a comment instead of an answer is that link-only answers are [discouraged](http://meta.stackexchange.com/q/225370/244644)). – itsjeyd May 19 '14 at 07:29

2 Answers2

1

Try library header2.el. Description here. You should be able to customize things to get just what you want.

Drew
  • 29,895
  • 7
  • 74
  • 104
1

I got it figured out based on @itsjeyd 's answer. For those Mac users reading this, add this to your ~/.emacs.d/init.el

(add-to-list 'load-path' "~/.emacs.d/")     
(autoload 'auto-make-header "header2")     
(add-hook 'write-file-hooks 'auto-update-file-header)     
(add-hook 'emacs-lisp-mode-hook 'auto-make-header)     
(add-hook 'c-mode-common-hook 'auto-make-header)     
(add-hook 'tex-mode-hook 'auto-make-header) 

after saving header2.el in the same directory as init.el. Thanks, everyone!

erip
  • 27
  • 5