meowking's Blog

meowking's Avatar Image
A Linux and Emacs enthusiast who loves anime and cats.

My Chinese gossip account: https://wxw.moe/@meow_king (talking nonsense
BG Image: https://wallhaven.cc/w/p93dx3
← All posts

Emacs lisp

How to quick implement a read-file-name function which behaves like project-find-file?

After reading the source code of project-find-file function, I find it is fairly simple to achieve this goal by adding advice to find-file function.

(defun mk/project-read-file-name ()
  (let ((find-file-advice (lambda (file-name) file-name)))
    (advice-add 'find-file :override find-file-advice)
    (unwind-protect
      (setq res (project-find-file t))
      (advice-remove 'find-file find-file-advice))))

Edit:
Use unwind-protect to make sure advice-remove can always be executed.

To like or reply, open original post on Emacs.ch