0

How can I tell emacs/e-lisp to check if a user defined variable is a full path to a file or just a folder name? Currently, for one particular mode, user can just define variable for a sqlite database as a folder, and as a result, get database error which is not very informative.

If it matters, the variable is org-roam-db-location and default value is defined in org-roam-db.el as:

(defcustom org-roam-db-location (locate-user-emacs-file "org-roam.db")
  "The path to file where the Org-roam database is stored.

It is the user's responsibility to set this correctly, especially
when used with multiple Org-roam instances."
  :type 'string
  :group 'org-roam)

1 Answer 1

2

You can check using the functions file-directory-p and/or file-regular-p:

(file-directory-p org-roam-db-location)

will return t if it is a directory (a "folder") and nil otherwise.

Similarly

(file-regular-p org-roam-db-location)

will return t if it is a regular file and nil otherwise.

1
  • Thanks, this is exactly what I was looking for.
    – kakk11
    Commented Jul 21 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.