于是现在在写一个定位project
的函数:
(defvar aucoda/project-files
'("compile_commands.json" ".clang_complete" ".cquery" ".ccls")
"Files to locate project root.
Root could be folders including these files or
their parent folder if they are build folders.")
(defun aucoda/find-files-in (dir files)
"Return the full path of found file or nil if not found.
DIR and its parents will be searched.
FILES is a list of files to be found."
(let ((json-cdb-p (lambda (json-cdb-p dir file skip-children-p)
(let ((file-path (concat dir (concat "/" file))))
(if (file-exists-p file-path) file-path
(if skip-children-p nil
(or (mapcan
(lambda (dir)
(funcall json-cdb-p json-cdb-p dir file t))
(directory-files dir t))))))))
(aux (lambda (aux json-cdb-p dir)
(let ((dir (directory-file-name dir)))
(let ((file-path
(or (mapcan
(lambda (file)
(funcall json-cdb-p json-cdb-p dir file nil))
files))))
(if file-path file-path
(let ((parent-dir (file-name-directory dir)))
(when parent-dir
(funcall aux aux json-cdb-p parent-dir)))))))))
(funcall aux aux json-cdb-p (expand-file-name dir))))
(defun aucoda/project-aucoda (dir)
"Return nil if project files not found or project instance.
DIR is required by `project-find-functions`."
(let ((file (aucoda/find-files-in dir aucoda/project-files)))
(if file (cons 'transient (file-name-directory file)) nil)))
但是会报:
File mode specification error: (wrong-type-argument consp /absolute/path/to/.cquery)
or: Wrong type argument: consp, "/absolute/path/to/.cquery"
Error in post-command-hook (#[0 "\303\304\301\242\305#\210\300\306!\205\0r\211q\210
?\205\0\307\310\311 \")\207" [#<buffer file.h> (#0) eglot--managed-mode remove-hook post-command-hook nil buffer-live-p apply eglot--connect eglot--guess-contact] 4]): (wrong-type-argument consp "/absolute/path/to/.cquery")
但是,自己在一个buffer
里执行(aucoda/find-files-in default-directory '("aucoda.el"))
是会正确返回找到的文件路径的。这个错误怎么来的呢?