help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: dired: goto directory of a file


From: Kevin Rodgers
Subject: Re: dired: goto directory of a file
Date: Thu, 15 Jan 2004 08:57:44 -0700
User-agent: Mozilla/5.0 (X11; U; SunOS i86pc; en-US; rv:0.9.4.1) Gecko/20020406 Netscape6/6.2.2

Barman Brakjoller wrote:

in a dired buffer (particu;ar in a dired-find buffer) it would be very
handy to be able to jump to the containing directory of a file:

eg. the dired buffer shows the line

 -rw-r--r--  1 leo  staff  618385 30 Nov 08:29 Audio/Apps/iCDc4.3.3.dmg.sit

then just jump to the directory Audio/Apps in a new dired window.


I came up with the following function which works in most cases I
guess:

(defun dired-open-containing-directory ()
  "Opens the directory where the file at point is located"
  (interactive)
  (let ((file (dired-filename-at-point)))
    (string-match "\\(.*/\\)" file)
    (find-file (substring file 0 (match-end 1)))))

Enjoy!

If there is some shorter/better way to extract the path from the full
filename and path, the function could be even shorter, but I didn't
find any function that does that.

C-h f file-name-directory


It's described in detail in the File Name Components node of the Emacs
Lisp manual; you might also want to browse the other subnodes of the
File Names node.

--
Kevin Rodgers



reply via email to

[Prev in Thread] Current Thread [Next in Thread]