[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Knowing the name of a file from the file itself
From: |
Andy Stewart |
Subject: |
Re: Knowing the name of a file from the file itself |
Date: |
Tue, 21 Oct 2008 08:25:29 +0800 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
Use this function
(defun copy-buffer-file-name-as-kill(choice)
"Copy the buffer-file-name to the kill-ring"
(interactive "cCopy Buffer Name (F) Full, (D) Directory, (N) Name")
(let ((new-kill-string)
(name (if (eq major-mode 'dired-mode)
(dired-get-filename)
(or (buffer-file-name) ""))))
(cond ((eq choice ?f)
(setq new-kill-string name))
((eq choice ?d)
(setq new-kill-string (file-name-directory name)))
((eq choice ?n)
(setq new-kill-string (file-name-nondirectory name)))
(t (message "Quit")))
(when new-kill-string
(message "%s copied" new-kill-string)
(kill-new new-kill-string))))
And C-y (yank) will get information your want.
abc <arcadiorubiogarcia@gmail.com> writes:
> Hi everyone,
>
> I'm a recent Emacs convert. I'm structuring my .emacs.d directory
> which has become quite messy.
>
> For that purpose, I'd like to know if it's possible to know the name
> of a file and the path to it from the file itself, like in many other
> languages, e.g. Ruby.
>
> I've looked for a variable or function for this with no luck.
>
>
> Thanks in advance.