pkg update and first config fix
org-brain not working, add org-roam
This commit is contained in:
@@ -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
|
||||
@@ -40,6 +40,9 @@
|
||||
(treemacs-import-functions-from treemacs-rendering
|
||||
treemacs-do-delete-single-node)
|
||||
|
||||
(treemacs-import-functions-from treemacs-annotations
|
||||
treemacs--do-apply-annotation)
|
||||
|
||||
(defconst treemacs--dirs-to-collapse.py
|
||||
(if (member "treemacs-dirs-to-collapse.py" (directory-files treemacs-dir))
|
||||
(treemacs-join-path treemacs-dir "treemacs-dirs-to-collapse.py")
|
||||
@@ -60,6 +63,9 @@
|
||||
(treemacs-join-path treemacs-dir "treemacs-find-ignored-files.py")
|
||||
(treemacs-join-path treemacs-dir "src/scripts/treemacs-find-ignored-files.py")))
|
||||
|
||||
(defconst treemacs--single-git-update-debouce-store (make-hash-table :size 10)
|
||||
"Table to keep track of files that will already be updated.")
|
||||
|
||||
(defvar treemacs--git-cache-max-size 60
|
||||
"Maximum size for `treemacs--git-cache'.
|
||||
If it does reach that size it will be cut back to 30 entries.")
|
||||
@@ -75,6 +81,8 @@ face changes, especially when a full project is refreshed.
|
||||
Since this table is a global value that can effectively grow indefinitely its
|
||||
value is limited by `treemacs--git-cache-max-size'.")
|
||||
|
||||
(defvar treemacs-git-mode)
|
||||
|
||||
(define-inline treemacs--git-status-face (status default)
|
||||
"Get the git face for the given STATUS.
|
||||
Use DEFAULT as default match.
|
||||
@@ -97,18 +105,6 @@ DEFAULT: Face"
|
||||
"Saves the specific version of git-mode that is active.
|
||||
Values are either `simple', `extended', `deferred' or nil.")
|
||||
|
||||
(define-inline treemacs--get-node-face (path git-info default)
|
||||
"Return the appropriate face for PATH based on GIT-INFO.
|
||||
If there is no git entry for PATH return DEFAULT.
|
||||
|
||||
PATH: Filepath
|
||||
GIT-INFO: Hash-Table
|
||||
DEFAULT: Face"
|
||||
(declare (pure t) (side-effect-free t))
|
||||
(inline-letevals (path git-info default)
|
||||
(inline-quote
|
||||
(treemacs--git-status-face (ht-get ,git-info ,path) ,default))))
|
||||
|
||||
(defun treemacs--resize-git-cache ()
|
||||
"Cuts `treemacs--git-cache' back down to size.
|
||||
Specifically its size will be reduced to half of `treemacs--git-cache-max-size'."
|
||||
@@ -134,7 +130,7 @@ Remote projects are ignored."
|
||||
(defun treemacs--git-status-parse-function (_future)
|
||||
"Dummy with FUTURE.
|
||||
Real implementation will be `fset' based on `treemacs-git-mode' value."
|
||||
(ht))
|
||||
treemacs--empty-table)
|
||||
|
||||
(defun treemacs--git-status-process-extended (path)
|
||||
"Start an extended python-parsed git status process for files under PATH."
|
||||
@@ -190,13 +186,13 @@ GIT-FUTURE: Pfuture"
|
||||
(treemacs-log-err "treemacs-git-status.py output: %s" git-output))
|
||||
(treemacs-log-err "treemacs-git-status.py did not output a valid hash table. See full output in *Messages*.")
|
||||
nil)))))
|
||||
(ht)))
|
||||
treemacs--empty-table))
|
||||
|
||||
(defun treemacs--git-status-process-simple (path)
|
||||
"Start a simple git status process for files under PATH."
|
||||
(let* ((default-directory (file-truename path))
|
||||
(process-environment (cons "GIT_OPTIONAL_LOCKS=0" process-environment))
|
||||
(future (pfuture-new "git" "status" "--porcelain" "--ignored" "-z" ".")))
|
||||
(future (pfuture-new "git" "status" "--porcelain" "--ignored=matching" "-z" ".")))
|
||||
(process-put future 'default-directory default-directory)
|
||||
future))
|
||||
|
||||
@@ -230,45 +226,12 @@ GIT-FUTURE: Pfuture"
|
||||
(setq i (1+ i))
|
||||
(ht-set! git-info-hash
|
||||
(treemacs-join-path git-root (s-trim-left path))
|
||||
(substring (s-trim-left status) 0 1)))))
|
||||
(treemacs--git-status-face
|
||||
(substring (s-trim-left status) 0 1)
|
||||
'treemacs-git-unmodified-face)))))
|
||||
(setq i (1+ i)))))))))
|
||||
git-info-hash))
|
||||
|
||||
;; TODO(2019/11/06): re-get git status when btn is flattened
|
||||
(defun treemacs--apply-deferred-git-state (parent-btn git-future buffer)
|
||||
"Apply the git fontification for direct children of PARENT-BTN.
|
||||
GIT-FUTURE is parsed the same way as in `treemacs--create-branch'. Additionally
|
||||
since this function is run on an idle timer the BUFFER to work on must be passed
|
||||
as well since the user may since select a different buffer, window or frame.
|
||||
|
||||
PARENT-BTN: Button
|
||||
GIT-FUTURE: Pfuture|HashMap
|
||||
BUFFER: Buffer"
|
||||
(when (and (buffer-live-p buffer) git-future)
|
||||
(with-current-buffer buffer
|
||||
;; cut the cache down to size if it grows too large
|
||||
(when (> (ht-size treemacs--git-cache) treemacs--git-cache-max-size)
|
||||
(run-with-idle-timer 2 nil #'treemacs--resize-git-cache))
|
||||
(-let [parent-path (treemacs-button-get parent-btn :path)]
|
||||
;; the node may have been closed or deleted by now
|
||||
(when (and (treemacs-find-in-dom parent-path)
|
||||
(memq (treemacs-button-get parent-btn :state) '(dir-node-open root-node-open)))
|
||||
(let ((depth (1+ (treemacs-button-get parent-btn :depth)))
|
||||
(git-info (treemacs--get-or-parse-git-result git-future))
|
||||
(btn parent-btn))
|
||||
(ht-set! treemacs--git-cache parent-path git-info)
|
||||
(treemacs-with-writable-buffer
|
||||
;; the depth check ensures that we only iterate over the nodes that are below parent-btn
|
||||
;; and stop when we've moved on to nodes that are above or belong to the next project
|
||||
(while (and (setq btn (next-button btn))
|
||||
(>= (treemacs-button-get btn :depth) depth))
|
||||
(-let [path (treemacs-button-get btn :key)]
|
||||
(when (and (= depth (treemacs-button-get btn :depth))
|
||||
(not (treemacs-button-get btn :no-git)))
|
||||
(treemacs-button-put
|
||||
btn 'face
|
||||
(treemacs--get-node-face path git-info (treemacs-button-get btn :default-face)))))))))))))
|
||||
|
||||
(defun treemacs-update-single-file-git-state (file)
|
||||
"Update the FILE node's git state, wrapped in `treemacs-save-position'.
|
||||
Internally calls `treemacs-do-update-single-file-git-state'.
|
||||
@@ -297,8 +260,13 @@ OVERRIDE-STATUS: Boolean"
|
||||
(let* ((local-buffer (current-buffer))
|
||||
(parent (treemacs--parent file))
|
||||
(parent-node (treemacs-find-in-dom parent)))
|
||||
(when parent-node
|
||||
(when (and
|
||||
treemacs-git-mode
|
||||
parent-node
|
||||
(null (ht-get treemacs--single-git-update-debouce-store file)))
|
||||
(ht-set! treemacs--single-git-update-debouce-store file t)
|
||||
(let* ((parents (unless (or exclude-parents
|
||||
(eq 'simple treemacs--git-mode)
|
||||
(null (treemacs-dom-node->parent parent-node)))
|
||||
;; include the first parent...
|
||||
(cons (treemacs-dom-node->key parent-node)
|
||||
@@ -306,45 +274,56 @@ OVERRIDE-STATUS: Boolean"
|
||||
(cdr (-map #'treemacs-dom-node->key
|
||||
(treemacs-dom-node->all-parents parent-node))))))
|
||||
(git-cache (ht-get treemacs--git-cache parent))
|
||||
(current-state (if override-status
|
||||
"OVERRIDE"
|
||||
(or (-some-> git-cache (ht-get file)) "0")))
|
||||
(current-face (if override-status
|
||||
"OVERRIDE"
|
||||
(or (-some-> git-cache (ht-get file) (symbol-name))
|
||||
"NONE")))
|
||||
(cmd `(,treemacs-python-executable
|
||||
"-O"
|
||||
,treemacs--single-file-git-status.py ,file ,current-state ,@parents)))
|
||||
,treemacs--single-file-git-status.py ,file ,current-face ,@parents)))
|
||||
(pfuture-callback cmd
|
||||
:directory parent
|
||||
:name "Treemacs Update Single File Process"
|
||||
:on-success
|
||||
(when (buffer-live-p local-buffer)
|
||||
(with-current-buffer local-buffer
|
||||
(treemacs-with-writable-buffer
|
||||
;; first the file node with its own default face
|
||||
(-let [output (read (pfuture-callback-output))]
|
||||
(-let [(file . state) (pop output)]
|
||||
(when git-cache
|
||||
(ht-set! git-cache file state))
|
||||
(-when-let (pos (treemacs-find-visible-node file))
|
||||
(let* ((default (if (file-directory-p file) 'treemacs-directory-face 'treemacs-git-unmodified-face))
|
||||
(face (treemacs--git-status-face state default)))
|
||||
(put-text-property
|
||||
(treemacs-button-start pos) (treemacs-button-end pos)
|
||||
'face face))))
|
||||
;; then the directories
|
||||
(pcase-dolist (`(,file . ,state) output)
|
||||
(-when-let (pos (treemacs-find-visible-node file))
|
||||
(-let [face (treemacs--git-status-face state 'treemacs-directory-face)]
|
||||
(put-text-property
|
||||
(treemacs-button-start pos) (treemacs-button-end pos)
|
||||
'face face))))))))
|
||||
(progn
|
||||
(ht-remove! treemacs--single-git-update-debouce-store file)
|
||||
(when (buffer-live-p local-buffer)
|
||||
(with-current-buffer local-buffer
|
||||
(treemacs-with-writable-buffer
|
||||
(save-excursion
|
||||
;; first the file node with its own default face
|
||||
(-let [output (read (pfuture-callback-output))]
|
||||
(-let [(path . face) (pop output)]
|
||||
(treemacs--git-face-quick-change path face git-cache))
|
||||
;; then the directories
|
||||
(pcase-dolist (`(,path . ,face) output)
|
||||
(treemacs--git-face-quick-change path face))))))))
|
||||
:on-error
|
||||
(pcase (process-exit-status process)
|
||||
(2 (ignore "No Change, Do Nothing"))
|
||||
(_
|
||||
(-let [err-str (treemacs--remove-trailing-newline (pfuture-output-from-buffer pfuture-buffer))]
|
||||
(treemacs-log-err "Update of node \"%s\" failed with status \"%s\" and result"
|
||||
file (treemacs--remove-trailing-newline status))
|
||||
(treemacs-log-err "\"%s\"" (treemacs--remove-trailing-newline err-str))))))))))
|
||||
(progn
|
||||
(ht-remove! treemacs--single-git-update-debouce-store file)
|
||||
(pcase (process-exit-status process)
|
||||
(2 (ignore "No Change, Do Nothing"))
|
||||
(_
|
||||
(-let [err-str (treemacs--remove-trailing-newline (pfuture-output-from-buffer pfuture-buffer))]
|
||||
(treemacs-log-err "Update of node \"%s\" failed with status \"%s\" and result"
|
||||
file (treemacs--remove-trailing-newline status))
|
||||
(treemacs-log-err "\"%s\"" (treemacs--remove-trailing-newline err-str)))))))))))
|
||||
|
||||
(define-inline treemacs--git-face-quick-change (path git-face &optional git-cache)
|
||||
"Quick-change of PATH's GIT-FACE.
|
||||
Updates the visible face and git-cache + annotation store entries. GIT-CACHE
|
||||
might be already known or not. If not it will be pulled from BTN's parent.
|
||||
Used when asynchronous processes report back git changes."
|
||||
(inline-letevals (path git-face git-cache)
|
||||
(inline-quote
|
||||
(let ((git-cache (or ,git-cache
|
||||
(ht-get treemacs--git-cache
|
||||
(treemacs--parent-dir ,path))))
|
||||
(btn (treemacs-find-visible-node ,path)))
|
||||
(when git-cache
|
||||
(ht-set! git-cache ,path ,git-face))
|
||||
(when btn
|
||||
(treemacs--do-apply-annotation btn ,git-face))))))
|
||||
|
||||
(defun treemacs--collapsed-dirs-process (path project)
|
||||
"Start a new process to determine directories to collapse under PATH.
|
||||
@@ -418,7 +397,7 @@ run because the git cache has yet to be filled."
|
||||
(treemacs-run-in-every-buffer
|
||||
(treemacs-save-position
|
||||
(dolist (file ignored-files)
|
||||
(when-let (treemacs-is-path-visible? file)
|
||||
(-when-let (treemacs-is-path-visible? file)
|
||||
(treemacs-do-delete-single-node file))))))))
|
||||
|
||||
(define-minor-mode treemacs-git-mode
|
||||
@@ -477,13 +456,13 @@ Use either ARG as git integration value of read it interactively."
|
||||
(fset 'treemacs--git-status-parse-function #'treemacs--parse-git-status-simple))
|
||||
(_
|
||||
(fset 'treemacs--git-status-process-function #'ignore)
|
||||
(fset 'treemacs--git-status-parse-function (lambda (_) (ht))))))
|
||||
(fset 'treemacs--git-status-parse-function (lambda (_) treemacs--empty-table)))))
|
||||
|
||||
(defun treemacs--tear-down-git-mode ()
|
||||
"Tear down `treemacs-git-mode'."
|
||||
(setf treemacs--git-mode nil)
|
||||
(fset 'treemacs--git-status-process-function #'ignore)
|
||||
(fset 'treemacs--git-status-parse-function (lambda (_) (ht))))
|
||||
(fset 'treemacs--git-status-parse-function (lambda (_) treemacs--empty-table)))
|
||||
|
||||
(define-inline treemacs--get-or-parse-git-result (future)
|
||||
"Get the parsed git result of FUTURE.
|
||||
@@ -499,7 +478,7 @@ FUTURE: Pfuture process"
|
||||
(let ((result (treemacs--git-status-parse-function ,future)))
|
||||
(process-put ,future 'git-table result)
|
||||
result))
|
||||
(ht)))))
|
||||
treemacs--empty-table))))
|
||||
|
||||
(define-minor-mode treemacs-hide-gitignored-files-mode
|
||||
"Toggle `treemacs-hide-gitignored-files-mode'.
|
||||
|
||||
Reference in New Issue
Block a user