update packages
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
;;; treemacs.el --- A tree style file viewer package -*- lexical-binding: t -*-
|
||||
|
||||
;; Copyright (C) 2020 Alexander Miller
|
||||
;; Copyright (C) 2021 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
|
||||
@@ -25,7 +25,6 @@
|
||||
(require 's)
|
||||
(require 'ht)
|
||||
(require 'f)
|
||||
(require 'ace-window)
|
||||
(require 'pfuture)
|
||||
(require 'treemacs-customization)
|
||||
(require 'treemacs-logging)
|
||||
@@ -35,6 +34,9 @@
|
||||
(require 'cl-lib)
|
||||
(require 'treemacs-macros))
|
||||
|
||||
(treemacs-import-functions-from "cfrs"
|
||||
cfrs-read)
|
||||
|
||||
(treemacs-import-functions-from "treemacs-tags"
|
||||
treemacs--expand-file-node
|
||||
treemacs--collapse-file-node
|
||||
@@ -272,6 +274,17 @@ button type on every call."
|
||||
(inline-quote
|
||||
(buffer-substring-no-properties (treemacs-button-start ,btn) (treemacs-button-end ,btn))))
|
||||
|
||||
(define-inline treemacs--tokenize-path (path exclude-prefix)
|
||||
"Get the PATH's single elements, excluding EXCLUDE-PREFIX.
|
||||
For example the input /A/B/C/D/E + /A/B will return [C D E].
|
||||
|
||||
PATH: File Path
|
||||
EXCLUDE-PREFIX: File Path"
|
||||
(declare (pure t) (side-effect-free t))
|
||||
(inline-letevals (path exclude-prefix)
|
||||
(inline-quote
|
||||
(cdr (f-split (substring ,path (length ,exclude-prefix)))))))
|
||||
|
||||
(defun treemacs--replace-recentf-entry (old-file new-file)
|
||||
"Replace OLD-FILE with NEW-FILE in the recent file list."
|
||||
;; code taken from spacemacs - is-bound check due to being introduced after emacs24?
|
||||
@@ -296,7 +309,7 @@ button type on every call."
|
||||
(when (or treemacs-follow-after-init
|
||||
(with-no-warnings treemacs-follow-mode))
|
||||
(with-current-buffer buffer (treemacs--follow)))
|
||||
(run-hooks 'treemacs-select-hook))))
|
||||
(run-hook-with-args 'treemacs-select-functions 'exists))))
|
||||
|
||||
(define-inline treemacs--button-symbol-switch (new-sym)
|
||||
"Replace icon in current line with NEW-SYM."
|
||||
@@ -429,7 +442,7 @@ Simply collapses and re-expands the button (if it has not been closed)."
|
||||
(goto-char (treemacs-button-start btn))
|
||||
(treemacs--push-button btn))))))
|
||||
|
||||
(define-inline treemacs--canonical-path (path)
|
||||
(define-inline treemacs-canonical-path (path)
|
||||
"The canonical version of PATH for being handled by treemacs.
|
||||
In practice this means expand PATH and remove its final slash."
|
||||
(declare (pure t) (side-effect-free t))
|
||||
@@ -437,6 +450,8 @@ In practice this means expand PATH and remove its final slash."
|
||||
(inline-quote
|
||||
(let (file-name-handler-alist)
|
||||
(-> ,path (expand-file-name) (treemacs--unslash))))))
|
||||
;; TODO(2020/12/28): alias is for backwards compatibility, remove it eventually
|
||||
(defalias 'treemacs--canonical-path #'treemacs-canonical-path)
|
||||
|
||||
(define-inline treemacs-is-file-git-ignored? (file git-info)
|
||||
"Determined if FILE is ignored by git by means of GIT-INFO."
|
||||
@@ -489,13 +504,14 @@ buffer."
|
||||
(make-obsolete #'treemacs--get-children-of #'treemacs-collect-child-nodes "v2.7"))
|
||||
|
||||
(defun treemacs--init (&optional root name)
|
||||
"Initialize a treemacs buffer from the current workspace.
|
||||
"Initialise a treemacs buffer from the current workspace.
|
||||
Add a project for ROOT and NAME if they are non-nil."
|
||||
(treemacs--maybe-load-workspaces)
|
||||
(let ((origin-buffer (current-buffer))
|
||||
(current-workspace (treemacs-current-workspace))
|
||||
(run-hook? nil))
|
||||
(pcase (treemacs-current-visibility)
|
||||
(run-hook? nil)
|
||||
(visibility (treemacs-current-visibility)))
|
||||
(pcase visibility
|
||||
('visible (treemacs--select-visible-window))
|
||||
('exists (treemacs--select-not-visible-window))
|
||||
('none
|
||||
@@ -506,13 +522,13 @@ Add a project for ROOT and NAME if they are non-nil."
|
||||
(treemacs--render-projects (treemacs-workspace->projects current-workspace))
|
||||
(when (treemacs-workspace->is-empty?)
|
||||
(let* ((path (-> (treemacs--read-first-project-path)
|
||||
(treemacs--canonical-path)))
|
||||
(treemacs-canonical-path)))
|
||||
(name (treemacs--filename path)))
|
||||
(treemacs-do-add-project-to-workspace path name)
|
||||
(treemacs-log "Created first project.")))
|
||||
(goto-char 2)
|
||||
(setf run-hook? t)))
|
||||
(when root (treemacs-do-add-project-to-workspace (treemacs--canonical-path root) name))
|
||||
(when root (treemacs-do-add-project-to-workspace (treemacs-canonical-path root) name))
|
||||
(with-no-warnings (setq treemacs--ready-to-follow t))
|
||||
(when (or treemacs-follow-after-init (with-no-warnings treemacs-follow-mode))
|
||||
(with-current-buffer origin-buffer
|
||||
@@ -520,7 +536,7 @@ Add a project for ROOT and NAME if they are non-nil."
|
||||
;; The hook should run at the end of the setup, but also only
|
||||
;; if a new buffer was created, as the other cases are already covered
|
||||
;; in their respective setup functions.
|
||||
(when run-hook? (run-hooks 'treemacs-select-hook))))
|
||||
(when run-hook? (run-hook-with-args 'treemacs-select-functions visibility))))
|
||||
|
||||
(defun treemacs--push-button (btn &optional recursive)
|
||||
"Execute the appropriate action given the state of the pushed BTN.
|
||||
@@ -586,7 +602,7 @@ IS-FILE?: Bool"
|
||||
(treemacs-button-get :parent)
|
||||
(treemacs-button-get :path)))
|
||||
(treemacs-do-update-node created-under)))
|
||||
(treemacs-goto-file-node (treemacs--canonical-path path-to-create) project)
|
||||
(treemacs-goto-file-node (treemacs-canonical-path path-to-create) project)
|
||||
(recenter))
|
||||
(treemacs-pulse-on-success
|
||||
"Created %s." (propertize path-to-create 'face 'font-lock-string-face)))))
|
||||
@@ -772,7 +788,7 @@ failed. PROJECT is used for determining whether Git actions are appropriate."
|
||||
"Find position of node at PATH.
|
||||
Unlike `treemacs-find-node' this will not expand other nodes in the view, but
|
||||
only look among those currently visible. The result however is the same: either
|
||||
a marker ponting to the found node or nil.
|
||||
a marker pointing to the found node or nil.
|
||||
|
||||
Unlike `treemacs-find-node', this function does not go to the node.
|
||||
|
||||
@@ -784,7 +800,7 @@ PATH: Node Path"
|
||||
|
||||
(defun treemacs-find-node (path &optional project)
|
||||
"Find position of node identified by PATH under PROJECT in the current buffer.
|
||||
Inspite the signature this function effectively supports two different calling
|
||||
In spite of the signature this function effectively supports two different calling
|
||||
conventions.
|
||||
|
||||
The first one is for movement towards a node that identifies a file. In this
|
||||
@@ -807,7 +823,7 @@ a project extension, created with `treemacs-define-project-extension', the
|
||||
first element of the path must instead be the keyword `:custom', followed by the
|
||||
node's unique path. The second argument is therefore ignored in this case.
|
||||
|
||||
Either way this fuction will return a marker to the moved to position if it was
|
||||
Either way this function will return a marker to the moved to position if it was
|
||||
successful.
|
||||
|
||||
PATH: Filepath | Node Path
|
||||
@@ -1033,7 +1049,7 @@ It needs to be moved aside in a way that works for all indent depths and
|
||||
(forward-char 1)))))
|
||||
|
||||
(defun treemacs--read-first-project-path ()
|
||||
"Read the first project on init with an empty workspace.
|
||||
"Read the first project on start with an empty workspace.
|
||||
This function is extracted here specifically so that treemacs-projectile can
|
||||
overwrite it so as to present the project root instead of the current dir as the
|
||||
first choice."
|
||||
@@ -1042,7 +1058,7 @@ first choice."
|
||||
|
||||
(defun treemacs--sort-value-selection ()
|
||||
"Interactive selection for a new `treemacs-sorting' value.
|
||||
Retursns a cons cell of a descriptive string name and the sorting symbol."
|
||||
Returns a cons cell of a descriptive string name and the sorting symbol."
|
||||
(declare (side-effect-free t))
|
||||
(let* ((sort-names '(("Sort Alphabetically Ascending" . alphabetic-asc)
|
||||
("Sort Alphabetically Descending" . alphabetic-desc)
|
||||
@@ -1169,7 +1185,7 @@ PATH: Node Path"
|
||||
|
||||
(defun treemacs--copy-or-move (action)
|
||||
"Internal implementation for copying and moving files.
|
||||
ACTION will be either `:copy' or `:move', depenting on whether we are calling
|
||||
ACTION will be either `:copy' or `:move', depending on whether we are calling
|
||||
from `treemacs-copy-file' or `treemacs-move-file'."
|
||||
(let ((no-node-msg)
|
||||
(wrong-type-msg)
|
||||
@@ -1196,11 +1212,13 @@ from `treemacs-copy-file' or `treemacs-move-file'."
|
||||
wrong-type-msg)
|
||||
(let* ((source (treemacs-button-get node :path))
|
||||
(source-name (treemacs--filename source))
|
||||
(destination (treemacs--unslash (read-file-name prompt nil default-directory :must-match)))
|
||||
(destination (treemacs--unslash (read-file-name prompt nil default-directory)))
|
||||
(target-is-dir? (file-directory-p destination))
|
||||
(target-name (if target-is-dir? (treemacs--filename source) (treemacs--filename destination)))
|
||||
(destination-dir (if target-is-dir? destination (treemacs--parent-dir destination)))
|
||||
(target (treemacs--find-repeated-file-name (f-join destination-dir target-name))))
|
||||
(unless (file-exists-p destination-dir)
|
||||
(make-directory destination-dir :parents))
|
||||
(when (eq action :move)
|
||||
;; do the deletion *before* moving the file, otherwise it will no longer exist and treemacs will
|
||||
;; not recognize it as a file path
|
||||
@@ -1232,6 +1250,18 @@ exists it returns /file/name (Copy 2).ext etc."
|
||||
(setf new-path (f-join dir (concat filename-no-ext (format template n) ext))))
|
||||
new-path))
|
||||
|
||||
(defun treemacs--read-string (prompt &optional initial-input)
|
||||
"Read a string with an interface based on `treemacs-read-string-input'.
|
||||
PROMPT and INITIAL-INPUT will be passed on to the read function.
|
||||
|
||||
PROMPT: String
|
||||
INITIAL-INPUT: String"
|
||||
(declare (side-effect-free t))
|
||||
(pcase treemacs-read-string-input
|
||||
('from-child-frame (cfrs-read prompt initial-input))
|
||||
('from-minibuffer (read-string prompt initial-input))
|
||||
(other (user-error "Unknown read-string-input value: `%s'" other))))
|
||||
|
||||
(provide 'treemacs-core-utils)
|
||||
|
||||
;;; treemacs-core-utils.el ends here
|
||||
|
||||
Reference in New Issue
Block a user