将Emacs变量传递给minibuffer shell命令 [英] Passing Emacs variables to minibuffer shell commands

查看:96
本文介绍了将Emacs变量传递给minibuffer shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过点击 M - !快速运行shell命令。我想做的一件事是对当前文件执行shell快速操作。一个例子是通过perforce检查文件:

I can run a shell command quickly by hitting M-!. One thing I'd like to do is perform shell quick operations on the current file. An example would be checking the file out through perforce:

M - ! p4 edit buffer-file-name RET

(是的,有强制整合,但我对minishell /变量问题更感兴趣,而不是一个特定的工作流程)

(Yes there are perforce integrations, but I'm more interested in the minishell/variable problem rather than a specific workflow)

当然,在发送命令之前,不评估 buffer-file-name 变量到这个shell。

Of course, the buffer-file-name variable is not evaluated before the command is sent to the shell.

有没有一个容易的飞行方法呢?或者我必须滚动自定义的elisp函数?

Is there an easy on-the-fly way to do this? Or will I have to roll a custom elisp function?

推荐答案

确实使用C-u M-:几乎是正确的。我不太确定在 eval-to-shell-argument 中使用 shell-quote-argument ,因为它只在字符串上工作,使得不可能使用 eval-to-shell-argument 插入一个数字或符号。您可以尝试以下方式:

Indeed using C-u M-: is almost right. I'm not so sure about using shell-quote-argument in eval-to-shell-argument since it only works on strings making it impossible to use eval-to-shell-argument to insert a number or a symbol. You could try something like:

(defun sm-minibuffer-insert-val (exp)
  (interactive
   (list (let ((enable-recursive-minibuffers t))
           (read-from-minibuffer "Insert: "
                                 nil read-expression-map t
                                 'read-expression-history))))
    (let ((val (with-selected-window (minibuffer-selected-window)
                 (eval exp)))
          (standard-output (current-buffer)))
      (prin1 val)))

然后将此函数绑定到您的minibuffer中(define-key minibuffer-local-map [?\M-:]'sm-minibuffer-insert-val)
当然,如果你想插入的唯一的东西是buffer-file-name,那么你的 execute-shell-command-on-buffer 更简单。

and then bind this function in your minibuffer with (define-key minibuffer-local-map [?\M-:] 'sm-minibuffer-insert-val). Of course, if the only thing you ever want to insert is the buffer-file-name, then your execute-shell-command-on-buffer is simpler.

这篇关于将Emacs变量传递给minibuffer shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