【问题标题】:An alternative find file function with the same default folder, every time每次使用相同默认文件夹的替代查找文件功能
【发布时间】:2013-11-06 14:28:28
【问题描述】:

我想绑定 super 和 9 以打开“查找文件:”,“Cx Cf”菜单,在用户输入字段中以 ~/x/ 作为“默认路径”,无论我的文件是哪个目录目前已经开放。不幸的是,我的 elisp 技能非常基础。非常感谢您对此提供帮助。

(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."
())

【问题讨论】:

    标签: emacs editor elisp


    【解决方案1】:

    只需定义一个调用read-file-name 的命令,并将您想要的目录作为默认目录(在interactive 规范中),然后在读取的文件名上调用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——只需将~/x/ 作为其DIR 参数传递即可。

    有关详细信息,请参阅 Elisp 手册,节点 Reading File Names。 (C-h i;选择Elispi read-file-name。)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-18
      • 2013-06-26
      • 1970-01-01
      • 2017-12-08
      • 1970-01-01
      • 2013-12-31
      相关资源
      最近更新 更多