我希望绑定super 9来打开"find file:“、”C“菜单,并将~/x/作为用户输入字段中的”默认路径“,不管我当前打开的文件位于哪个目录。不幸的是,我的私奔技能非常基本。我真的很想在这方面提供一些帮助。
(global-set-key (kbd "s-9") 'enter_find_file_with_dir_x_as_default)
(defun enter_find_file_with_dir_x_as_default ()
"Enter find file with the path ~/x/ as the default input every time."
())发布于 2013-10-27 22:23:25
只需定义一个命令,使用您想要的目录(在read-file-name规范中)调用interactive,然后对文件名read调用find-file。
(defun my-find-file (file)
"..."
(interactive (list (read-file-name "File: " "~/x/")))
(find-file file))请参阅read-file-name文档,以决定您可能需要哪些其他参数(例如,您是只接受现有的文件名还是允许一个新的文件缓冲区)。
还要注意,如果您想将它绑定到一个键,那么它必须是一个命令,所以它需要一个interactive规范。如果您只想要一个从目录~/x/开始读取文件名的函数,那么答案是read-file-name --只需将它作为DIR参数传递给它。
有关更多信息,请参见Elisp手册节点Reading File Names。(C-h i;选择Elisp;i read-file-name.)
https://stackoverflow.com/questions/19624255
复制相似问题