3

我有下面的函数,我.emacs经常使用它来将本地文件的文件名/路径放在当前缓冲区中。它工作得很好,但是,我希望它能够ido完成。但我似乎无法做到这一点......也许你可以帮助我。

(defun insert-file-name (filename &optional args)
  "Insert name of file FILENAME into buffer after point.

  Prefixed with \\[universal-argument], expand the file name to
  its fully canocalized path.  See `expand-file-name'.

  Prefixed with \\[negative-argument], use relative path to file
  name from current directory, `default-directory'.  See
  `file-relative-name'.

  The default with no prefix is to insert the file name exactly as
  it appears in the minibuffer prompt."
  ;; Based on insert-file in Emacs -- ashawley 20080926
  (interactive "*fInsert file name: \nP")
  (cond ((eq '- args)
         (insert (expand-file-name filename)))
        ((not (null args))
         (insert (filename)))
        (t
         (insert (file-relative-name filename)))))
4

1 回答 1

4

ido-everywhere开启后,(interactive "f")将正常使用,ido-read-file-name它不仅会为您的功能提供自动完成,而且几乎无处不在。

如果你只想为这个函数而不是任何地方都有 ido 补全,你可以ido-read-file-name在交互表单中显式调用。在您的情况下使用 ido 的一个副作用是它似乎总是返回一条完整的路径,从而区分filename(expand-file-name filename)无效。

(defun insert-file-name (filename &optional args)
  "Insert name of file FILENAME into buffer after point.

  Prefixed with \\[universal-argument], expand the file name to
  its fully canocalized path.  See `expand-file-name'.

  Prefixed with \\[negative-argument], use relative path to file
  name from current directory, `default-directory'.  See
  `file-relative-name'.

  The default with no prefix is to insert the file name exactly as
  it appears in the minibuffer prompt."
  ;; Based on insert-file in Emacs -- ashawley 20080926
  (interactive `(,(ido-read-file-name "File Name: ")
                 ,current-prefix-arg))
  (cond ((eq '- args)
         (insert (expand-file-name filename)))
        ((not (null args))
         (insert filename))
        (t
         (insert (file-relative-name filename)))))
于 2013-05-27T07:29:01.353 回答