Value of the dired-directory

只愿长相守 提交于 2019-12-20 01:40:55

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/10772821/value-of-the-dired-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!