Function: treemacs--validate-persist-lines
treemacs--validate-persist-lines is a byte-compiled function defined
in treemacs-persistence.el.
Signature
(treemacs--validate-persist-lines LINES &optional (CONTEXT :start) (PREV nil) (PATHS nil) (PROJ-COUNT 0) (WS-COUNT 0))
Documentation
Recursively verify the make-up of the given LINES, based on their CONTEXT.
Lines must start with a workspace name, followed by a project name, followed by the project's path property, followed by either the next project or the next workspace.
The previously looked at line type is given by CONTEXT.
The previously looked at line is given by PREV.
PATHS contains all the project paths previously seen in the current workspace. These are used to make sure that no file path appears in the workspaces more than once.
PROJ-COUNT counts the number of non-disabled projects in a workspace to make sure that there is at least one project that will be displayed.
WS-COUNT counts the number of non-disabled workspaces to make sure that there is at least one workspace that will be used.
A successful validation returns just the symbol 'success, in case of an error a list of 3 items is returned: the symbol 'error, the exact line where the error happened, and the error message. In some circumstances (for example when a project is missing a path property) it makes sense to display the error not in the currently looked at line, but the one above, which is why the previously looked at line PREV is given as well.
LINES: List of Strings CONTEXT: Keyword PREV: String PATHS: List<String> PROJ-COUNT: Int
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-persistence.el
(cl-defun treemacs--validate-persist-lines
(lines
&optional
(context :start)
(prev nil)
(paths nil)
(proj-count 0)
(ws-count 0))
"Recursively verify the make-up of the given LINES, based on their CONTEXT.
Lines must start with a workspace name, followed by a project name, followed by
the project's path property, followed by either the next project or the next
workspace.
The previously looked at line type is given by CONTEXT.
The previously looked at line is given by PREV.
PATHS contains all the project paths previously seen in the current workspace.
These are used to make sure that no file path appears in the workspaces more
than once.
PROJ-COUNT counts the number of non-disabled projects in a workspace to make
sure that there is at least one project that will be displayed.
WS-COUNT counts the number of non-disabled workspaces to make sure that there is
at least one workspace that will be used.
A successful validation returns just the symbol \\='success, in case of an error
a list of 3 items is returned: the symbol \\='error, the exact line where the
error happened, and the error message. In some circumstances (for example when
a project is missing a path property) it makes sense to display the error not in
the currently looked at line, but the one above, which is why the previously
looked at line PREV is given as well.
LINES: List of Strings
CONTEXT: Keyword
PREV: String
PATHS: List<String>
PROJ-COUNT: Int"
(treemacs-block
(cl-labels ((as-warning (txt) (propertize txt 'face 'warning)))
(treemacs-unless-let (line (car lines))
(pcase context
(:property
(treemacs-return-if (= 0 proj-count)
`(error ,prev ,(as-warning "Workspace must contain at least 1 project that is not disabled.")))
(treemacs-return-if (= 0 ws-count)
`(error ,prev ,(as-warning "There must be at least 1 worspace that is not disabled.")))
(treemacs-return
'success))
(:start
(treemacs-return
(list 'error :start (as-warning "Input is empty"))))
(_
(treemacs-return
(list 'error prev (as-warning "Cannot end with a project or workspace name")))))
(pcase context
(:start
(treemacs-return-if (not (s-matches? treemacs--persist-workspace-name-regex line))
`(error ,line ,(as-warning "First item must be a workspace name")))
(-let [ws-is-disabled? (s-starts-with? "* COMMENT" line)]
(unless ws-is-disabled? (cl-incf ws-count)))
(treemacs--validate-persist-lines (cdr lines) :workspace line nil 0 ws-count))
(:workspace
(treemacs-return-if (not (s-matches? treemacs--persist-project-name-regex line))
`(error ,line ,(as-warning "Workspace name must be followed by project name")))
(-let [proj-is-disabled? (s-starts-with? "** COMMENT" line)]
(unless proj-is-disabled? (cl-incf proj-count))
(treemacs--validate-persist-lines (cdr lines) :project line nil proj-count ws-count)))
(:project
(treemacs-return-if (not (s-matches? treemacs--persist-kv-regex line))
`(error ,prev ,(as-warning "Project name must be followed by path declaration")))
(-let [path (cadr (s-split " :: " line))]
;; Path not existing is only a hard error when org-editing, when loading on boot
;; its significance is determined by the customization setting
;; `treemacs-missing-project-action'. Remote files are skipped to avoid opening
;; Tramp connections.
(treemacs-return-if (and (string= treemacs--org-edit-buffer-name (buffer-name))
(not (s-starts-with? "** COMMENT" prev))
(not (file-remote-p path))
(not (file-exists-p path)))
`(error ,line ,(format (as-warning "File '%s' does not exist") (propertize path 'face 'font-lock-string-face))))
(treemacs-return-if (or (--any (treemacs-is-path path :in it) paths)
(--any (treemacs-is-path it :in path) paths))
`(error ,line ,(format (as-warning "Path '%s' appears in the workspace more than once.")
(propertize path 'face 'font-lock-string-face))))
(treemacs--validate-persist-lines (cdr lines) :property line (cons path paths) proj-count ws-count)))
(:property
(let ((line-is-workspace-name (s-matches? treemacs--persist-workspace-name-regex line))
(line-is-project-name (s-matches? treemacs--persist-project-name-regex line)))
(cond
(line-is-workspace-name
(treemacs-return-if (= 0 proj-count)
`(error ,prev ,(as-warning "Workspace must contain at least 1 project that is not disabled.")))
(-let [ws-is-disabled? (s-starts-with? "* COMMENT" line)]
(unless ws-is-disabled? (cl-incf ws-count)))
(treemacs--validate-persist-lines (cdr lines) :workspace line nil 0 ws-count))
(line-is-project-name
(-let [proj-is-disabled? (s-starts-with? "** COMMENT" line)]
(unless proj-is-disabled? (cl-incf proj-count)))
(treemacs--validate-persist-lines (cdr lines) :project line paths proj-count ws-count))
(t
(treemacs-return-if (-none? #'identity (list line-is-workspace-name line-is-project-name))
`(error ,prev ,(as-warning "Path property must be followed by the next workspace or project"))))))))))))