Emacs: default dir for (interactive “f”)

好久不见. 提交于 2019-12-12 17:19:16

问题


I am writing a simple hacky solution to switch between «projects» (sets of buffers and frames (X windows)) on top of DesktopAid. I made a procedure to write a project file:

(defun project-save-as (project-filename)
  "Save the current session to a new project session file."
  (interactive "FProject file to write: ")
  (copy-file project-default project-filename t)
  ; New project is the new current project.
  (write-cur-project-file project-filename)
  (set-variable 'cur-project-filename project-filename)
  (copy-file cur-project-filename project-default t)
 )

But it's annoying to navigate to the directory with project files each time. Is there a way to set a default directory for (interactive) without altering global variables?

Update: here is my (somewhat silly) code, if anybody is interested → http://paste.lisp.org/display/129116


回答1:


You can easily roll your own interactive functionality, by passing it a form which evaluates to the list of arguments for your function.

In this case you could call read-file-name directly with a hard-coded default directory argument if you wanted to avoid creating a new variable (although it does seem like the sort of thing that you would use a variable for).

e.g.:

(interactive
  (list (read-file-name "Project file to write: " "~/")))


来源:https://stackoverflow.com/questions/10278934/emacs-default-dir-for-interactive-f

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!