pkg update and first config fix

org-brain not working, add org-roam
This commit is contained in:
2022-12-19 23:02:34 +01:00
parent 02b3e07185
commit 82f05baffe
885 changed files with 356098 additions and 36993 deletions

View File

@@ -1,6 +1,6 @@
;;; treemacs.el --- A tree style file viewer package -*- lexical-binding: t -*-
;; Copyright (C) 2021 Alexander Miller
;; Copyright (C) 2022 Alexander Miller
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -27,6 +27,7 @@
(require 'treemacs-core-utils)
(require 'treemacs-dom)
(require 'treemacs-scope)
(require 'treemacs-customization)
(eval-when-compile
(require 'cl-lib)
@@ -87,8 +88,6 @@
(defvar-local treemacs--org-err-ov nil
"The overlay that will display validations when org-editing.")
(defvar-local treemacs--project-positions nil)
(defvar-local treemacs--project-of-buffer nil
"The project that the current buffer falls under, if any.")
@@ -103,12 +102,16 @@ rely on the current buffer and workspace being aligned.")
To be called whenever a project or workspace changes."
(inline-quote
(dolist (buf (buffer-list))
(setf (buffer-local-value 'treemacs--project-of-buffer buf) nil))))
(with-current-buffer buf
(setf treemacs--project-of-buffer nil)))))
(defun treemacs--current-builtin-project-function ()
"Find the current project.el project."
(declare (side-effect-free t))
(-some-> (project-current) (cdr) (file-truename) (treemacs-canonical-path)))
(-when-let (project (project-current))
(if (fboundp 'project-root)
(-> project (project-root) (file-truename) (treemacs-canonical-path))
(-> project (cdr) (file-truename) (treemacs-canonical-path)))))
(defun treemacs--current-directory-project-function ()
"Find the current working directory."
@@ -219,18 +222,13 @@ FILE: Filepath"
"Get the position of the next project.
Will return `point-max' if there is no next project."
(declare (side-effect-free t))
(inline-quote (next-single-char-property-change (point-at-eol) :project)))
(inline-quote (next-single-char-property-change (line-end-position) :project)))
(define-inline treemacs--prev-project-pos ()
"Get the position of the next project.
Will return `point-min' if there is no next project."
(declare (side-effect-free t))
(inline-quote (previous-single-char-property-change (point-at-bol) :project)))
(define-inline treemacs--reset-project-positions ()
"Reset `treemacs--project-positions'."
(inline-quote
(setq treemacs--project-positions (make-hash-table :test #'equal :size 20))))
(inline-quote (previous-single-char-property-change (line-beginning-position) :project)))
(define-inline treemacs-project->key (self)
"Get the hash table key of SELF.
@@ -244,58 +242,51 @@ SELF may be a project struct or a root key of a top level extension."
(treemacs-project->path ,self)
,self))))
(define-inline treemacs--set-project-position (project position)
"Insert PROJECT's POSITION into `treemacs--project-positions'."
(inline-letevals (project position)
(inline-quote
(ht-set! treemacs--project-positions (treemacs-project->key ,project) ,position))))
(define-inline treemacs-project->position (self)
"Return the position of project SELF in the current buffer."
(declare (side-effect-free t))
(inline-letevals (self)
(inline-quote
(ht-get treemacs--project-positions (treemacs-project->key ,self)))))
(treemacs-dom-node->position
(treemacs-find-in-dom (treemacs-project->path ,self))))))
(define-inline treemacs-project->is-expanded? (self)
"Return non-nil if project SELF is expanded in the current buffer."
(declare (side-effect-free t))
(inline-letevals (self)
(inline-quote
(eq 'root-node-open
(-> ,self (treemacs-project->position) (treemacs-button-get :state))))))
(memq (-> ,self (treemacs-project->position) (treemacs-button-get :state))
treemacs--open-node-states))))
(define-inline treemacs-project->refresh-path-status! (self)
(defun treemacs-project->refresh-path-status! (self)
"Refresh the path status of project SELF in the current buffer.
Does not preserve the current position in the buffer."
(inline-letevals (self)
(inline-quote
(let ((old-path-status (treemacs-project->path-status ,self))
(new-path-status (treemacs--get-path-status (treemacs-project->path ,self))))
(unless (eq old-path-status new-path-status)
(setf (treemacs-project->path-status ,self) new-path-status)
;; When the path transforms from unreadable or disconnected to readable,
;; update the :symlink status on its button.
(let ((pos (treemacs-project->position ,self))
(path (treemacs-project->path ,self)))
(when (treemacs-project->is-readable? ,self)
(treemacs-button-put pos :symlink (file-symlink-p path)))
(treemacs-button-put pos 'face (treemacs--root-face ,self))))))))
(let ((old-path-status (treemacs-project->path-status self))
(new-path-status (treemacs--get-path-status (treemacs-project->path self))))
(unless (eq old-path-status new-path-status)
(setf (treemacs-project->path-status self) new-path-status)
;; When the path transforms from unreadable or disconnected to readable,
;; update the :symlink status on its button.
(let ((pos (treemacs-project->position self))
(path (treemacs-project->path self)))
(when (treemacs-project->is-readable? self)
(treemacs-button-put pos :symlink (file-symlink-p path)))
(treemacs-button-put pos 'face (treemacs--root-face self))))))
(define-inline treemacs-project->refresh! (self)
;; TODO(2021/08/17): -> rendering
(defun treemacs-project->refresh! (self)
"Refresh project SELF in the current buffer.
Does not preserve the current position in the buffer."
(inline-letevals (self)
(inline-quote
(progn
(treemacs-project->refresh-path-status! ,self)
(when (treemacs-project->is-expanded? ,self)
(let ((root-btn (treemacs-project->position ,self)))
(goto-char root-btn)
(treemacs--forget-last-highlight)
(treemacs--collapse-root-node root-btn)
(unless (treemacs-project->is-unreadable? ,self)
(treemacs--expand-root-node root-btn))))))))
(treemacs-project->refresh-path-status! self)
(when (treemacs-project->is-expanded? self)
(let ((root-btn (treemacs-project->position self)))
(goto-char root-btn)
(treemacs--forget-last-highlight)
(funcall (alist-get (treemacs-button-get root-btn :state)
treemacs-TAB-actions-config))
(unless (treemacs-project->is-unreadable? self)
(funcall (alist-get (treemacs-button-get root-btn :state)
treemacs-TAB-actions-config))))))
(define-inline treemacs-project->is-last? (self)
"Return t when root node of project SELF is the last in the view."
@@ -405,6 +396,7 @@ Returns either
* `remote-unreadable' when PATH is a remote unreadable file or directory,
* `remote-disconnected' when PATH is remote, but the connection is down, or
* `extension' when PATH is not a string."
(declare (side-effect-free t))
(cond
((not (stringp path)) 'extension)
((not (file-remote-p path))
@@ -414,14 +406,15 @@ Returns either
(t 'remote-unreadable)))
(define-inline treemacs-project->is-unreadable? (self)
"Return t if the project SELF is definitely unreadable.
"Return non-nil if the project SELF is definitely unreadable.
If `path-status' of the project is `remote-disconnected', the return value will
be nil even though the path might still be unreadable. Does not verify the
readability, the cached path-state is used."
readability, the cached path-state is used. Extension projects will count as
readable."
(declare (side-effect-free t))
(inline-quote (memq (treemacs-project->path-status ,self)
'(local-unreadable remote-unreadable extension))))
'(local-unreadable remote-unreadable))))
(define-inline treemacs-project->is-readable? (self)
"Return t if the project SELF is definitely readable for file operations.
@@ -521,6 +514,7 @@ NAME: String"
(when treemacs-expand-added-projects
(treemacs--expand-root-node (treemacs-project->position project))))))
(treemacs--persist)
(treemacs--invalidate-buffer-project-cache)
(when (with-no-warnings treemacs-hide-gitignored-files-mode)
(treemacs--prefetch-gitignore-cache path))
(run-hook-with-args 'treemacs-create-project-functions project)
@@ -577,8 +571,7 @@ Return values may be as follows:
'user-cancel)
(treemacs-run-in-every-buffer
(treemacs-with-writable-buffer
(let* ((project-path (treemacs-project->path project))
(project-pos (goto-char (treemacs-project->position project-path)))
(let* ((project-pos (goto-char (treemacs-project->position project)))
(prev-project-pos (move-marker (make-marker) (treemacs--prev-project-pos)))
(next-project-pos (move-marker (make-marker) (treemacs--next-project-pos))))
(when (treemacs-project->is-expanded? project)
@@ -592,7 +585,7 @@ Return values may be as follows:
;; the end of the previous button's line. If the `treemacs--projects-end'
;; is at the EOL of the it will move to EOL of the previous button.
(previous-button
(delete-region (treemacs-button-end previous-button) (point-at-eol))
(delete-region (treemacs-button-end previous-button) (line-end-position))
(when next-button (forward-button 1)))
;; Previous project does not exist, but a next button exists. Delete from
;; BOL to the start of the next buttons line.
@@ -601,16 +594,17 @@ Return values may be as follows:
;; The first item after the deletion will be bottom extensions. Project
;; end will be at its BOL, making it move upon expand/collapse. Lock the marker.
(set-marker-insertion-type (treemacs--projects-end) nil))
(delete-region (point-at-bol) (progn (goto-char next-button) (forward-line 0) (point))))
(delete-region (line-beginning-position) (progn (goto-char next-button) (forward-line 0) (point))))
;; Neither the previous nor the next button exists. Simply delete the
;; current line.
(t
(delete-region (point-at-bol) (point-at-eol)))))
(delete-region (line-beginning-position) (line-end-position)))))
(if (equal (point-min) prev-project-pos)
(goto-char next-project-pos)
(goto-char prev-project-pos)))
(treemacs--forget-last-highlight)
(treemacs--invalidate-buffer-project-cache)
(--when-let (treemacs-get-local-window)
(with-selected-window it
(recenter)))
@@ -714,13 +708,17 @@ PROJECT: Project Struct"
(interactive)
(save-excursion
(goto-char (treemacs-project->position project))
(let* ((start (point-at-bol))
(let* ((start (line-beginning-position))
(next (treemacs--next-non-child-button (treemacs-project->position project)))
(end (if next (-> next (treemacs-button-start) (previous-button) (treemacs-button-end)) (point-max))))
(end (if next
(-> next (treemacs-button-start) (previous-button) (treemacs-button-end))
;; final position minus the final newline
(1- (point-max)))))
(cons start end))))
(defun treemacs--consolidate-projects ()
"Correct treemacs buffers' content after the workspace was edited."
(treemacs--invalidate-buffer-project-cache)
(treemacs-run-in-every-buffer
(let* ((current-file (--when-let (treemacs-current-button) (treemacs--nearest-path it)))
(current-workspace (treemacs-current-workspace))
@@ -753,6 +751,7 @@ PROJECT: Project Struct"
(setf projects-in-buffer (delete project-in-buffer projects-in-buffer))))
(treemacs-with-writable-buffer
(treemacs--forget-last-highlight)
(treemacs--reset-dom)
;; delete everything's that's visible and render it again - the order of projects could
;; have been changed
(erase-buffer)
@@ -787,7 +786,7 @@ PROJECT: Project Struct"
(_
(goto-char 0)
(search-forward-regexp (rx-to-string `(seq bol ,line eol)))))
(setf treemacs--org-err-ov (make-overlay (point-at-eol) (point-at-eol)))
(setf treemacs--org-err-ov (make-overlay (line-end-position) (line-end-position)))
(overlay-put treemacs--org-err-ov 'after-string
(concat (propertize "" 'face 'error) message))
(add-hook 'after-change-functions #'treemacs--org-edit-remove-validation-msg nil :local)))
@@ -807,18 +806,27 @@ PROJECT: Project Struct"
(--when-let (funcall fun)
(treemacs-return it)))))
(defun treemacs--select-workspace-by-name (&optional name)
"Interactively select the workspace with the given NAME."
(defun treemacs--find-workspace-by-name (name)
"Find a workspace with the given NAME.
Returns nil when there is no match."
(treemacs--maybe-load-workspaces)
(if (= 1 (length treemacs--workspaces))
(car treemacs--workspaces)
(-let [name (or name
(completing-read
"Workspace: "
(->> treemacs--workspaces
(--map (cons (treemacs-workspace->name it) it)))))]
(--first (string= name (treemacs-workspace->name it))
treemacs--workspaces))))
(--first (string= name (treemacs-workspace->name it))
treemacs--workspaces))
(defun treemacs--select-workspace-by-name ()
"Interactively select the workspace.
Selection is based on the list of names of all workspaces and still happens
when there is only one workspace."
(treemacs--maybe-load-workspaces)
(let (name)
(while (or (null name) (string= "" name))
(setf name (completing-read
"Workspace: "
(->> treemacs--workspaces
(--map (cons (treemacs-workspace->name it) it)))
nil :require-match)))
(--first (string= name (treemacs-workspace->name it))
treemacs--workspaces)))
(defun treemacs--maybe-clean-buffers-on-workspace-switch (which)
"Delete buffers depending on the value of WHICH.