campbellm · 2022-08-12 13:06
I'm playing with fzf-el, but I don't like how fzf-find-file works since I'm a dired junkie and like to use C-x C-f for both files and dirs.
So, I tried this, hoping to use a universal arg when I want to fzf-find-file, and normal without.
(defun fzf-or-find-file ()
(interactive)
(if (equal current-prefix-arg nil)
(find-file)
(fzf-find-file)))
This works with C-u M-x fzf-or-find-file (the fzf version runs), but when I DON'T pass a Ctrl-u, find-file ... fails. I'm sure I'm calling it incorrectly here, but pointers welcome.
The failure looks like [this](https://i.imgur.com/A9eCKAq.png)
What'd I do wrong?
franburstall · 2022-08-12 14:11
`find-file` expects an argument when called from lisp and you are not supplying one. Try
(call-interactively #'find-file)
instead.
[deleted] · 2022-08-12 14:15
[deleted]
tancrauss · 2022-08-12 14:15
I was about to comment the same, this seems to work
campbellm · 2022-08-12 14:16
> (call-interactively #'find-file)
Perfect, thanks!
vifon · 2022-08-12 17:48
Apart from what the others said, use `(interactive "P")` and an argument instead of checking `current-prefix-arg` by hand. The final version I'd propose:
(defun fzf-or-find-file (arg)
(interactive "P")
(call-interactively (if arg
#'fzf-find-file
#'find-file)))
campbellm · 2022-08-12 18:44
Cool, thanks; that looks cleaner. At this stage with elisp I don't even know what I don't know, so all advice helpful.