all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* insert name of current file
@ 2011-01-25 21:59 Gradivus
  2011-01-25 22:09 ` Dirk-Jan C. Binnema
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Gradivus @ 2011-01-25 21:59 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 186 bytes --]

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.

Thanks,

O

[-- Attachment #2: Type: text/html, Size: 245 bytes --]

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

* Re: insert name of current file
  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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Dirk-Jan C. Binnema @ 2011-01-25 22:09 UTC (permalink / raw)
  To: Gradivus; +Cc: help-gnu-emacs

>>>>> On Tue, 25 Jan 2011 16:59:03 -0500, Gradivus  wrote:

  > [1  <text/plain; ISO-8859-1 (7bit)>]
  > 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.

  
M-: (insert-string (file-name-nondirectory (buffer-file-name))) RET

If you need it more often, you can of course write a function for it.

Best wishes,
Dirk.

-- 
Dirk-Jan C. Binnema                  Helsinki, Finland
e:djcb@djcbsoftware.nl           w:www.djcbsoftware.nl
pgp: D09C E664 897D 7D39 5047 A178 E96A C7A1 017D DA3C



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

* Re: insert name of current file
  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
  3 siblings, 0 replies; 6+ messages in thread
From: Deniz Dogan @ 2011-01-25 22:10 UTC (permalink / raw)
  To: Gradivus; +Cc: help-gnu-emacs

2011/1/25 Gradivus <mondifero@gmail.com>:
>
> Hi,
>
> Sorry I'm a noob.
>

You're excused!

> 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.
>

As far as I know, there is no such functionality by default, but put
this in your init file to bind "C-c i f" to it:

(defun insert-buffer-file-name ()
  "Inserts the name of the file for the current buffer."
  (interactive)
  (if buffer-file-name
      (insert (file-name-nondirectory buffer-file-name))
    (message "No file associated with buffer.")))

(global-set-key (kbd "C-c i f") 'insert-buffer-file-name)

Hope that helps,
Deniz Dogan



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

* Re: insert name of current file
  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
  3 siblings, 0 replies; 6+ messages in thread
From: Oleksandr Gavenko @ 2011-01-25 22:33 UTC (permalink / raw)
  To: help-gnu-emacs

On 2011-01-25 23:59, Gradivus wrote:
>
> 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.
>
If this task noes not repeatedly you can type: C-x C-f DOWN
and select file name, press C-w to copy it and C-g to
back to editing buffer where you can put file name by C-y.

I also have stuck with this knowledge some years ago.

-- 
Best regards!




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

* Re: insert name of current file
       [not found] <mailman.7.1295992748.30245.help-gnu-emacs@gnu.org>
@ 2011-01-25 23:15 ` Tim X
  0 siblings, 0 replies; 6+ messages in thread
From: Tim X @ 2011-01-25 23:15 UTC (permalink / raw)
  To: help-gnu-emacs

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


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

* Re: insert name of current file
  2011-01-25 21:59 insert name of current file Gradivus
                   ` (2 preceding siblings ...)
  2011-01-25 22:33 ` Oleksandr Gavenko
@ 2011-01-26  3:41 ` Steven W. Orr
  3 siblings, 0 replies; 6+ messages in thread
From: Steven W. Orr @ 2011-01-26  3:41 UTC (permalink / raw)
  To: help-gnu-emacs

On 1/25/2011 4:59 PM, Gradivus wrote:
>
> 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.
>
> Thanks,
>
> O
>

I know this isn't what you asked, but I've used this to death for years:

(defun insert-filename (fn)
   "Use filename completion to insert a filename into current buffer."
   (interactive "FFilename to insert: ")
   (insert fn))
(define-key global-map [?\C-x ?\C-j] 'insert-filename)

Why limit yourself to just one filename? One other thing: This will insert the 
whole pathname. Just get the filename you want and then just back up to the 
beginning of the name, then M-Backspace to get rid of the offending prefix.

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net



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

end of thread, other threads:[~2011-01-26  3:41 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
     [not found] <mailman.7.1295992748.30245.help-gnu-emacs@gnu.org>
2011-01-25 23: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.