我在这里找到了替换文件位置的函数,但似乎无法正常工作:http://www.emacswiki.org/emacs/InsertFileName。它能够正确找到指定位置的文件,但从我看来,它似乎使用了你输入的文件而不是最初检测到的文件。我不确定如何解决这个问题。
如果我在 /home/testfile 上运行该函数,
首先,它会说要替换的文件,例如:/home/secondfile 然后它会说:用'/home/secondfile'替换:/home/secondfile 然后它会说:没有在指定位置找到文件
有什么想法吗?
下面是这个函数:
如果我在 /home/testfile 上运行该函数,
首先,它会说要替换的文件,例如:/home/secondfile 然后它会说:用'/home/secondfile'替换:/home/secondfile 然后它会说:没有在指定位置找到文件
有什么想法吗?
下面是这个函数:
(autoload 'ffap-guesser "ffap")
(autoload 'ffap-read-file-or-url "ffap")
(defun my-replace-file-at-point (currfile newfile)
"Replace CURRFILE at point with NEWFILE.
When interactive, CURRFILE will need to be confirmed by user
and will need to exist on the file system to be recognized,
unless it is a URL.
NEWFILE does not need to exist. However, Emacs's minibuffer
completion can help if it needs to be.
"
(interactive
(let ((currfile (ffap-read-file-or-url "Replace filename: "
(ffap-guesser))))
(list currfile
(ffap-read-file-or-url (format "Replace `%s' with: "
currfile) currfile))))
(save-match-data
(if (or (looking-at (regexp-quote currfile))
(let ((filelen (length currfile))
(opoint (point))
(limit (+ (point) (length currfile))))
(save-excursion
(goto-char (1- filelen))
(and (search-forward currfile limit
'noerror)
(< (match-beginning 0) opoint))
(>= (match-end 0) opoint))))
(replace-match newfile)
(error "No file at point to replace"))))