From: Andy Stewart <lazycat.manatee@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Knowing the name of a file from the file itself
Date: Tue, 21 Oct 2008 08:25:29 +0800 [thread overview]
Message-ID: <87od1e3ibq.fsf@manatee.domain> (raw)
In-Reply-To: 47ec3b12-d424-4b0f-8a90-d6ee3ca2add8@m73g2000hsh.googlegroups.com
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.
next prev parent reply other threads:[~2008-10-21 0:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-20 23:04 Knowing the name of a file from the file itself abc
2008-10-21 0:25 ` Andy Stewart [this message]
2008-10-21 1:28 ` Andreas Politz
2008-10-21 10:13 ` abc
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=87od1e3ibq.fsf@manatee.domain \
--to=lazycat.manatee@gmail.com \
--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).