unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Jump to directory from a *Locate* buffer
@ 2015-01-14 21:35 Marcin Borkowski
  2015-01-14 22:57 ` Bob Proulx
  0 siblings, 1 reply; 5+ messages in thread
From: Marcin Borkowski @ 2015-01-14 21:35 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hi list,

imagine that I run M-x locate to find some file, and I want to open
Dired in the directory one of the found files is in.  Is there a way to
do it or should I write some Elisp for that?

TIA,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: Jump to directory from a *Locate* buffer
  2015-01-14 21:35 Jump to directory from a *Locate* buffer Marcin Borkowski
@ 2015-01-14 22:57 ` Bob Proulx
  2015-01-15  0:53   ` Marcin Borkowski
  0 siblings, 1 reply; 5+ messages in thread
From: Bob Proulx @ 2015-01-14 22:57 UTC (permalink / raw)
  To: help-gnu-emacs

Marcin Borkowski wrote:
> imagine that I run M-x locate to find some file, and I want to open
> Dired in the directory one of the found files is in.  Is there a way to
> do it or should I write some Elisp for that?

What I do in that situation, already at the beginning of the file
name, is to C-space to set the mark then C-f to the end of the
directory name.  Then M-w copy to the kill ring.  Then C-x C-f C-y RET
to find-file and yank in the directory and open it in dired mode.

However using locate generates a dired buffer meaning all of those
commands are available too.  The 'w' command copies the filename.  The
0w command copies the full pathname of the file.  Therefore an
alternative could be to 0w on that filename to copy the entire full
pathname to the kill ring.  Then C-x C-f C-y and then DEL or M-DEL to
delete the filename part and then RET when the path is just the
directory name.

I am sure there are other ways too.

Bob



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

* Re: Jump to directory from a *Locate* buffer
  2015-01-14 22:57 ` Bob Proulx
@ 2015-01-15  0:53   ` Marcin Borkowski
  2015-01-15  1:14     ` John Mastro
  0 siblings, 1 reply; 5+ messages in thread
From: Marcin Borkowski @ 2015-01-15  0:53 UTC (permalink / raw)
  To: help-gnu-emacs


On 2015-01-14, at 23:57, Bob Proulx <bob@proulx.com> wrote:

> Marcin Borkowski wrote:
>> imagine that I run M-x locate to find some file, and I want to open
>> Dired in the directory one of the found files is in.  Is there a way to
>> do it or should I write some Elisp for that?
>
> What I do in that situation, already at the beginning of the file
> name, is to C-space to set the mark then C-f to the end of the
> directory name.  Then M-w copy to the kill ring.  Then C-x C-f C-y RET
> to find-file and yank in the directory and open it in dired mode.
>
> However using locate generates a dired buffer meaning all of those
> commands are available too.  The 'w' command copies the filename.  The
> 0w command copies the full pathname of the file.  Therefore an
> alternative could be to 0w on that filename to copy the entire full
> pathname to the kill ring.  Then C-x C-f C-y and then DEL or M-DEL to
> delete the filename part and then RET when the path is just the
> directory name.

Thanks, though neither of your ways is very, let's say, "Emacs-ish": you
wouldn't win the Emacs Golf contest with them.  (Neither would I, for
that matter: my usual method is to open a file in the *Locate* list and
then hit C-x C-d RET.)

> I am sure there are other ways too.

Definitely there /should/ be.  And if there are not, someone has to code
them.  (I need this almost on a daily basis, so it's definitely worth
optimizing.)

> Bob

Best,

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

* Re: Jump to directory from a *Locate* buffer
  2015-01-15  0:53   ` Marcin Borkowski
@ 2015-01-15  1:14     ` John Mastro
  2015-01-15  5:52       ` Marcin Borkowski
  0 siblings, 1 reply; 5+ messages in thread
From: John Mastro @ 2015-01-15  1:14 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org; +Cc: Marcin Borkowski

Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:
> Definitely there /should/ be.  And if there are not, someone has to code
> them.  (I need this almost on a daily basis, so it's definitely worth
> optimizing.)

If I understand the situation correctly, something like this is all it
takes.

    (defun locate-open-in-dired (file)
      (interactive (list (dired-filename-at-point)))
      (cond ((file-directory-p file)
             (dired file))
            ((file-regular-p file)
             (dired (file-name-directory file)))
            (t
             (error "Not a file: '%s'" file))))

    (define-key locate-mode-map (kbd "C-c d") #'locate-open-in-dired)

-- 
john



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

* Re: Jump to directory from a *Locate* buffer
  2015-01-15  1:14     ` John Mastro
@ 2015-01-15  5:52       ` Marcin Borkowski
  0 siblings, 0 replies; 5+ messages in thread
From: Marcin Borkowski @ 2015-01-15  5:52 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org


On 2015-01-15, at 02:14, John Mastro <john.b.mastro@gmail.com> wrote:

> Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:
>> Definitely there /should/ be.  And if there are not, someone has to code
>> them.  (I need this almost on a daily basis, so it's definitely worth
>> optimizing.)
>
> If I understand the situation correctly, something like this is all it
> takes.
>
>     (defun locate-open-in-dired (file)
>       (interactive (list (dired-filename-at-point)))
>       (cond ((file-directory-p file)
>              (dired file))
>             ((file-regular-p file)
>              (dired (file-name-directory file)))
>             (t
>              (error "Not a file: '%s'" file))))
>
>     (define-key locate-mode-map (kbd "C-c d") #'locate-open-in-dired)

Looks like it should.  Thanks!  I'll check it ASAP.

-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



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

end of thread, other threads:[~2015-01-15  5:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-14 21:35 Jump to directory from a *Locate* buffer Marcin Borkowski
2015-01-14 22:57 ` Bob Proulx
2015-01-15  0:53   ` Marcin Borkowski
2015-01-15  1:14     ` John Mastro
2015-01-15  5:52       ` Marcin Borkowski

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