Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs: default dir for (interactive "f")

Tags:

emacs

elisp

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

like image 744
Mischa Arefiev Avatar asked Nov 30 '25 16:11

Mischa Arefiev


1 Answers

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: " "~/")))
like image 143
phils Avatar answered Dec 02 '25 06:12

phils



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!