Fix treemacs-add-project wrong type argument hash table p nil
After a recent cleanup of treemacs projects, I wanted to add again a known project:
~/src/django
Yet M-x treemacs-add-project returned
(wrong-type-argument hash-table-p nil)
Debugging with M-x debug-on-error gave away a suspicious gethash
call:
Debugger entered--Lisp error:
(wrong-type-argument hash-table-p nil)
gethash("/home/ra/src/django/crm" nil nil)
treemacs-add-project("/home/ra/src/django/")
...
gethash("/home/ra/src/django/crm" nil nil)
contains crm
. But why?
So I started digging in the treemacs options by calling M-x custom-options and found treemacs-persist-file
A short glance at that file gave away the problem:
cat ~/.emacs.default/.cache/treemacs-persist
...
* Default
** crm
- path :: ~/src/django/crm
...
The project was already there but only it’s subdir (crm) was added to treemacs. Mind that only the parent dir is versioned (.git).
Long story short 💡:
Check if a project’s subdirectory already exists in treemacs e.g. ~/src/django/crm
before attempting to add it’s versioned parent e.g. ~/src/django
.