[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: insert name of current file
From: |
Tim X |
Subject: |
Re: insert name of current file |
Date: |
Wed, 26 Jan 2011 10:15:13 +1100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) |
Gradivus <mondifero@gmail.com> writes:
> Hi,
>
> Sorry I'm a noob.
>
> I wonder if someone knows how I can insert the current file's name
> (i.e., the name of the file I'm editing) at the cursor, and without the full
> path.
>
I use tempo templates, which I bind to a key. When opening a new file,
hitting the template key inserts the template, which includes the
filename of the current file (along with other information). I also use
the timestamp package so that when I save the file, the last modified
date is updated. The template uses the comment-start variable so that
the inserted text is prefixed with the appropriate comment character for
the mode being used. The code is attached below.
Tim
;;;
;;; Filename: 55tempo.el
;;; Creation Date: Wednesday, 30 April 2003 11:41 AM EST
;;; Last Modified: Saturday, 19 July 2008 12:44 PM EST
;;; Author: Tim Cross
;;; Description:
;;; This file contains some tempo 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@une.edu.au>" '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