问题
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