在Emacs中,如何在shell命令中插入文件名? [英] In Emacs, how to insert file name in shell-command?

查看:121
本文介绍了在Emacs中,如何在shell命令中插入文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用shell命令很多(默认绑定到M-!),但是我经常在正在编辑的缓冲区中做东西。而不是键入缓冲区名称(并且没有文件名完成在shell命令中可用,唉!),只要有一个快捷键(如f3),只要按下键,就可以为我插入该名称。 p>

问题是我不想全局绑定密钥(我在其他上下文中使用f3作为其他的东西),只有在shell命令提示时才使用minibuffer。编写一个lisp函数来插入当前的缓冲区名称很容易,但是我应该修改什么模式的keymap来绑定一个键到该函数?



或者,是否有任何lisp代码/包在shell命令中提供文件名完成,类似于bash?我知道正常的Mx shell完成,但是在minibuff中输入命令的方便很难放弃;)



编辑: / p>

这是我想要的,取自 huaiyuan 的答案来自 http://osdir.com/ml/emacs.sources/2002-04/msg00022.html

 (define-key minibuffer-local-map 
[f3](lambda()(interactive)
(insert(buffer-name(current-buffer-not -mini)))))

(defun current-buffer-not-mini()
如果当前缓冲区不是* mini-buffer,则返回当前缓冲区*

(if(not(window-minibuffer-p))(current-buffer)
(if(eq(get-lru-window)(next-window) )
(window-buffer(previous-window))(window-buffer(next-window))))​​)


解决方案

 (define-key minibuffer-local-map 
[f3](lambda()(interactive) ))))



编辑:



正如在评论部分和其他地方所指出的,上面的代码段不起作用。 (对不起,我应该在发布之前测试过:)。一些修复已经发布;这里是另一个:

 (define-key minibuffer-local-map [f3] 
(lambda )
(insert(buffer-name(window-buffer(minibuffer-selected-window))))​​))

关于发出 shell-command 的文件名完成,也许这个kludge可以工作(在Emacs 23.0.60上适用于我):

 (require'shell)
(define-key minibuffer-local-map(kbdCi)'comint-dynamic-complete)


I use shell-command a lots (default binded to M-!), but often I'm doing stuff to the buffer I'm currently editing. Instead of typing the buffer name (and no filename completion is available in shell-command, alas!), it'd be nice to have a shortcut key, say f3, to insert that name for me whenever I press the key.

The problem is I don't want to bind the key globally (I use f3 for other things in other context), only in minibuffer when shell-command is prompting. It's easy to write a lisp function to insert the current buffer name, but what mode's keymap should I modify to bind a key to that function?

Alternatively, is there any lisp code/package that provide filename completion in shell-command, similar to how bash does it? I know the normal M-x shell does completion, but the convenience of entering a command in minibuffer is hard to give up ;)

Edit:

here is what I wanted, taken from huaiyuan's answer with some fixes inspired by / stolen from http://osdir.com/ml/emacs.sources/2002-04/msg00022.html

(define-key minibuffer-local-map
  [f3] (lambda () (interactive) 
       (insert (buffer-name (current-buffer-not-mini)))))

(defun current-buffer-not-mini ()
  "Return current-buffer if current buffer is not the *mini-buffer*
  else return buffer before minibuf is activated."
  (if (not (window-minibuffer-p)) (current-buffer)
      (if (eq (get-lru-window) (next-window))
          (window-buffer (previous-window)) (window-buffer (next-window)))))

解决方案

(define-key minibuffer-local-map
  [f3] (lambda () (interactive) (insert (buffer-name))))

Edit:

As pointed out in the comment section and elsewhere, the above code snippet doesn't work. (Sorry, I should have tested it before posting. :) Some fixes have been posted; here is another:

(define-key minibuffer-local-map [f3]
  (lambda () (interactive) 
     (insert (buffer-name (window-buffer (minibuffer-selected-window))))))

Regarding filename completion while issuing shell-command, perhaps this kludge would work (it works for me on Emacs 23.0.60):

(require 'shell)
(define-key minibuffer-local-map (kbd "C-i") 'comint-dynamic-complete)

这篇关于在Emacs中,如何在shell命令中插入文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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