4

I am following this wiki suggestion to set up Emacs so that, i can move forward and backwards in dired mode without creating new buffers.

Using the a key together with the (put 'dired-find-alternate-file 'disabled nil) setting allows me to move into directories without new buffers.

But the hook for the ^ key mentioned in the wiki is not working for me. Going to previous directory with ^ still opens new buffers.

Here are the settings I am using in my .emacs.d/init.el

; dired settings
(require 'dired-x)
(setq dired-omit-files "^\\.?#\\|^\\.$\\|^\\.\\.$\\|^\\.")
(add-hook 'dired-mode-hook (lambda ()
                             (dired-omit-mode 1)))
(setq dired-listing-switches "-aBhl --group-directories-first")
(put 'dired-find-alternate-file 'disabled nil)
(add-hook 'dired-mode-hook
 (lambda ()
  (define-key dired-mode-map (kbd "^")
    (lambda () (interactive) (find-alternate-file "..")))))
Drew
  • 2,084
  • 11
  • 18
z33m
  • 183
  • 1
  • 7
  • Your code for the keyboard shortcut looks good -- if it's opening a new buffer, your keyboard shortcut is probably not being recognized for some reason -- if you do a `C-h k ^` you'll probably see that the default function `dired-up-directory` is still being called. Are the any error messages? I get errors when trying to load `dired-x` -- `Key sequence * O starts with non-prefix key *` – lawlist Jan 15 '14 at 21:30
  • I believe this is the case. The `define-key` keyboard shortcut is not getting recognized for some reason. If i type `M-x find-alternate-file` and then `..` it goes back without creating new buffer. Also `C-h k ^` shows that `^` is bound to `dired-up-directory`. I do not get any errors though. – z33m Jan 16 '14 at 04:42

1 Answers1

3

Just use Dired+. Use C-M-R to toggle whether to reuse Dired buffers. Put this in your init file if you want to reuse by default:

 (diredp-make-find-file-keys-reuse-dirs)

This also takes care of ^. In sum, no need to code anything - just load Dired+.

Drew
  • 2,084
  • 11
  • 18
  • I have installed dired+ over the package manager. It seems that the version of dired+ that gets installed doesnt have this function. Could i be getting outdated versions from the package archives? I have added marmalade to my `package-archives` list – z33m Jan 16 '14 at 05:06
  • @z33m -- Dunno what the problem could be. That function has been in `dired+.el` since 2010/01/21, as the Change Log in the file shows. Visit the file and see if you don't find that function. Does `C-h f` for that function name really tell you it is not defined, after you have loaded `dired+.el`? Note that this function is not a *command* -- you cannot invoke it using `M-x`. But you can evaluate the sexp I wrote using `M-:` (or using `C-x C-e` on it in, say, `*scratch*` or your init file). – Drew Jan 16 '14 at 18:30
  • yes i was trying to run it with `M-x`. i've added this command to my `init.el` and its working now. Thanks! – z33m Jan 16 '14 at 22:22