all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Knowing the name of a file from the file itself
@ 2008-10-20 23:04 abc
  2008-10-21  0:25 ` Andy Stewart
  2008-10-21  1:28 ` Andreas Politz
  0 siblings, 2 replies; 4+ messages in thread
From: abc @ 2008-10-20 23:04 UTC (permalink / raw)
  To: help-gnu-emacs

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.


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

* Re: Knowing the name of a file from the file itself
  2008-10-20 23:04 Knowing the name of a file from the file itself abc
@ 2008-10-21  0:25 ` Andy Stewart
  2008-10-21  1:28 ` Andreas Politz
  1 sibling, 0 replies; 4+ messages in thread
From: Andy Stewart @ 2008-10-21  0:25 UTC (permalink / raw)
  To: help-gnu-emacs

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.


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

* Re: Knowing the name of a file from the file itself
  2008-10-20 23:04 Knowing the name of a file from the file itself abc
  2008-10-21  0:25 ` Andy Stewart
@ 2008-10-21  1:28 ` Andreas Politz
  2008-10-21 10:13   ` abc
  1 sibling, 1 reply; 4+ messages in thread
From: Andreas Politz @ 2008-10-21  1:28 UTC (permalink / raw)
  To: help-gnu-emacs

abc wrote:
> 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.

I think `load-file-name' is what you are looking for.


,----[ C-h v load-file-name RET ]
| load-file-name is a variable defined in `C source code'.
| Its value is nil
|
|
| Documentation:
| Full name of file being loaded by `load'.
|
`----


-ap


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

* Re: Knowing the name of a file from the file itself
  2008-10-21  1:28 ` Andreas Politz
@ 2008-10-21 10:13   ` abc
  0 siblings, 0 replies; 4+ messages in thread
From: abc @ 2008-10-21 10:13 UTC (permalink / raw)
  To: help-gnu-emacs

load-file-name was exactly what I was looking for. Thank you both for
your explanations.


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

end of thread, other threads:[~2008-10-21 10:13 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-10-20 23:04 Knowing the name of a file from the file itself abc
2008-10-21  0:25 ` Andy Stewart
2008-10-21  1:28 ` Andreas Politz
2008-10-21 10:13   ` abc

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.