emacs - dired-directory 的值

标签 emacs elisp dired

我想在当前缓冲区的位置运行一个脚本,或者,如果它是一个 dired 缓冲区 - 在当前 dired 目录上运行脚本。当前目录似乎存储在 dired-directory多变的。确实如此 - 但是当我尝试使用它时 - 它有时会给我以前的目录而不是当前的目录:

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

如何让 defun 获得 dired 当前目录的正确值?

最佳答案

您可以使用变量 default-directory .

在这种情况下,您无需检查是否处于 dired 模式。

关于emacs - dired-directory 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10772821/

相关文章:

emacs - 在 Emacs 字体锁定模式中对字符串文字中的变量引用进行字体化

emacs - 如何确定一个包是否安装在elisp中?

regex - Emacs 在每个单词周围添加引号

emacs - 在不活动期间隐藏 Emacs 回显区域

emacs - org 模式下的内联 PDF 图像

emacs - 从交互函数内部调用kill-rectangle

emacs/elisp 使用 dired/file 对话框选择文件,然后执行操作?

emacs - 如何在 Emacs 中 [tar 和] 压缩标记的文件

emacs - 使用 ido.el 在 emacs 上使用 dired 复制粘贴各种文件

emacs - 将缓冲区发送到 emacs 中的 repl