I found this macro, to run code for specific project path:
(defmacro project-specifics (name &rest body)
`(progn
(add-hook 'find-file-hook
(lambda ()
(when (string-match-p ,name (buffer-file-name))
,@body)))
(add-hook 'dired-after-readin-hook
(lambda ()
(when (string-match-p ,name (dired-current-directory))
,@body)))))
and I use it:
(project-specifics "projects/test"
(message "z"))
And I work on modification that will remove prevoius lambda from the hook, so far I have helper functions
(defun remove-lambda-helper (list matcher)
(dolist (item list)
(if (and (listp item) (eq (car item) 'lambda))
(when (funcall matcher item)
(message "found")
(setq list (delete item list))))))
(defun remove-hook-name-lambda (name hook)
(remove-lambda-helper hook
(lambda (body)
(equal (cadr (cadr (caddr body))) name))))
But when I call:
(remove-hook-name-lambda "projects/test" find-file-hook)
found is show up in *Messages*
buffer but the lambda is not removed. What's wrong here?