unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Tim X <timx@nospam.dev.null>
To: help-gnu-emacs@gnu.org
Subject: Re: insert name of current file
Date: Wed, 26 Jan 2011 10:15:13 +1100	[thread overview]
Message-ID: <87y6684ltq.fsf@rapttech.com.au> (raw)
In-Reply-To: mailman.7.1295992748.30245.help-gnu-emacs@gnu.org

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


       reply	other threads:[~2011-01-25 23:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.7.1295992748.30245.help-gnu-emacs@gnu.org>
2011-01-25 23:15 ` Tim X [this message]
2011-01-25 21:59 insert name of current file Gradivus
2011-01-25 22:09 ` Dirk-Jan C. Binnema
2011-01-25 22:10 ` Deniz Dogan
2011-01-25 22:33 ` Oleksandr Gavenko
2011-01-26  3:41 ` Steven W. Orr

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87y6684ltq.fsf@rapttech.com.au \
    --to=timx@nospam.dev.null \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).