Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Value of the dired-directory

Tags:

emacs

elisp

dired

I wanted to run a script in the location of the current buffer, or, if it is a dired buffer - to run the script on the current dired directory. The current dired directory seems to be stored in dired-directory variable. Indeed it is - but when I try to make use of it - it sometimes gives me the previous dirs instead of the current one:

(defun bk-konsoles ()
  "Calls: bk-konsoles.bash"
  (interactive)
  (let ((curDir (if (memq major-mode '(dired-mode sr-mode)) dired-directory
                  (if (buffer-file-name) (file-name-directory (buffer-file-name))))))
    (shell-command (concat (expand-file-name "~/its/plts/goodies/bk-konsoles.bash ") curDir " & disown") nil nil)
    (kill-buffer "*Shell Command Output*")
    (delete-other-windows)))

How do I make the defun get the right value of the dired's current directory?

like image 311
Adobe Avatar asked Jan 16 '23 13:01

Adobe


1 Answers

You can use the variable default-directory.

In this case you don't need to check if you're in the dired mode or not.

like image 180
Oleg Pavliv Avatar answered Jan 19 '23 02:01

Oleg Pavliv