我在這裏找到了替換filen的函數,但它似乎無法正常工作:http://www.emacswiki.org/emacs/InsertFileName。它正確地找到了文件中的點,但替換似乎將您輸入的文件,而不是從我能看到的最初檢測到的文件。我不知道如何解決這個問題。替換emacs處的文件
如果我上的/ home/testfile的運行功能
首先,它說,文件替換等等,例如:/家庭/ secondfile 於是說更換一個 '/ home/secondfile' 有:/家庭/ 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"))))
謝謝!是的,它不能正常工作在完整的路徑名稱上,除非你使用expand-file-name,但正如你所說的用簡寫的版本替換它。如果它已經被擴展,或者最好只是擴展文件名,如果前綴arg(C-u)被傳遞給函數,是否有輕易強制擴展它的方法? – 2012-08-06 22:46:31