【问题标题】:emacs: How to Capture stdout from dired-do-shell-command?emacs:如何从 dired-do-shell-command 捕获标准输出?
【发布时间】:2015-04-22 21:33:16
【问题描述】:

在 Emacs 中,有没有办法捕获 dired-do-shell-command 的标准输出,比如 kill-ring?

不知道怎么做,我最终去了 Messages 缓冲区并从那里手动获取标准输出。

【问题讨论】:

    标签: emacs dired


    【解决方案1】:

    该命令的帮助说明输出到名为*Shell Command Output* 的缓冲区,假设命令没有&。如果是这种情况,这段代码会做你想做的事:

    (defun do-shell-and-copy-to-kill-ring (command &optional arg file-list)
      (interactive
       (let ((files (dired-get-marked-files t current-prefix-arg)))
         (list
          (dired-read-shell-command "! on %s: " current-prefix-arg files)
          current-prefix-arg
          files)))
      (dired-do-shell-command command arg file-list)
      (with-current-buffer "*Shell Command Output*"
        (copy-region-as-kill (point-min) (point-max))))
    

    对于异步命令,您需要等待它们并查看*Async Shell Command* 缓冲区。

    【讨论】:

    • 谢谢!我用它来将您的解决方案连接到我的设置中: (defun my-dired-mode-keys () "Modify keymaps used by `dired-mode'." (local-set-key (kbd "C-c d") 'do- shell-and-copy-to-kill-ring)) (add-hook 'dired-mode-hook 'my-dired-mode-keys)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-09
    • 1970-01-01
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    相关资源
    最近更新 更多