Function: treemacs-is-path
treemacs-is-path is a macro defined in treemacs-macros.el.
Signature
(treemacs-is-path LEFT OP &optional RIGHT)
Documentation
Readable utility macro for various path predicates.
LEFT is a file path, OP is the operator and RIGHT is either a path, project, or workspace. OP can be one of the following:
* :same-as will check for string equality.
* :in will check will check whether LEFT is a child or the same as RIGHT.
* :directly-in will check will check whether LEFT is *direct* child of RIGHT.
* :parent-of will check whether LEFT is a parent of, and not equal to, RIGHT.
* :in-project will check whether LEFT is part of the project RIGHT.
* :in-workspace will check whether LEFT is part of the workspace RIGHT and
return the appropriate project when it is. If RIGHT is not given it will
default to calling treemacs-current-workspace.
LEFT and RIGHT are expected to be in treemacs canonical file path format (see
also treemacs-canonical-path).
Even if LEFT or RIGHT should be a form and not a variable it is guaranteed that they will be evaluated only once.
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-macros.el
(defmacro treemacs-is-path (left op &optional right)
"Readable utility macro for various path predicates.
LEFT is a file path, OP is the operator and RIGHT is either a path, project, or
workspace. OP can be one of the following:
* `:same-as' will check for string equality.
* `:in' will check will check whether LEFT is a child or the same as RIGHT.
* `:directly-in' will check will check whether LEFT is *direct* child of RIGHT.
* `:parent-of' will check whether LEFT is a parent of, and not equal to, RIGHT.
* `:in-project' will check whether LEFT is part of the project RIGHT.
* `:in-workspace' will check whether LEFT is part of the workspace RIGHT and
return the appropriate project when it is. If RIGHT is not given it will
default to calling `treemacs-current-workspace'.
LEFT and RIGHT are expected to be in treemacs canonical file path format (see
also `treemacs-canonical-path').
Even if LEFT or RIGHT should be a form and not a variable it is guaranteed that
they will be evaluated only once."
(declare (debug (&rest form)))
(treemacs-static-assert (memq op '(:same-as :in :directly-in :parent-of :in-project :in-workspace))
"Invalid treemacs-is-path operator: `%s'" op)
(treemacs-static-assert (or (eq op :in-workspace) right)
"Right-side argument is required")
(macroexp-let2* nil
((left left)
(right right))
(pcase op
(:same-as
`(string= ,left ,right))
(:in
`(or (string= ,left ,right)
(s-starts-with? (treemacs--add-trailing-slash ,right) ,left)))
(:directly-in
`(let ((l (length ,right)))
(and (> (length ,left) l)
(string= (treemacs--filename ,left) (substring ,left (1+ l)))
(string-prefix-p ,right ,left))))
(:parent-of
`(and (s-starts-with? (treemacs--add-trailing-slash ,left) ,right)
(not (string= ,left ,right))))
(:in-project
`(treemacs-is-path ,left :in (treemacs-project->path ,right)))
(:in-workspace
(-let [ws (or right '(treemacs-current-workspace))]
`(--first (treemacs-is-path ,left :in-project it)
(treemacs-workspace->projects ,ws)))))))