在VIM中,可以使用%
在调用shell命令时指示当前文件名。任何人都可以指向我的文档方向,显示emacs中的等价物吗?
答案 0 :(得分:4)
没有一个。但这是Emacs!所以这里:
(defun my-shell-command-on-current-file (command &optional output-buffer error-buffer)
"Run a shell command on 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))
(global-set-key (kbd "M-!") 'my-shell-command-on-current-file)
答案 1 :(得分:1)
只要迷你缓冲区希望你输入内容,你就可以使用它(警告:不能用于ido,但显然你总能用例如C-x C-f来解决这个问题)。您也可以在常规缓冲区中使用它。
(defun insert-filename-or-buffername (&optional arg)
"If the buffer has a file, insert the base name of that file.
Otherwise insert the buffer name. With prefix argument, insert the full file name."
(interactive "P")
(let* ((buffer (window-buffer (minibuffer-selected-window)))
(file-path-maybe (buffer-file-name buffer)))
(insert (if file-path-maybe
(if arg
file-path-maybe
(file-name-nondirectory file-path-maybe))
(buffer-name buffer)))))
(define-key minibuffer-local-map (kbd "C-c f") 'insert-filename-or-buffername)
答案 2 :(得分:0)
在我的情况下,使用来自自制软件的emacs 24 gui版本....我看到文件名是(小) - 模式栏左下角的第3项,就在迷你缓冲区的上方。
要查看我的位置,使用ido-mode我只需C-x C-f
无需配置。