all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* FSF like smart header
@ 2010-07-19 20:37 Andrea Crotti
  2010-07-19 20:41 ` Erik Iverson
  0 siblings, 1 reply; 9+ messages in thread
From: Andrea Crotti @ 2010-07-19 20:37 UTC (permalink / raw)
  To: help-gnu-emacs

I want to have some nice system to have finally some sort of smart
header in front of some files.

For example it would be nice something like:
when you create a file of c-mode in such directory, add a header on top
with those datas (author time, name of the project etc...)

So I guess I have to add a hook to find-file with some conditions, or is
there something more elaborate?

I would also like to use yasnippet, can I maybe pass some parameters to
a yasnippet snippet to expand automatically some variables (haven't seen
anything like that).

For the timestamp I can use the already nice defined time-stamp
functions...

What do you guys have as personal setup for these kind of things?

Thanks!

PS. another useful useage would be automatic addition of guard in files .h...




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FSF like smart header
  2010-07-19 20:37 FSF like smart header Andrea Crotti
@ 2010-07-19 20:41 ` Erik Iverson
  2010-07-19 22:55   ` Drew Adams
  0 siblings, 1 reply; 9+ messages in thread
From: Erik Iverson @ 2010-07-19 20:41 UTC (permalink / raw)
  To: Andrea Crotti; +Cc: help-gnu-emacs



Andrea Crotti wrote:
> I want to have some nice system to have finally some sort of smart
> header in front of some files.
> 
> For example it would be nice something like:
> when you create a file of c-mode in such directory, add a header on top
> with those datas (author time, name of the project etc...)
> 
> So I guess I have to add a hook to find-file with some conditions, or is
> there something more elaborate?

http://www.gnu.org/software/emacs/manual/html_node/autotype/Autoinserting.html




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FSF like smart header
       [not found] <mailman.8.1279571889.6173.help-gnu-emacs@gnu.org>
@ 2010-07-19 22:15 ` Tim X
  0 siblings, 0 replies; 9+ messages in thread
From: Tim X @ 2010-07-19 22:15 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> I want to have some nice system to have finally some sort of smart
> header in front of some files.
>
> For example it would be nice something like:
> when you create a file of c-mode in such directory, add a header on top
> with those datas (author time, name of the project etc...)
>
> So I guess I have to add a hook to find-file with some conditions, or is
> there something more elaborate?
>
> I would also like to use yasnippet, can I maybe pass some parameters to
> a yasnippet snippet to expand automatically some variables (haven't seen
> anything like that).
>
> For the timestamp I can use the already nice defined time-stamp
> functions...
>
> What do you guys have as personal setup for these kind of things?
>
> Thanks!
>
I use the following, based on tempo, which puts a standard header block in my files. It
uses the omment character of the major mode to determine how to put the
header in as a comment. It uses timestamp.el to handle the timestamps.
Each time the file is saved, the timestamp is automatically updated. It
could also be easily updated to use environment variables to control the
author etc. 

;;;								   
;;;      Filename: /home/tcross/.emacs.d/55tempo.el
;;; Creation Date: Wednesday, 30 April 2003 11:41 AM EST
;;; Last Modified: Saturday, 19 July 2008 12:44 PM EST
;;;           Job: private
;;;        Author: Tim Cross <tcross@pobox.une.edu.au>
;;;   Description:
;;; This file contains some temp templates for setting file headers. 
;;; 

