本文介绍了如何在Emacs中重命名一个打开的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在Emacs中重命名一个打开的文件?当我正在查看它?某些东西就像保存一样,但是原来的一个应该消失。解决方案
从:
;;来源:http://steve.yegge.googlepages.com/my-dot-emacs-file
(defun rename-file-and-buffer(new-name)
重命名当前的缓冲区和文件
(交互式新名称)
(let((name(buffer-name))
(filename(buffer-file-name)))
(如果(不是文件名)
(消息缓冲区'%s'不访问文件!)
(if(get-buffer new-name)
消息名为'%s'的缓冲区已经存在!new-name
(progn
(rename-file filename new-name 1)
(rename-buffer new-name)
(set-visited-file-name new-name)
(set-buffer-modified-p nil))))))
看看该页面,还有一个非常有用的相关功能,称为移动缓冲区文件。
Is there a way to rename an open file in Emacs? While I'm viewing it? Something like save-as, but the original one should go away.
解决方案
Try this function from Steve Yegge's .emacs:
;; source: http://steve.yegge.googlepages.com/my-dot-emacs-file (defun rename-file-and-buffer (new-name) "Renames both current buffer and file it's visiting to NEW-NAME." (interactive "sNew name: ") (let ((name (buffer-name)) (filename (buffer-file-name))) (if (not filename) (message "Buffer '%s' is not visiting a file!" name) (if (get-buffer new-name) (message "A buffer named '%s' already exists!" new-name) (progn (rename-file filename new-name 1) (rename-buffer new-name) (set-visited-file-name new-name) (set-buffer-modified-p nil))))))
Take a look at that page, there's another really useful related function there, called "move-buffer-file".
这篇关于如何在Emacs中重命名一个打开的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!