I want to add user's home folder (~) into the lsp-workspace-blacklist in the init file. Is it possible to achieve this in the init file?

I have tried (lsp-project-blacklist (quote ("~"))) but seems like ~ is not detected:

  • 1
    This issue seems to indicate that lsp-project-blacklist is obsolete. You might want to check the issue out and/or upgrade your lsp-mode before you do anything else.
    – NickD
    Sep 5, 2022 at 16:06

1 Answer 1


~ is a shell-ism. Try (setq lsp-project-blacklist (list (expand-file-name "~")))[1].

C-h f expand-file-name says:

Convert filename NAME to absolute, and canonicalize it.
Second arg DEFAULT-DIRECTORY is directory to start with if NAME is relative
(does not start with slash or tilde); both the directory name and
a directory’s file name are accepted.  If DEFAULT-DIRECTORY is nil or
missing, the current buffer’s value of ‘default-directory’ is used.
NAME should be a string that is a valid file name for the underlying

File name components that are ‘.’ are removed, and so are file name
components followed by ‘..’, along with the ‘..’ itself; note that
these simplifications are done without checking the resulting file
names in the file system.

Multiple consecutive slashes are collapsed into a single slash, except
at the beginning of the file name when they are significant (e.g., UNC
file names on MS-Windows.)

An initial "~" in NAME expands to your home directory.

An initial "~USER" in NAME expands to USER’s home directory.  If
USER doesn’t exist, "~USER" is not expanded.

To do other file name substitutions, see ‘substitute-in-file-name’.

It's a handy function to keep in mind.

[1] I assume that lsp-project-blacklist is a list of paths, but I don't actually know what its type is, so this is just a suggestion to try.

  • So should I do: (lsp-project-blacklist (quote ((expand-file-name "~")))) ?
    – alper
    Sep 3, 2022 at 9:53
  • No, quote would inhibit evaluation: you want to evaluate the expand-filename, so you can use the backquote mechanism or construct the list expicitly. I've added a suggestion using the explicit construction, but heed the caveat in the footnote.
    – NickD
    Sep 3, 2022 at 16:01
  • ) is missing at the end of (setq lsp-project-blacklist .. line
    – alper
    Sep 3, 2022 at 19:11
  • Fixed - thanks!
    – NickD
    Sep 3, 2022 at 20:35
  • I have tested and it works but it blacklists all the subfolders as well: File '/home/alper/work/Driver.py' is in blacklisted directory '/home/alper/' ; do you think could we force to consider only /home/user but exclude its subfolders from the blacklist
    – alper
    Sep 5, 2022 at 13:30

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.