(require 'tempo)


(tempo-define-template "generic-header"
        '((format "%s" comment-start)
          "      Filename: " (file-name-nondirectory (buffer-file-name)) 'n
          (format "%s" comment-start) " Creation Date: "
          (format-time-string "%A, %d %B %Y %I:%M %p %Z") 'n
          (format "%s" comment-start) " Last Modified: " 'n
          (format "%s" comment-start)
          "        Author: Tim Cross <tcross@xxxx>" 'n
          (format "%s" comment-start) "   Description:" 'n
          (format "%s" comment-start) 'n
          'n))

;;; Lets setup some key bindings.

(global-set-key [(f5)] 'tempo-template-generic-header)

(provide 'tc-template)


-- 
tcross (at) rapttech dot com dot au


^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: FSF like smart header
  2010-07-19 20:41 ` Erik Iverson
@ 2010-07-19 22:55   ` Drew Adams
  2010-08-03 15:15     ` Andrea Crotti
  0 siblings, 1 reply; 9+ messages in thread
From: Drew Adams @ 2010-07-19 22:55 UTC (permalink / raw)
  To: 'Erik Iverson', 'Andrea Crotti'; +Cc: help-gnu-emacs

> > I want to have some nice system to have finally some sort of smart
> > header in front of some files.
> > 
> > For example it would be nice something like:
> > when you create a file of c-mode in such directory, add a 
> > header on top with those datas (author time, name of the
> > project etc...)
> > 
> > So I guess I have to add a hook to find-file with some 
> > conditions, or is there something more elaborate?
> 
> http://www.gnu.org/software/emacs/manual/html_node/autotype/Au
> toinserting.html

More generally (includes info about the previous feature):
http://www.emacswiki.org/emacs/AutomaticFileHeaders




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FSF like smart header
  2010-07-19 22:55   ` Drew Adams
@ 2010-08-03 15:15     ` Andrea Crotti
  2010-08-03 15:40       ` Andrea Crotti
  0 siblings, 1 reply; 9+ messages in thread
From: Andrea Crotti @ 2010-08-03 15:15 UTC (permalink / raw)
  To: help-gnu-emacs

"Drew Adams" <drew.adams@oracle.com> writes:

> More generally (includes info about the previous feature):
> http://www.emacswiki.org/emacs/AutomaticFileHeaders

Given that I didn't like that too much and I prefer using yasnippet I
did this simple thing for header files (but can be adapted to anything)

--8<---------------cut here---------------start------------->8---
(defun is-header (file)
  "Check if file is an header"
  (equal "h" (file-name-extension file)))
      

(defun my-h-header ()
  "try to insert the header smartly"
  (if
      (is-header buffer-file-name)
      (progn 
        (insert "once")
        (yas/expand))))

(add-hook 'c-mode-hook 'my-h-header)
--8<---------------cut here---------------end--------------->8---

Which is pretty nice :)




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FSF like smart header
  2010-08-03 15:15     ` Andrea Crotti
@ 2010-08-03 15:40       ` Andrea Crotti
  2010-08-03 16:22         ` Richard Riley
  0 siblings, 1 reply; 9+ messages in thread
From: Andrea Crotti @ 2010-08-03 15:40 UTC (permalink / raw)
  To: help-gnu-emacs



I head another idea to make it more general:
--8<---------------cut here---------------start------------->8---
;; (mode . (regexp snippet)
(setq auto-snips
             '((c-mode . '('h' "once"))
               (python-mode . (t "!"))))

(defun smart-snips()
  (let
      ((found (assoc major-mode auto-snips)))
    (if (and
         found
         (string-match (nth 0 found) major-mode)
         (yes-or-no-p "insert the header?"))
        (progn
          (insert (nth 1 found))
          (yas/expand)))))
--8<---------------cut here---------------end--------------->8---

In this way we define for every language (and possibly extension) what
snippet we want to expand when we create a file.

Then adding smart-snips to "find-file-hook" would do the rest of the magic.

It doesn't work yet because I guess c-mode is a symbol and string-match
doesn't like it.
Don't know if I should just use the string representation or if there's
a smarter way...




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FSF like smart header
  2010-08-03 15:40       ` Andrea Crotti
@ 2010-08-03 16:22         ` Richard Riley
  2010-08-03 16:50           ` Drew Adams
  2010-08-03 18:06           ` Andrea Crotti
  0 siblings, 2 replies; 9+ messages in thread
From: Richard Riley @ 2010-08-03 16:22 UTC (permalink / raw)
  To: help-gnu-emacs

Andrea Crotti <andrea.crotti.0@gmail.com> writes:

> I head another idea to make it more general:
>
>
> ;; (mode . (regexp snippet)
> (setq auto-snips
>              '((c-mode . '('h' "once"))
>                (python-mode . (t "!"))))
>
> (defun smart-snips()
>   (let
>       ((found (assoc major-mode auto-snips)))
>     (if (and
>          found
>          (string-match (nth 0 found) major-mode)
>          (yes-or-no-p "insert the header?"))
>         (progn
>           (insert (nth 1 found))
>           (yas/expand)))))
>
>
>
> In this way we define for every language (and possibly extension) what
> snippet we want to expand when we create a file.
>
> Then adding smart-snips to "find-file-hook" would do the rest of the magic.
>
> It doesn't work yet because I guess c-mode is a symbol and string-match
> doesn't like it.
> Don't know if I should just use the string representation or if there's
> a smarter way...
>
>
>
>

FYI - Whats does this provide that other existing packages to auto
create headers for certain file types do not?

http://www.emacswiki.org/emacs/AutomaticFileHeaders

It's maintained by Drew and seems pretty comprehensive.









^ permalink raw reply	[flat|nested] 9+ messages in thread

* RE: FSF like smart header
  2010-08-03 16:22         ` Richard Riley
@ 2010-08-03 16:50           ` Drew Adams
  2010-08-03 18:06           ` Andrea Crotti
  1 sibling, 0 replies; 9+ messages in thread
From: Drew Adams @ 2010-08-03 16:50 UTC (permalink / raw)
  To: 'Richard Riley', help-gnu-emacs

> FYI - Whats does this provide that other existing packages to auto
> create headers for certain file types do not?
> 
> http://www.emacswiki.org/emacs/AutomaticFileHeaders
> It's maintained by Drew and seems pretty comprehensive.

Just to clarify -

That page lists several different packages that create or update file headers.
I maintain only one of them, header2.el.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: FSF like smart header
  2010-08-03 16:22         ` Richard Riley
  2010-08-03 16:50           ` Drew Adams
@ 2010-08-03 18:06           ` Andrea Crotti
  1 sibling, 0 replies; 9+ messages in thread
From: Andrea Crotti @ 2010-08-03 18:06 UTC (permalink / raw)
  To: help-gnu-emacs

Richard Riley <rileyrg@gmail.com> writes:

> FYI - Whats does this provide that other existing packages to auto
> create headers for certain file types do not?
>
> http://www.emacswiki.org/emacs/AutomaticFileHeaders
>
> It's maintained by Drew and seems pretty comprehensive.

Probably nothing, but I prefer to keep everything in yasnippet if
possible.

I think in general is much more powerful than normal skeletons, and
anyway is very easy as you saw to extend it in this way...




^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2010-08-03 18:06 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-19 20:37 FSF like smart header Andrea Crotti
2010-07-19 20:41 ` Erik Iverson
2010-07-19 22:55   ` Drew Adams
2010-08-03 15:15     ` Andrea Crotti
2010-08-03 15:40       ` Andrea Crotti
2010-08-03 16:22         ` Richard Riley
2010-08-03 16:50           ` Drew Adams
2010-08-03 18:06           ` Andrea Crotti
     [not found] <mailman.8.1279571889.6173.help-gnu-emacs@gnu.org>
2010-07-19 22:15 ` Tim X

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.