English 中文(简体)
向小型飞机壳指挥部通过Emacs变量
原标题:Passing Emacs variables to minibuffer shell commands

我可以很快地通过点击M-!。 我想要做的一件事就是在本档案中迅速开展行动。 举例说,通过武力检查档案:

M-!p4 edit/69/-file-name

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

当然,在将指挥权送至军阀之前,没有对<代码>-名称变量进行评价。

这样做是否容易? 或者,我是否必须发挥习惯的作用?

最佳回答

确实使用C-u M-:几乎正确。 http://code>shell-quote-argument in eval-to-shell-argument 因为它只进行插图,使得无法使用<代码>------------------------------------------------------------------------------------------------------- 你们可以尝试这样的东西:

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

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.

问题回答

在<代码>M-!后(shell-command)新闻<down>, 您将及时查阅档案。 现在,你可以把你想要接下去的指挥器加起来。

http://www.ohchr.org。 该文件将给您的 cur。

页: 1

(defun execute-shell-command-on-buffer (shell-command-text)
    (interactive "MShell command:")
    (shell-command (format shell-command-text (shell-quote-argument buffer-file-name)))
    )

https://gist.github.com/2367513

我现在要谈谈:

M->>p4 edit %s <

我坚决接受这一回答,因为我确实要求采取不需要职能的解决办法。

您可使用<代码>C-u M-: (eval-expression,附有普遍预设理由),以评价任何李平表达方式,并在目前的缓冲中添加其价值(包括只要您有,可回收-minibuffers,即为非nil值)。

您的例子:C-u M-:缓冲-file-name RET

注:该表述的结果以Lisp形式印刷:也就是说,以下述方式引证:read的后继呼吁将形成 Equal。 销售价值。 对于扼杀,这意味着重复引用,这或许会被解释为你期望低劣。 然而,你可能会遇到一些带有特殊特征的扼杀问题,需要Eliesp和壳牌不同的穿梭。

更正确的方式使用<代码>shell-quote-argument,如梅毒解决办法。 这里的缩略语是“自由表达”一词,在适当引述的字句中添加其价值:

(defun eval-to-shell-argument (form)
  (interactive "XEval: ")
  (insert (shell-quote-argument form)))

The read-and-evaluate step happens automatically by using an "X" as the argument to interactive.

www.un.org/spanish/ecosoc 加入: 如@tenpn notes,上述解决办法并不是为了在像一个<代码>这样的小型布置中添加诸如<代码>buffer-file-name等缓冲-当地变量。 M-! popsup(更确切地说,它增加了小型水土的缓冲-当地价值,这不大可能有用)。 这里是一份修订案文,似乎正在工作。 如果微型筹资活动活跃,则在阅读和评估一种表述时,使先前选定的窗口的缓冲暂时活跃。

Final edit: From @Stefan s answer I see that I should have used (minibuffer-selected-window) to find the previously-selected window. I ve also added a (format "%s" ..) to allow inserting non-string values, while still quoting special characters in strings. Here s the final version:

(defun eval-to-shell-argument ()
  (interactive)
  (let* ((buffer
          (if (minibufferp)
              (window-buffer (minibuffer-selected-window))
            (current-buffer)))
         (result
          (with-current-buffer buffer
            (eval-minibuffer "Eval: "))))
    (insert (shell-quote-argument (format "%s" result)))))

您可以用M-!做这项工作,但你可以评估小型面包店的任意损耗,这样写出一项功能就绝对必要:

M-: (shell-command (format "p4 edit %s” (shell-quote-argument Muz-file-name))

然而,我想到<代码>eshell。 你们想要的是:

M-x>eshell-commandp4 edit (evalkir-file-name)

Edit: Except unfortunately that doesn t work, as the *eshell cmd* buffer is selected when that is evaluated. One solution would be:

M-x>eshell-command>p4 edit (evalkir-file-name (other-buffer nil t)

(无代表,无争议)

每个人都似乎正在推出自己的版本,这里就是地雷——它将取代目前的档案名称或标志可怕的档案或目前可怕的档案,只要有<%>>>>>>>>>><<>>>>/代码>。 遵循与<代码>相同的公约。 M-!,因此我对此有约束力。

(defun my-shell-command (command &optional output-buffer error-buffer)
  "Run a shell command with the current file (or marked dired files).
In the shell command, the file(s) will be substituted wherever a  %  is."
  (interactive (list (read-from-minibuffer "Shell command: "
                                           nil nil nil  shell-command-history)
                     current-prefix-arg
                     shell-command-default-error-buffer))
  (cond ((buffer-file-name)
         (setq command (replace-regexp-in-string "%" (buffer-file-name) command nil t)))
        ((and (equal major-mode  dired-mode) (save-excursion (dired-move-to-filename)))
         (setq command (replace-regexp-in-string "%" (mapconcat  identity (dired-get-marked-files) " ") command nil t))))
  (shell-command command output-buffer error-buffer))




相关问题
suppress additional braces in emacs electric mode

I started using ruby-electric-mode. I like it except that I am used to closing open brackets myself (the other pairing are still useful to me). How can I make emacs suppress additional brackets when ...

Setting up an emacs environment in windows?

I am currently constrained to a windows dev box and I want to migrate my projects from eclipse to emacs. What are some good references on setting up an emacs dev environment for windows? Anything ...

Emacs Setting which-function-mode

I would like to have which-function-mode on by default when I open up Emacs. I ve added the following lines to my .emacs file. (setq which-func-mode t) (setq which-function-mode t) When I open ...

Enabling go mode for emacs

I don t seem to be able to enable a go mode for emacs. C mode doesn t work without semicolons. The best I have found is the JavaScript mode by Karl Landstrom, since JavaScript also doesn t require ...

Custom Emacs key bindings are not working

The key bindings I ve defined in my .emacs file aren t working. Here s the file: ;init modes (menu-bar-mode 0) (tool-bar-mode 0) (cua-mode) (column-number-mode) (fset perl-mode cperl-mode) (cperl-...

eval during emacs lisp macro expansion

How can I fix the simple macro foo in (elisp)Eval During Expansion? None of the followings work: (defmacro foo1 (a) `(setq (eval ,a) t)) (defmacro foo2 (a) `(setq ,(eval a) t)) (defmacro foo3 (...

Get local cvs comment history when committing file/s in emacs

I often commit files with similar cvs comment but not in a single operation. I would like to able to bring up previous comments I ve used in a previous commit when I am in the process of writing a ...

热门标签