ztree-1.0.6/0000755000175000017500000000000014036000457012500 5ustar dogslegdogslegztree-1.0.6/ztree-diff-model.el0000644000175000017500000004133314024072101016153 0ustar dogslegdogsleg;;; ztree-diff-model.el --- diff model for directory trees -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2021 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov ;; ;; Created: 2013-11-11 ;; ;; Keywords: files tools ;; URL: https://github.com/fourier/ztree ;; Compatibility: GNU Emacs 24.x ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;; Diff model ;;; Code: (require 'ztree-util) (eval-when-compile (require 'cl-lib)) (defvar ztree-diff-consider-file-permissions nil "Mark files as different if their permissions are different") (defvar ztree-diff-consider-file-size t "Mark files as different if their size different") (defvar ztree-diff-additional-options nil "Command-line options for the diff program used as a diff backend. These options are added to default '-q' option. Should be a list of strings. Example: (setq ztree-diff-options '(\"-w\" \"-i\"))") (defvar-local ztree-diff-model-ignore-fun nil "Function which determines if the node should be excluded from comparison.") ;; Create a record ztree-diff-node with defined fields and getters/setters ;; here: ;; parent - parent node ;; left-path is the full path on the left side of the diff window, ;; right-path is the full path of the right side, ;; short-name - is the file or directory name ;; children - list of nodes - files or directories if the node is a directory ;; different = {nil, 'same, 'new, 'diff, 'ignore} - means comparison status (cl-defstruct (ztree-diff-node (:constructor) (:constructor ztree-diff-node-create (parent left-path right-path different &aux (short-name (ztree-file-short-name (or left-path right-path))) (right-short-name (if (and left-path right-path) (ztree-file-short-name right-path) short-name))))) parent left-path right-path short-name right-short-name children different) (defun ztree-diff-model-ignore-p (node) "Determine if the NODE should be excluded from comparison results." (when ztree-diff-model-ignore-fun (funcall ztree-diff-model-ignore-fun node))) (defun ztree-diff-node-to-string (node) "Construct the string with contents of the NODE given." (let ((string-or-nil #'(lambda (x) (if x (cond ((stringp x) x) ((eq x 'new) "new") ((eq x 'diff) "different") ((eq x 'ignore) "ignored") ((eq x 'same) "same") (t (ztree-diff-node-short-name x))) "(empty)"))) (children (ztree-diff-node-children node)) (ch-str "")) (dolist (x children) (setq ch-str (concat ch-str "\n * " (ztree-diff-node-short-name x) ": " (funcall string-or-nil (ztree-diff-node-different x))))) (concat "Node: " (ztree-diff-node-short-name node) "\n" " * Parent: " (funcall string-or-nil (ztree-diff-node-parent node)) "\n" " * Status: " (funcall string-or-nil (ztree-diff-node-different node)) "\n" " * Left path: " (funcall string-or-nil (ztree-diff-node-left-path node)) "\n" " * Right path: " (funcall string-or-nil (ztree-diff-node-right-path node)) "\n" " * Children: " ch-str "\n"))) (defun ztree-diff-node-short-name-wrapper (node &optional right-side) "Return the short name of the NODE given. If the RIGHT-SIDE is true, take the right leaf" (if (not right-side) (ztree-diff-node-short-name node) (ztree-diff-node-right-short-name node))) (defun ztree-diff-node-is-directory (node) "Determines if the NODE is a directory." (let ((left (ztree-diff-node-left-path node)) (right (ztree-diff-node-right-path node))) (if left (file-directory-p left) (file-directory-p right)))) (defun ztree-diff-node-side (node) "Determine the side there the file is present for NODE. Return BOTH if the file present on both sides; LEFT if only on the left side and RIGHT if only on the right side." (let ((left (ztree-diff-node-left-path node)) (right (ztree-diff-node-right-path node))) (if (and left right) 'both (if left 'left 'right)))) (defun ztree-diff-node-equal (node1 node2) "Determines if NODE1 and NODE2 are equal." (and (string-equal (ztree-diff-node-short-name node1) (ztree-diff-node-short-name node2)) (string-equal (ztree-diff-node-left-path node1) (ztree-diff-node-left-path node2)) (string-equal (ztree-diff-node-right-path node1) (ztree-diff-node-right-path node1)))) (defun ztree-diff-model-files-equal (file1 file2) "Compare files FILE1 and FILE2 using external diff. Returns t if equal." (unless (ztree-same-host-p file1 file2) (error "Compared files are not on the same host")) (let* ((file1-untrampified (ztree-untrampify-filename file1)) (file2-untrampified (ztree-untrampify-filename file2))) (if (or (and ztree-diff-consider-file-size (/= (nth 7 (file-attributes file1)) (nth 7 (file-attributes file2)))) (and ztree-diff-consider-file-permissions (not (string-equal (nth 8 (file-attributes file1)) (nth 8 (file-attributes file2))))) (/= 0 (apply #'process-file diff-command nil nil nil `("-q" ,@ztree-diff-additional-options ,file1-untrampified ,file2-untrampified)))) 'diff 'same))) (defun ztree-directory-files (dir) "Return the list of full paths of files in a directory DIR. Filters out . and .." (ztree-filter #'(lambda (file) (let ((simple-name (ztree-file-short-name file))) (not (or (string-equal simple-name ".") (string-equal simple-name ".."))))) (directory-files dir 'full))) (defun ztree-diff-model-partial-rescan (node) "Rescan the NODE. The node is a either a file or directory with both left and right parts existing." ;; if a directory - recreate (if (ztree-diff-node-is-directory node) (ztree-diff-node-recreate-with-progress node) ;; if a file, change a status (setf (ztree-diff-node-different node) (if (or (ztree-diff-model-ignore-p node) ; if should be ignored (eql (ztree-diff-node-different node) 'ignore) ; was ignored (eql (ztree-diff-node-different ; or parent was ignored (ztree-diff-node-parent node)) 'ignore)) 'ignore (ztree-diff-model-files-equal (ztree-diff-node-left-path node) (ztree-diff-node-right-path node))))) ;; update all parents statuses (ztree-diff-node-update-all-parents-diff node)) (defun ztree-diff-model-subtree (parent path side diff) "Create a subtree with given PARENT for the given PATH. Argument SIDE either `left' or `right' side. Argument DIFF different status to be assigned to all created nodes." (let ((files (ztree-directory-files path)) (result nil)) (dolist (file files) (if (file-directory-p file) (let* ((node (ztree-diff-node-create parent (when (eq side 'left) file) (when (eq side 'right) file) diff)) (children (ztree-diff-model-subtree node file side diff))) (setf (ztree-diff-node-children node) children) (push node result)) (push (ztree-diff-node-create parent (when (eq side 'left) file) (when (eq side 'right) file) diff) result))) result)) (defun ztree-diff-node-update-diff-from-children (node) "Set the diff status for the NODE based on its children." (unless (eql (ztree-diff-node-different node) 'ignore) (let ((diff (cl-reduce #'ztree-diff-model-update-diff (ztree-diff-node-children node) :initial-value 'same :key 'ztree-diff-node-different))) (setf (ztree-diff-node-different node) diff)))) (defun ztree-diff-node-update-all-parents-diff (node) "Recursively update all parents diff status for the NODE." (let ((parent node)) (while (setq parent (ztree-diff-node-parent parent)) (ztree-diff-node-update-diff-from-children parent)))) (defun ztree-diff-model-update-diff (old new) "Get the diff status depending if OLD or NEW is not nil. If the OLD is `ignore', do not change anything" ;; if the old whole directory is ignored, ignore children's status (cond ((eql old 'ignore) 'ignore) ;; if the new status is ignored, use old ((eql new 'ignore) old) ;; if the old or new status is different, return different ((or (eql old 'diff) (eql new 'diff)) 'diff) ;; if new is 'new, return new ((eql new 'new) 'new) ;; all other cases return old (t old))) (defun ztree-diff-node-update-diff-from-parent (node) "Recursively update diff status of all children of NODE. This function will traverse through all children recursively setting status from the NODE, unless they have an ignore status" (let ((status (ztree-diff-node-different node)) (children (ztree-diff-node-children node))) ;; if the parent has ignore status, force all kids this status ;; otherwise only update status when the child status is not ignore (mapc (lambda (child) (when (or (eql status 'ignore) (not (or (eql status 'ignore) (eql (ztree-diff-node-different child) 'ignore)))) (setf (ztree-diff-node-different child) status) (ztree-diff-node-update-diff-from-parent child))) children))) (defun ztree-diff-model-find-in-files (list shortname is-dir) "Find in LIST of files the file with name SHORTNAME. If IS-DIR searching for directories; assume files otherwise" (ztree-find list (lambda (x) (and (string-equal (ztree-file-short-name x) shortname) (eq is-dir (file-directory-p x)))))) (defun ztree-diff-model-should-ignore (node) "Determine if the NODE and its children should be ignored. If no parent - never ignore; if in ignore list - ignore if parent has ignored status - ignore" (let ((parent (ztree-diff-node-parent node))) (and parent (or (eql (ztree-diff-node-different parent) 'ignore) (ztree-diff-model-ignore-p node))))) (defun ztree-diff-node-recreate-with-progress (node) "Initiate update of the NODE with a progress printout" (let ((progress-reporter (make-progress-reporter (concat "Comparing " (ztree-diff-node-left-path node) " and " (ztree-diff-node-right-path node) " ...")))) (ztree-diff-node-recreate node progress-reporter) (progress-reporter-done progress-reporter))) (defun ztree-diff-node-recreate (node &optional reporter) "Traverse 2 paths defined in the NODE updating its children and status. When REPORTER provided update the progress." (let* ((list1 (ztree-directory-files (ztree-diff-node-left-path node))) ;; left list of liles (list2 (ztree-directory-files (ztree-diff-node-right-path node))) ;; right list of files (should-ignore (ztree-diff-model-should-ignore node)) ;; status automatically assigned to children of the node (children-status (if should-ignore 'ignore 'new)) (children nil)) ;; list of children ;; update waiting status (when reporter (progress-reporter-update reporter)) ;; update node status ignore status either inhereted from the ;; parent or the own (when should-ignore (setf (ztree-diff-node-different node) 'ignore)) ;; first - adding all entries from left directory (dolist (file1 list1) ;; for every entry in the first directory ;; we are creating the node (let* ((simple-name (ztree-file-short-name file1)) (isdir (file-directory-p file1)) ;; find if the file is in the second directory and the type ;; is the same - i.e. both are directories or both are files (file2 (ztree-diff-model-find-in-files list2 simple-name isdir)) ;; create a child. The current node is a parent ;; new by default - will be overriden below if necessary (child (ztree-diff-node-create node file1 file2 children-status))) ;; update child own ignore status (when (ztree-diff-model-should-ignore child) (setf (ztree-diff-node-different child) 'ignore)) ;; if exists on a right side with the same type, ;; remove from the list of files on the right side (when file2 (setf list2 (cl-delete file2 list2 :test #'string-equal))) (cond ;; when exist just on a left side and is a directory, add all ((and isdir (not file2)) (setf (ztree-diff-node-children child) (ztree-diff-model-subtree child file1 'left (ztree-diff-node-different child)))) ;; if 1) exists on both sides and 2) it is a file ;; and 3) not ignored file ((and file2 (not isdir) (not (eql (ztree-diff-node-different child) 'ignore))) (setf (ztree-diff-node-different child) (ztree-diff-model-files-equal file1 file2))) ;; if exists on both sides and it is a directory, traverse further ((and file2 isdir) (ztree-diff-node-recreate child))) ;; push the created node to the children list (push child children))) ;; second - adding entries from the right directory which are not present ;; in the left directory (dolist (file2 list2) ;; for every entry in the second directory ;; we are creating the node (let* ((isdir (file-directory-p file2)) ;; create the child to be added to the results list (child (ztree-diff-node-create node nil file2 children-status))) ;; update ignore status of the child (when (ztree-diff-model-should-ignore child) (setf (ztree-diff-node-different child) 'ignore)) ;; if it is a directory, set the whole subtree to children (when isdir (setf (ztree-diff-node-children child) (ztree-diff-model-subtree child file2 'right (ztree-diff-node-different child)))) ;; push the created node to the result list (push child children))) ;; finally set different status based on all children ;; depending if the node should participate in overall result (unless should-ignore (setf (ztree-diff-node-different node) (cl-reduce #'ztree-diff-model-update-diff children :initial-value 'same :key 'ztree-diff-node-different))) ;; and set children (setf (ztree-diff-node-children node) children))) (defun ztree-diff-model-update-node (node) "Refresh the NODE." (ztree-diff-node-recreate-with-progress node)) (defun ztree-diff-model-set-ignore-fun (ignore-p) "Set the buffer-local ignore function to IGNORE-P. Ignore function is a function of one argument (ztree-diff-node) which returns t if the node should be ignored (like files starting with dot etc)." (setf ztree-diff-model-ignore-fun ignore-p)) (provide 'ztree-diff-model) ;;; ztree-diff-model.el ends here ztree-1.0.6/ztree-util.el0000644000175000017500000000673314024072101015127 0ustar dogslegdogsleg;;; ztree-util.el --- Auxiliary utilities for the ztree package -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2021 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov ;; ;; Created: 2013-11-11 ;; ;; Keywords: files tools ;; URL: https://github.com/fourier/ztree ;; Compatibility: GNU Emacs 24.x ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;;; Code: (defmacro def-ztree-local-fun (name doc) "Create a buffer-local variable NAME-FUN and a function NAME. Both variables and a function will have a documentation DOC. Function will FUNCALL the variable NAME-FUN. Used to create callbacks. Example: (macroexpand-1 '(def-ztree-local-fun add \"Addition\")) (progn (defvar-local add-fun nil \"Addition\") (defun add (&rest args) \"Addition\" (apply add-fun args)))" (let ((var (intern (concat (symbol-name name) "-fun")))) `(progn (defvar-local ,var nil ,doc) (defun ,name (&rest args) ,doc (apply ,var args))))) (defun ztree-find (where which) "Find element of the list WHERE matching predicate WHICH." (catch 'found (dolist (elt where) (when (funcall which elt) (throw 'found elt))) nil)) (defun ztree-filter (condp lst) "Filter out elements not satisfying predicate CONDP in the list LST. Taken from http://www.emacswiki.org/emacs/ElispCookbook#toc39" (delq nil (mapcar (lambda (x) (and (funcall condp x) x)) lst))) (defun ztree-printable-string (string) "Strip newline character from file names, like `Icon\n'. Argument STRING string to process.'." (replace-regexp-in-string "\n" "" string)) (defun ztree-file-short-name (file) "By given FILE name return base file/directory name. Taken from http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01238.html" (let* ((dir (directory-file-name file)) (simple-dir (file-name-nondirectory dir))) ;; check if the root directory (if (string= "" simple-dir) dir (ztree-printable-string simple-dir)))) (defun ztree-car-atom (value) "Return VALUE if value is an atom, otherwise (car value) or nil. Used since `car-safe' returns nil for atoms" (if (atom value) value (car value))) (defun ztree-insert-with-face (text face) "Insert TEXT with the FACE provided." (let ((start (point))) (insert text) (put-text-property start (point) 'face face))) (defun ztree-untrampify-filename (file) "Return FILE as the local file name." (or (file-remote-p file 'localname) file)) (defun ztree-quotify-string (str) "Surround STR with quotes." (concat "\"" str "\"")) (defun ztree-same-host-p (file1 file2) "Return t if FILE1 and FILE2 are on the same host." (let ((file1-remote (file-remote-p file1)) (file2-remote (file-remote-p file2))) (string-equal file1-remote file2-remote))) (provide 'ztree-util) ;;; ztree-util.el ends here ztree-1.0.6/ztree-pkg.el0000644000175000017500000000055114036000457014733 0ustar dogslegdogsleg;; Generated package description from ztree.el -*- no-byte-compile: t -*- (define-package "ztree" "1.0.6" "Text mode directory tree" '((cl-lib "0")) :keywords '("files" "tools") :authors '(("Alexey Veretennikov" . "alexey.veretennikov@gmail.com")) :maintainer '("Alexey Veretennikov" . "alexey.veretennikov@gmail.com") :url "https://github.com/fourier/ztree") ztree-1.0.6/ztree-dir.el0000644000175000017500000001730314024072101014723 0ustar dogslegdogsleg;;; ztree-dir.el --- Text mode directory tree -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2021 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov ;; ;; Created: 2013-11-11 ;; ;; Keywords: files tools ;; URL: https://github.com/fourier/ztree ;; Compatibility: GNU Emacs 24.x ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;; ;; Add the following to your .emacs file: ;; ;; (push (substitute-in-file-name "path-to-ztree-directory") load-path) ;; (require 'ztree-dir) ;; ;; Call the ztree interactive function: ;; M-x ztree-dir ;; Open/close directories with double-click, Enter or Space keys ;; ;;; Issues: ;; ;;; TODO: ;; 1) Add some file-handling and marking abilities ;; ;;; Code: (require 'ztree-util) (require 'ztree-view) (require 'ztree-protocol) (eval-when-compile (require 'cl-lib)) ;; ;; Constants ;; (defconst ztree-hidden-files-regexp "^\\." "Hidden files regexp. By default all filest starting with dot `.', including . and ..") ;; ;; Configurable variables ;; (defvar ztree-dir-move-focus nil "Defines if move focus to opened window on hard-action command (RETURN) on a file.") (defvar-local ztree-dir-filter-list (list ztree-hidden-files-regexp) "List of regexp file names to filter out. By default paths starting with dot (like .git) are ignored. One could add own filters in the following way: (setq-default ztree-dir-filter-list (cons \"^.*\\.pyc\" ztree-dir-filter-list)) ") (defvar-local ztree-dir-show-filtered-files nil "Show or not files from the filtered list.") ;; ;; Faces ;; (defface ztreep-header-face '((((type tty pc) (class color)) :foreground "lightblue" :weight bold) (((background dark)) (:height 1.2 :foreground "lightblue" :weight bold)) (t :height 1.2 :foreground "darkblue" :weight bold)) "*Face used for the header in Ztree buffer." :group 'Ztree :group 'font-lock-highlighting-faces) (defvar ztreep-header-face 'ztreep-header-face) (define-minor-mode ztreedir-mode "A minor mode for displaying the directory trees in text mode." ;; initial value nil ;; modeline name " Dir" ;; The minor mode keymap `( (,(kbd "H") . ztree-dir-toggle-show-filtered-files) (,(kbd ">") . ztree-dir-narrow-to-dir) (,(kbd "<") . ztree-dir-widen-to-parent) (,(kbd "d") . ztree-dir-open-dired-at-point))) ;; ;; File bindings to the directory tree control ;; (defun ztree-insert-buffer-header () "Insert the header to the ztree buffer." (let ((start (point))) (insert "Directory tree") (insert "\n") (insert "==============") (set-text-properties start (point) '(face ztreep-header-face))) (insert "\n")) (defun ztree-file-not-hidden (filename) "Determines if the file with FILENAME should be visible." (let ((name (ztree-file-short-name filename))) (and (not (or (string= name ".") (string= name ".."))) (or ztree-dir-show-filtered-files (not (cl-find-if (lambda (rx) (string-match rx name)) ztree-dir-filter-list)))))) (defun ztree-find-file (node hard) "Find the file at NODE. If HARD is non-nil, the file is opened in another window. Otherwise, the ztree window is used to find the file." (when (and (stringp node) (file-readable-p node)) (cond ((and hard ztree-dir-move-focus) (find-file-other-window node)) (hard (save-selected-window (find-file-other-window node))) (t (find-file node))))) (defun ztree-dir-toggle-show-filtered-files () "Toggle visibility of the filtered files." (interactive) (setq ztree-dir-show-filtered-files (not ztree-dir-show-filtered-files)) (message (concat (if ztree-dir-show-filtered-files "Show" "Hide") " filtered files")) (ztree-refresh-buffer)) (defun ztree-dir-directory-files (path) "Return the list of files/directories for the given PATH." ;; remove . and .. from the list of files to avoid infinite ;; recursion (cl-remove-if (lambda (x) (string-match-p "/\\.\\.?$" x)) (directory-files path 'full))) (defun ztree-dir-change-directory (node) "Change the start node to NODE and update current directory." (ztree-change-start-node node) (setq default-directory node)) (defun ztree-dir-narrow-to-dir () "Interactive command to narrow the current directory buffer. The buffer is narrowed to the directory under the cursor. If the cursor is on a file, the buffer is narrowed to the parent directory." (interactive) (let* ((line (line-number-at-pos)) (node (ztree-find-node-in-line line)) (parent (ztree-get-parent-for-line line))) (if (file-directory-p node) (ztree-dir-change-directory node) (when parent (ztree-dir-change-directory (ztree-find-node-in-line parent)))))) (defun ztree-dir-widen-to-parent () "Interactive command to widen the current directory buffer to parent. The buffer is widened to the parent of the directory of the current buffer. This allows to jump to the parent directory if this directory is one level up of the opened." (interactive) (let* ((node ztree-start-node) (parent (file-name-directory (directory-file-name node)))) (when parent (ztree-dir-change-directory parent)))) (defun ztree-dir-open-dired-at-point () "If the point is on a directory, open DIRED with this directory. Otherwise open DIRED with the parent directory" (interactive) (let* ((line (line-number-at-pos)) (node (ztree-find-node-in-line line)) (parent (ztree-get-parent-for-line line))) (cond ((and node (file-directory-p node)) (dired node)) (parent (dired (ztree-find-node-in-line parent)))))) ;; ;; Implementation of the ztree-protocol ;; (cl-defmethod ztree-node-visible-p ((file string)) "Return T if the NODE shall be visible." (ztree-file-not-hidden file)) (cl-defmethod ztree-node-short-name ((file string)) "Return the short name for a node." (ztree-file-short-name file)) (cl-defmethod ztree-node-expandable-p ((file string)) "Return T if the node is expandable." (file-directory-p file)) (cl-defmethod ztree-node-equal ((file1 string) (file2 string)) "Equality function for NODE1 and NODE2. Return T if nodes are equal" (string-equal file1 file2)) (cl-defmethod ztree-node-children ((file string)) "Return a list of NODE children" (ztree-dir-directory-files file)) (cl-defmethod ztree-node-action ((file string) hard) "Perform an action when the Return is pressed on a NODE." (ztree-find-file file hard)) ;; for ztree-node-side, ztree-node-face, ztree-node-left-short-name ;; and ztree-node-right-short-name use default implementations ;; ;; Entry point ;; ;;;###autoload (defun ztree-dir (path) "Create an interactive buffer with the directory tree of the PATH given." (interactive "DDirectory: ") (when (and (file-exists-p path) (file-directory-p path)) (let ((buf-name (concat "*Directory " path " tree*"))) (ztree-view buf-name #'ztree-insert-buffer-header (expand-file-name (substitute-in-file-name path)) #'ztreedir-mode nil)))) (provide 'ztree-dir) ;;; ztree-dir.el ends here ztree-1.0.6/ztree-diff.el0000644000175000017500000006224414036000457015071 0ustar dogslegdogsleg;;; ztree-diff.el --- Text mode diff for directory trees -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2021 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov ;; ;; Created: 2013-11-11 ;; ;; Keywords: files tools ;; URL: https://github.com/fourier/ztree ;; Compatibility: GNU Emacs 24.x ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;;; Code: (eval-when-compile (require 'cl-lib)) (require 'ztree-view) (require 'ztree-diff-model) (defconst ztree-diff-hidden-files-regexp "^\\." "Hidden files regexp. By default all filest starting with dot `.', including . and ..") (defface ztreep-diff-header-face '((((type tty pc) (class color)) :foreground "lightblue" :weight bold) (((background dark)) (:height 1.2 :foreground "lightblue" :weight bold)) (t :height 1.2 :foreground "darkblue" :weight bold)) "*Face used for the header in Ztree Diff buffer." :group 'Ztree-diff :group 'font-lock-highlighting-faces) (defvar ztreep-diff-header-face 'ztreep-diff-header-face) (defface ztreep-diff-header-small-face '((((type tty pc) (class color)) :foreground "lightblue" :weight bold) (((background dark)) (:foreground "lightblue" :weight bold)) (t :weight bold :foreground "darkblue")) "*Face used for the header in Ztree Diff buffer." :group 'Ztree-diff :group 'font-lock-highlighting-faces) (defvar ztreep-diff-header-small-face 'ztreep-diff-header-small-face) (defface ztreep-diff-model-diff-face '((t (:foreground "red"))) "*Face used for different files in Ztree-diff." :group 'Ztree-diff :group 'font-lock-highlighting-faces) (defvar ztreep-diff-model-diff-face 'ztreep-diff-model-diff-face) (defface ztreep-diff-model-add-face '((t (:foreground "blue"))) "*Face used for added files in Ztree-diff." :group 'Ztree-diff :group 'font-lock-highlighting-faces) (defvar ztreep-diff-model-add-face 'ztreep-diff-model-add-face) (defface ztreep-diff-model-ignored-face '((((type tty pc) (class color) (min-colors 256)) :foreground "#2f2f2f") (((type tty pc) (class color) (min-colors 8)) :foreground "white") (t (:foreground "#7f7f7f" :strike-through t))) "*Face used for non-modified files in Ztree-diff." :group 'Ztree-diff :group 'font-lock-highlighting-faces) (defvar ztreep-diff-model-ignored-face 'ztreep-diff-model-ignored-face) (defface ztreep-diff-model-normal-face '((((type tty pc) (class color) (min-colors 8)) :foreground "white") (t (:foreground "#7f7f7f"))) "*Face used for non-modified files in Ztree-diff." :group 'Ztree-diff :group 'font-lock-highlighting-faces) (defvar ztreep-diff-model-normal-face 'ztreep-diff-model-normal-face) (defvar-local ztree-diff-filter-list (list ztree-diff-hidden-files-regexp) "List of regexp file names to filter out. By default paths starting with dot (like .git) are ignored") (defvar-local ztree-diff-dirs-pair nil "Pair of the directories stored. Used to perform the full rescan.") (defvar-local ztree-diff-show-equal-files t "Show or not equal files/directories on both sides.") (defvar-local ztree-diff-show-filtered-files nil "Show or not files from the filtered list.") (defvar-local ztree-diff-show-right-orphan-files t "Show or not orphan files/directories on right side.") (defvar-local ztree-diff-show-left-orphan-files t "Show or not orphan files/directories on left side.") (defvar ztree-diff-ediff-previous-window-configurations nil "Window configurations prior to calling `ediff'. A queue of window configurations, allowing to restore last configuration even if there were a couple of ediff sessions") ;;;###autoload (define-minor-mode ztreediff-mode "A minor mode for displaying the difference of the directory trees in text mode." ;; initial value nil ;; modeline name " Diff" ;; The minor mode keymap `( (,(kbd "C") . ztree-diff-copy) (,(kbd "h") . ztree-diff-toggle-show-equal-files) (,(kbd "H") . ztree-diff-toggle-show-filtered-files) (,(kbd "D") . ztree-diff-delete-file) (,(kbd "v") . ztree-diff-view-file) (,(kbd "d") . ztree-diff-simple-diff-files) (,(kbd "r") . ztree-diff-partial-rescan) (,(kbd "R") . ztree-diff-full-rescan) ([f5] . ztree-diff-full-rescan))) (defun ztree-diff-node-face (node) "Return the face for the NODE depending on diff status." (let ((diff (ztree-diff-node-different node))) (cond ((eq diff 'ignore) ztreep-diff-model-ignored-face) ((eq diff 'diff) ztreep-diff-model-diff-face) ((eq diff 'new) ztreep-diff-model-add-face) ((eq diff 'same) ztreep-diff-model-normal-face)))) (defun ztree-diff-insert-buffer-header () "Insert the header to the ztree buffer." (ztree-insert-with-face "Differences tree" ztreep-diff-header-face) (insert "\n") (when ztree-diff-dirs-pair (ztree-insert-with-face (concat "Left: " (car ztree-diff-dirs-pair)) ztreep-diff-header-small-face) (insert "\n") (ztree-insert-with-face (concat "Right: " (cdr ztree-diff-dirs-pair)) ztreep-diff-header-small-face) (insert "\n")) (ztree-insert-with-face "Legend:" ztreep-diff-header-small-face) (insert "\n") (ztree-insert-with-face " Normal file " ztreep-diff-model-normal-face) (ztree-insert-with-face "- same on both sides" ztreep-diff-header-small-face) (insert "\n") (ztree-insert-with-face " Orphan file " ztreep-diff-model-add-face) (ztree-insert-with-face "- does not exist on other side" ztreep-diff-header-small-face) (insert "\n") (ztree-insert-with-face " Mismatch file " ztreep-diff-model-diff-face) (ztree-insert-with-face "- different from other side" ztreep-diff-header-small-face) (insert "\n ") (ztree-insert-with-face "Ignored file" ztreep-diff-model-ignored-face) (ztree-insert-with-face " - ignored from comparison" ztreep-diff-header-small-face) (insert "\n") (ztree-insert-with-face "==============" ztreep-diff-header-face) (insert "\n")) (defun ztree-diff-full-rescan () "Force full rescan of the directory trees." (interactive) (when (and ztree-diff-dirs-pair (yes-or-no-p (format "Force full rescan?"))) (ztree-diff (car ztree-diff-dirs-pair) (cdr ztree-diff-dirs-pair)))) (defun ztree-diff-existing-common (node) "Return the NODE if both left and right sides exist." (let ((left (ztree-diff-node-left-path node)) (right (ztree-diff-node-right-path node))) (if (and left right (file-exists-p left) (file-exists-p right)) node nil))) (defun ztree-diff-existing-common-parent (node) "Return the first node in up in hierarchy of the NODE which has both sides." (let ((common (ztree-diff-existing-common node))) (if common common (ztree-diff-existing-common-parent (ztree-diff-node-parent node))))) (defun ztree-diff-do-partial-rescan (node) "Partly rescan the NODE." (let* ((common (ztree-diff-existing-common-parent node)) (parent (ztree-diff-node-parent common))) (if (not parent) (when ztree-diff-dirs-pair (ztree-diff (car ztree-diff-dirs-pair) (cdr ztree-diff-dirs-pair))) (ztree-diff-model-partial-rescan common) (ztree-refresh-buffer (line-number-at-pos))))) (defun ztree-diff-partial-rescan () "Perform partial rescan on the current node." (interactive) (let ((found (ztree-find-node-at-point))) (when found (ztree-diff-do-partial-rescan (car found))))) (defun ztree-diff-simple-diff (node) "Create a simple diff buffer for files from left and right panels. Argument NODE node containing paths to files to call a diff on." (let* ((node-left (ztree-diff-node-left-path node)) (node-right (ztree-diff-node-right-path node))) (when (and node-left node-right (not (file-directory-p node-left))) ;; show the diff window on the bottom ;; to not to crush tree appearance (let ((split-width-threshold nil)) (diff node-left node-right))))) (defun ztree-diff-simple-diff-files () "Create a simple diff buffer for files from left and right panels." (interactive) (let ((found (ztree-find-node-at-point))) (when found (let ((node (car found))) (ztree-diff-simple-diff node))))) (defun ztree-diff-ediff-before-setup-hook-function () "Hook function for `ediff-before-setup-hook'. See the Info node `(ediff) hooks'. This hook function removes itself." (push (current-window-configuration) ztree-diff-ediff-previous-window-configurations) (ztree-save-current-position) (remove-hook 'ediff-before-setup-hook #'ztree-diff-ediff-before-setup-hook-function)) (defun ztree-diff-ediff-quit-hook-function () "Hook function for `ediff-quit-hook'. See the Info node `(ediff) hooks'. This hook function removes itself." (set-window-configuration (pop ztree-diff-ediff-previous-window-configurations)) (ztree-refresh-buffer) (remove-hook 'ediff-quit-hook #'ztree-diff-ediff-quit-hook-function)) (defun ztree-diff-ediff (file-a file-b &optional startup-hooks) "Ediff that cleans up after itself. Ediff-related buffers are killed and the pre-Ediff window configuration is restored." (add-hook 'ediff-before-setup-hook #'ztree-diff-ediff-before-setup-hook-function) (add-hook 'ediff-quit-hook #'ztree-diff-ediff-quit-hook-function t) (ediff file-a file-b startup-hooks)) (defun ztree-diff-node-action (node hard) "Perform action on NODE: 1 if both left and right sides present: 1.1 if they are differend 1.1.1 if HARD ediff 1.1.2 simple diff otherwiste 1.2 if they are the same - view left 2 if left or right present - view left or rigth" ;; save current position in case if the window ;; configuration will change (ztree-save-current-position) (let ((left (ztree-diff-node-left-path node)) (right (ztree-diff-node-right-path node)) ;; FIXME: The GNU convention is to only use "path" for lists of ;; directories as in load-path. (open-f #'(lambda (path) (if hard (find-file path) (let ((split-width-threshold nil)) (view-file-other-window path)))))) (cond ((and left right) (if (eql (ztree-diff-node-different node) 'same) (funcall open-f left) (if hard (ztree-diff-ediff left right) (ztree-diff-simple-diff node)))) (left (funcall open-f left)) (right (funcall open-f right)) (t nil)))) (defun ztree-diff-copy-file (node source-path destination-path copy-to-right) "Update the NODE status and copy the file. File copied from SOURCE-PATH to DESTINATION-PATH. COPY-TO-RIGHT specifies which side of the NODE to update." (let ((target-path (concat (file-name-as-directory destination-path) (file-name-nondirectory (directory-file-name source-path))))) (let ((err (condition-case error-trap (progn ;; don't ask for overwrite ;; keep time stamp (copy-file source-path target-path t t) nil) (error error-trap)))) ;; error message if failed (if err (message (concat "Error: " (nth 2 err))) ;; otherwise: ;; assuming all went ok when left and right nodes are the same ;; set both as not different if they were not ignored (unless (eq (ztree-diff-node-different node) 'ignore) (setf (ztree-diff-node-different node) 'same)) ;; update left/right paths (if copy-to-right (setf (ztree-diff-node-right-path node) target-path) (setf (ztree-diff-node-left-path node) target-path)) (ztree-diff-node-update-all-parents-diff node) (ztree-refresh-buffer (line-number-at-pos)))))) (defun ztree-diff-copy-dir (node source-path destination-path copy-to-right) "Update the NODE status and copy the directory. Directory copied from SOURCE-PATH to DESTINATION-PATH. COPY-TO-RIGHT specifies which side of the NODE to update." (let* ((src-path (file-name-as-directory source-path)) (target-path (file-name-as-directory destination-path)) (target-full-path (concat target-path (file-name-nondirectory (directory-file-name source-path))))) (let ((err (condition-case error-trap (progn ;; keep time stamp ;; ask for overwrite (copy-directory src-path target-path t t) nil) (error error-trap)))) ;; error message if failed (if err (progn (message (concat "Error: " (nth 1 err))) ;; and do rescan of the node (ztree-diff-do-partial-rescan node)) ;; if everything is ok, update statuses (message target-full-path) (if copy-to-right (setf (ztree-diff-node-right-path node) target-full-path) (setf (ztree-diff-node-left-path node) target-full-path)) ;; TODO: do not rescan the node. Use some logic like in delete (ztree-diff-model-update-node node) (ztree-diff-node-update-all-parents-diff node) (ztree-refresh-buffer (line-number-at-pos)))))) (defun ztree-diff-copy () "Copy the file under the cursor to other side." (interactive) (let ((found (ztree-find-node-at-point))) (when found (let* ((node (car found)) (side (cdr found)) (node-side (ztree-diff-node-side node)) (copy-to-right t) ; copy from left to right (node-left (ztree-diff-node-left-path node)) (node-right (ztree-diff-node-right-path node)) (source-path nil) (destination-path nil) (parent (ztree-diff-node-parent node))) (when parent ; do not copy the root node ;; determine a side to copy from/to ;; algorithm: ;; 1) if both side are present, use the side ;; variable (setq copy-to-right (if (eq node-side 'both) (eq side 'left) ;; 2) if one of sides is absent, copy from ;; the side where the file is present (eq node-side 'left))) ;; 3) in both cases determine if the destination ;; directory is in place (setq source-path (if copy-to-right node-left node-right) destination-path (if copy-to-right (ztree-diff-node-right-path parent) (ztree-diff-node-left-path parent))) (when (and source-path destination-path (yes-or-no-p (format "Copy [%s]%s to [%s]%s/ ?" (if copy-to-right "LEFT" "RIGHT") (ztree-diff-node-short-name node) (if copy-to-right "RIGHT" "LEFT") destination-path))) (if (file-directory-p source-path) (ztree-diff-copy-dir node source-path destination-path copy-to-right) (ztree-diff-copy-file node source-path destination-path copy-to-right)))))))) (defun ztree-diff-view-file () "View file at point, depending on side." (interactive) (let ((found (ztree-find-node-at-point))) (when found (let* ((node (car found)) (side (cdr found)) (node-side (ztree-diff-node-side node)) (node-left (ztree-diff-node-left-path node)) (node-right (ztree-diff-node-right-path node))) (when (or (eq node-side 'both) (eq side node-side)) (cond ((and (eq side 'left) node-left) (view-file node-left)) ((and (eq side 'right) node-right) (view-file node-right)))))))) (defun ztree-diff-delete-file () "Delete the file under the cursor." (interactive) (let ((found (ztree-find-node-at-point))) (when found (let* ((node (car found)) (side (cdr found)) (node-side (ztree-diff-node-side node)) (parent (ztree-diff-node-parent node)) ;; algorithm for determining what to delete similar to copy: ;; 1. if the file is present on both sides, delete ;; from the side currently selected ;; 2. if one of sides is absent, delete ;; from the side where the file is present (delete-from-left (or (eql node-side 'left) (and (eql node-side 'both) (eql side 'left)))) (remove-path (if delete-from-left (ztree-diff-node-left-path node) (ztree-diff-node-right-path node)))) (when (and parent ; do not delete the root node (yes-or-no-p (format "Delete the file [%s]%s ?" (if delete-from-left "LEFT" "RIGHT") remove-path))) (let* ((delete-command (if (file-directory-p remove-path) #'delete-directory #'delete-file)) (children (ztree-diff-node-children parent)) (err (condition-case error-trap (progn (funcall delete-command remove-path t) nil) (error error-trap)))) (if err (progn (message (concat "Error: " (nth 2 err))) ;; when error happened while deleting the ;; directory, rescan the node ;; and update the parents with a new status ;; of this node (when (file-directory-p remove-path) (ztree-diff-model-partial-rescan node))) ;; if everything ok ;; if was only on one side ;; remove the node from children (if (or (and (eql node-side 'left) delete-from-left) (and (eql node-side 'right) (not delete-from-left))) (setf (ztree-diff-node-children parent) (ztree-filter (lambda (x) (not (ztree-diff-node-equal x node))) children)) ;; otherwise update only one side (mapc (if delete-from-left (lambda (x) (setf (ztree-diff-node-left-path x) nil)) (lambda (x) (setf (ztree-diff-node-right-path x) nil))) (cons node (ztree-diff-node-children node))) ;; and update diff status ;; if was ignored keep the old status (unless (eql (ztree-diff-node-different node) 'ignore) (setf (ztree-diff-node-different node) 'new)) ;; finally update all children statuses (ztree-diff-node-update-diff-from-parent node))) (ztree-diff-node-update-all-parents-diff node) (ztree-refresh-buffer (line-number-at-pos)))))))) (defun ztree-diff-node-ignore-p (node) "Determine if the NODE is in filter list. If the node is in the filter list it shall not be visible, unless it is a parent node." (let ((name (ztree-diff-node-short-name node))) ;; ignore then ;; not a root and is in filter list (and (ztree-diff-node-parent node) (ztree-find ztree-diff-filter-list #'(lambda (rx) (string-match rx name)))))) (defun ztree-node-is-visible (node) "Determine if the NODE should be visible." (let ((diff (ztree-diff-node-different node))) ;; visible then ;; either it is a root. root have no parent (or (not (ztree-diff-node-parent node)) ; parent is always visible ;; or the files are different (eql diff 'diff) ;; or it is orphaned, but show orphaned files for now (and (eql diff 'new) (if (ztree-diff-node-left-path node) ztree-diff-show-left-orphan-files ztree-diff-show-right-orphan-files)) ;; or it is ignored but we show ignored for now (and (eql diff 'ignore) ztree-diff-show-filtered-files) ;; or they are same but we show same for now (and (eql diff 'same) ztree-diff-show-equal-files)))) (defmacro ztree-diff-define-toggle-show (what) (let ((funcsymbol (intern (concat "ztree-diff-toggle-show-" what "-files"))) (variable (intern (concat "ztree-diff-show-" what "-files"))) (fundesc (concat "Toggle visibility of the " what " files/directories"))) `(defun ,funcsymbol () ,fundesc (interactive) (setq ,variable (not ,variable)) (message (concat (if ,variable "Show " "Hide ") ,what " files")) (ztree-refresh-buffer)))) (ztree-diff-define-toggle-show "equal") (ztree-diff-define-toggle-show "filtered") (ztree-diff-define-toggle-show "left-orphan") (ztree-diff-define-toggle-show "right-orphan") (defun ztree-diff-toggle-show-orphan-files () "Toggle visibility of left and right orphan files." (interactive) (let ((show (not ztree-diff-show-left-orphan-files))) (setq ztree-diff-show-left-orphan-files show) (setq ztree-diff-show-right-orphan-files show) (message (concat (if show "Show" "Hide") " orphan files")) (ztree-refresh-buffer))) ;; ;; Implementation of the ztree-protocol ;; (cl-defmethod ztree-node-visible-p ((node ztree-diff-node)) "Return T if the NODE shall be visible." (ztree-node-is-visible node)) (cl-defmethod ztree-node-short-name ((node ztree-diff-node)) "Return the short name for a node." (ztree-diff-node-short-name-wrapper node nil)) (cl-defmethod ztree-node-right-short-name ((node ztree-diff-node)) "Return the short name for a node." (ztree-diff-node-short-name-wrapper node t)) (cl-defmethod ztree-node-expandable-p ((node ztree-diff-node)) "Return T if the node is expandable." (ztree-diff-node-is-directory node)) (cl-defmethod ztree-node-equal ((node1 ztree-diff-node) (node2 ztree-diff-node)) "Equality function for NODE1 and NODE2. Return T if nodes are equal" (ztree-diff-node-equal node1 node2)) (cl-defmethod ztree-node-children ((node ztree-diff-node)) "Return a list of NODE children" (ztree-diff-node-children node)) (cl-defmethod ztree-node-action ((node ztree-diff-node) hard) "Perform an action when the Return is pressed on a NODE." (ztree-diff-node-action node hard)) (cl-defmethod ztree-node-side ((node ztree-diff-node)) "Determine the side of the NODE." (ztree-diff-node-side node)) (cl-defmethod ztree-node-face ((node ztree-diff-node)) "Return a face to write a NODE in" (ztree-diff-node-face node)) ;; ;; Entry point ;; ;;;###autoload (defun ztree-diff (dir1 dir2) "Create an interactive buffer with the directory tree of the path given. Argument DIR1 left directory. Argument DIR2 right directory." (interactive "DLeft directory \nDRight directory ") (unless (and dir1 (file-directory-p dir1)) (error "Path %s is not a directory" dir1)) (unless (file-exists-p dir1) (error "Path %s does not exist" dir1)) (unless (and dir2 (file-directory-p dir2)) (error "Path %s is not a directory" dir2)) (unless (file-exists-p dir2) (error "Path %s does not exist" dir2)) (unless (ztree-same-host-p dir1 dir2) (error "Compared directories are not on the same host")) (let* ((model (ztree-diff-node-create nil dir1 dir2 nil)) (buf-name (concat "*" (ztree-diff-node-short-name model) " <--> " (ztree-diff-node-right-short-name model) "*"))) ;; after this command we are in a new buffer, ;; so all buffer-local vars are valid (ztree-view buf-name #'ztree-diff-insert-buffer-header model (lambda () (ztree-diff-model-set-ignore-fun #'ztree-diff-node-ignore-p) (setq ztree-diff-dirs-pair (cons dir1 dir2)) (ztree-diff-node-recreate-with-progress model) (ztreediff-mode)) t))) (provide 'ztree-diff) ;;; ztree-diff.el ends here ztree-1.0.6/README.md0000644000175000017500000001364013767077315014004 0ustar dogslegdogsleg# ztree Ztree is a project dedicated to implementation of several text-tree applications inside [GNU Emacs](http://www.gnu.org/software/emacs/). It consists of 2 subprojects: **ztree-diff** and **ztree-dir** (the basis of **ztree-diff**). Available in [GNU ELPA](https://elpa.gnu.org/) and [MELPA](http://melpa.org/#/). ## Installation ### Using ELPA Press `M-x` in GNU Emacs and write `list-packages`. Find the `ztree` in the list of packages and press `i` to select this package, `x` to install the package. ### Using MELPA Add to your `.emacs` or `.emacs.d/init.el` following lines: ```scheme (setq package-archives '(("gnu" . "http://elpa.gnu.org/packages/") ("melpa" . "http://melpa.milkbox.net/packages/"))) ``` Follow the installation instructions for the GNU ELPA above. ### Manual Add the following to your .emacs file: ```scheme (push (substitute-in-file-name "path-to-ztree-directory") load-path) (require 'ztree) ``` ## ztree-diff **ztree-diff** is a directory-diff tool for Emacs inspired by commercial tools like Beyond Compare or Araxis Merge. It supports showing the difference between two directories; calling **Ediff** for not matching files, copying between directories, deleting file/directories, hiding/showing equal files/directories. The comparison itself performed with the external **GNU diff** tool, so make sure to have one in the executable path. Verified on OSX and Linux. If one wants to have a stand-alone application, consider the (WIP)[zdircmp](https://github.com/fourier/zdircmp) project based on **ztree-diff**. Call the `ztree-diff` interactive function: ``` M-x ztree-diff ``` Then you need to specify the left and right directories to compare. ### Hotkeys supported * Open/close directories with double-click, `RET` or `Space` keys. * To jump to the parent directory, hit the `Backspace` key. * To toggle open/closed state of the subtree of the current directory, hit the `x` key. * `RET` on different files starts the **Ediff** (or open file if one absent or the same) * `Space` show the simple diff window for the current file instead of **Ediff** (or view file if one absent or the same) * `TAB` to fast switch between panels * `h` key to toggle show/hide identical files/directories * `H` key to toggle show/hide hidden/ignored files/directories * `C` key to copy current file or directory to the left or right panel * `D` key to delete current file or directory * `v` key to quick view the current file * `r` initiates the rescan/refresh of current file or subdirectory * `F5` forces the full rescan. ### Customizations By default all files starting with dot (like `.gitignore`) are not shown and excluded from the difference status for directories. One can add an additional regexps to the list `ztree-diff-filter-list`. One also could turn on unicode characters to draw the tree with instead of normal ASCII-characters. This is controlled by the `ztree-draw-unicode-lines` variable. The variable `ztree-diff-consider-file-permissions` (which is `nil` by default) if set to `t` allows to compare file attributes as well, the files will be considered different if they have different mode. The special variable `ztree-diff-additional-options` introduced to provide an additional arguments to the 'diff' tool. For example one could specify ``` (setq ztree-diff-additional-options '("-w" "-i")) ``` to ignore case differences and whitespace differences. ### Screenshots ![ztreediff emacsx11](https://github.com/fourier/ztree/raw/screenshots/screenshots/emacs_diff_xterm.png "Emacs in xterm with ztree-diff") ![ztreediff-diff emacsx11](https://github.com/fourier/ztree/raw/screenshots/screenshots/emacs_diff_simplediff_xterm.png "Emacs in xterm with ztree-diff and simple diff") ## ztree-dir **ztree-dir** is a simple text-mode directory tree for Emacs. See screenshots below for the GUI and the terminal versions of the **ztree-dir**. Call the `ztree-dir` interactive function: ``` M-x ztree-dir ``` ### Hotkeys supported * Open/close directories with double-click, `RET` or `Space` keys. * To jump to the parent directory, hit the `Backspace` key. * To toggle open/closed state of the subtree of the current directory, hit the `x` key. * To visit a file, press `Space` key. * To open file in other window, use `RET` key. * To open `Dired` with the directory the point is currently on, use the `d` key. ### Customizations Set the `ztree-dir-move-focus` variable to `t` in order to move focus to the other window when the `RET` key is pressed; the default behavior is to keep focus in `ztree-dir` window. ![ztree emacsapp](https://github.com/fourier/ztree/raw/screenshots/screenshots/emacs_app.png "Emacs App with ztree-dir") ![ztree emacsx11](https://github.com/fourier/ztree/raw/screenshots/screenshots/emacs_xterm.png "Emacs in xterm with ztree-dir") ## Contributions You can contribute to **ztree** in one of the following ways. - Submit a bug report - Submit a feature request - Submit a simple pull request (with changes < 15 lines) ### Copyright issues Since **ztree** is a part of [GNU ELPA](https://elpa.gnu.org/), it is copyrighted by the [Free Software Foundation, Inc.](http://www.fsf.org/). Therefore in order to submit nontrivial changes (with total amount of lines > 15), one needs to to grant the right to include your works in GNU Emacs to the FSF. For this you need to complete [this](https://raw.githubusercontent.com/fourier/ztree/contributions/request-assign.txt) form, and send it to [assign@gnu.org](mailto:assign@gnu.org). The FSF will send you the assignment contract that both you and the FSF will sign. For more information one can read [here](http://www.gnu.org/licenses/why-assign.html) to understand why it is needed. As soon as the paperwork is done one can contribute to **ztree** with bigger pull requests. Note what pull requests without paperwork done will not be accepted, so please notify the [maintainer](mailto:alexey.veretennikov@gmail.com) if everything is in place. ztree-1.0.6/LICENSE0000644000175000017500000010451514024072101013503 0ustar dogslegdogsleg GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . ztree-1.0.6/ztree-protocol.el0000644000175000017500000000552214024072101016006 0ustar dogslegdogsleg;;; ztree-protocol.el --- generic protocol for ztree-view -*- lexical-binding: t; -*- ;; Copyright (C) 2021 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov ;; ;; Created: 2021-02-12 ;; ;; Keywords: files tools ;; URL: https://github.com/fourier/ztree ;; Compatibility: GNU Emacs 24.x ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;; Generic protocol for ztree-view ;;; Code: (eval-when-compile (require 'cl-lib)) ;;; Node protocol ;;; Obligatory to implement (cl-defgeneric ztree-node-visible-p (node) "Return T if the NODE shall be visible.") (cl-defgeneric ztree-node-short-name (node) "Return the short name for a node.") (cl-defgeneric ztree-node-expandable-p (node) "Return T if the node is expandable.") (cl-defgeneric ztree-node-equal (node1 node2) "Equality function for NODE1 and NODE2. Return T if nodes are equal") (cl-defgeneric ztree-node-children (node) "Return a list of NODE children") ;;; Optional to implement (cl-defgeneric ztree-node-side (node) "Determine the side of the NODE.") (cl-defgeneric ztree-node-face (node) "Return a face to write a NODE in") (cl-defgeneric ztree-node-action (node) "Perform an action when the Return is pressed on a NODE.") (cl-defgeneric ztree-node-left-short-name (node) "Return the left short name for a node in 2-sided tree.") (cl-defgeneric ztree-node-right-short-name (node) "Return the right short name for a node in 2-sided tree.") ;;; Default implentations of optional methods (cl-defmethod ztree-node-side ((node t)) (ignore node) :left) (cl-defmethod ztree-node-face ((node t)) "Return a face to write a NODE in" (ignore node)) (cl-defmethod ztree-node-action ((node t) hard) "Perform an action when the Return is pressed on a NODE. Argument HARD specifies if the Return was pressed (t) or Space (nil)" (ignore node) (ignore hard)) (cl-defmethod ztree-node-left-short-name ((node t)) "Return the left short name for a node in 2-sided tree." (ztree-node-short-name node)) (cl-defmethod ztree-node-right-short-name ((node t)) "Return the right short name for a node in 2-sided tree." (ztree-node-short-name node)) (provide 'ztree-protocol) ;;; ztree-protocol.el ends here ztree-1.0.6/ztree-view.el0000644000175000017500000007460014036000457015132 0ustar dogslegdogsleg;;; ztree-view.el --- Text mode tree view (buffer) -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2021 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov ;; ;; Created: 2013-11-11 ;; ;; Keywords: files tools ;; URL: https://github.com/fourier/ztree ;; Compatibility: GNU Emacs 24.x ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;; ;; Add the following to your .emacs file: ;; ;; (push (substitute-in-file-name "path-to-ztree-directory") load-path) ;; (require 'ztree-view) ;; ;; Call the ztree interactive function: ;; Use the following function: ztree-view ;; ;;; Issues: ;; ;;; TODO: ;; ;; ;;; Code: (eval-when-compile (require 'cl-lib)) (require 'subr-x) (require 'ztree-util) (require 'ztree-protocol) ;; ;; Globals ;; (defvar ztree-draw-unicode-lines nil "If set forces ztree to draw lines with unicode characters.") (defvar ztree-show-number-of-children nil "If set forces ztree show number of child entries in the braces.") (defvar-local ztree-expanded-nodes-list nil "A list of Expanded nodes (i.e. directories) entries.") (defvar-local ztree-start-node nil "Start node(i.e. directory) for the window.") (defvar-local ztree-line-to-node-table nil "List of tuples with full node(i.e. file/directory name and the line.") (defvar-local ztree-start-line nil "Index of the start line - the root.") (defvar-local ztree-parent-lines-array nil "Array of parent lines. The ith value of the array is the parent line for line i. If ith value is i - it is the root line") (defvar-local ztree-count-subsequent-bs nil "Counter for the subsequest BS keys (to identify double BS). Used in order to not to use cl package and `lexical-let'") (defvar-local ztree-line-tree-properties nil "Hash table, with key - line number, value - property list of the line. The property list has the following keys: - side (`left', `right', `both'). Used for 2-side trees, to determine if the node exists on left or right or both sides - offset - the column there the text starts ") (defvar-local ztree-prev-position nil "The cons pair of the previous line and column. Used to restore cursor position after refresh") (defvar-local ztree-last-window-width nil "The window width at the last refresh") (defvar-local ztree-two-sided-p nil "If the tree is 2 sided, 2 trees shall be drawn side by side") (def-ztree-local-fun ztree-tree-header "Function inserting the header into the tree buffer. MUST inster newline at the end!") ;; ;; Major mode definitions ;; (defvar ztree-mode-map (let ((map (make-sparse-keymap))) (define-key map (kbd "\r") 'ztree-perform-action) (define-key map (kbd "SPC") 'ztree-perform-soft-action) (define-key map [double-mouse-1] 'ztree-perform-action) (define-key map (kbd "TAB") 'ztree-jump-side) (define-key map (kbd "g") 'ztree-refresh-buffer) (define-key map (kbd "x") 'ztree-toggle-expand-subtree) (define-key map [remap next-line] 'ztree-next-line) (define-key map [remap previous-line] 'ztree-previous-line) (if window-system (define-key map (kbd "") 'ztree-move-up-in-tree) (define-key map "\177" 'ztree-move-up-in-tree)) map) "Keymap for `ztree-mode'.") (defface ztreep-node-face '((((background dark)) (:foreground "#ffffff")) (((type nil)) (:inherit 'font-lock-function-name-face)) (t (:foreground "Blue"))) "*Face used for expandable entries(directories etc) in Ztree buffer." :group 'Ztree :group 'font-lock-highlighting-faces) (defvar ztreep-node-face 'ztreep-node-face) (defface ztreep-leaf-face '((((background dark)) (:foreground "cyan1")) (((type nil)) (:inherit 'font-lock-variable-name-face)) (t (:foreground "darkblue"))) "*Face used for not expandable nodes(leafs, i.e. files) in Ztree buffer." :group 'Ztree :group 'font-lock-highlighting-faces) (defvar ztreep-leaf-face 'ztreep-leaf-face) (defface ztreep-arrow-face '((((background dark)) (:foreground "#7f7f7f")) (t (:foreground "#8d8d8d"))) "*Face used for arrows in Ztree buffer." :group 'Ztree :group 'font-lock-highlighting-faces) (defvar ztreep-arrow-face 'ztreep-arrow-face) (defface ztreep-expand-sign-face '((((background dark)) (:foreground "#7f7fff")) (t (:foreground "#8d8d8d"))) "*Face used for expand sign [+] in Ztree buffer." :group 'Ztree :group 'font-lock-highlighting-faces) (defvar ztreep-expand-sign-face 'ztreep-expand-sign-face) (defface ztreep-node-count-children-face '((t (:inherit 'font-lock-comment-face :slant italic))) "*Face used for count of number of child entries in Ztree buffer." :group 'Ztree :group 'font-lock-highlighting-faces) (defvar ztreep-node-count-children-face 'ztreep-node-count-children-face) ;;;###autoload (define-derived-mode ztree-mode special-mode "Ztree" "A major mode for displaying the directory tree in text mode." ;; only spaces (setq indent-tabs-mode nil) (setq buffer-read-only t)) (defun ztree-scroll-to-line (line) "Set the cursor to specified LINE and to the text offset (if possible)." (let ((center (/ (window-width) 2)) (cur-line (line-number-at-pos))) ;; based on dired-next-line ;; set line-move to move by logical lines (let ((line-move-visual) (goal-column)) (line-move (- line cur-line) t) (when-let (offset (plist-get (gethash (line-number-at-pos) ztree-line-tree-properties) 'offset)) (when (and ztree-two-sided-p (>= (current-column) center)) (cl-incf offset (1+ center))) (beginning-of-line) (goto-char (+ (point) offset)))))) (defun ztree-find-node-in-line (line) "Return the node for the LINE specified. Search through the array of node-line pairs." (gethash line ztree-line-to-node-table)) (defun ztree-find-node-at-point () "Find the node at point. Returns cons pair (node, side) for the current point or nil if there is no node" (let ((center (/ (window-width) 2)) (node (ztree-find-node-in-line (line-number-at-pos)))) (when node (cons node (if (> (current-column) center) 'right 'left))))) (defun ztree-is-expanded-node (node) "Find if the NODE is in the list of expanded nodes." (ztree-find ztree-expanded-nodes-list #'(lambda (x) (ztree-node-equal x node)))) (defun ztree-set-parent-for-line (line parent) "For given LINE set the PARENT in the global array." (aset ztree-parent-lines-array (- line ztree-start-line) parent)) (defun ztree-get-parent-for-line (line) "For given LINE return a parent." (when (and (>= line ztree-start-line) (< line (+ (length ztree-parent-lines-array) ztree-start-line))) (aref ztree-parent-lines-array (- line ztree-start-line)))) (defun ztree-do-toggle-expand-subtree-iter (node state) "Iteration in expanding subtree. Argument NODE current node. Argument STATE node state." (when (ztree-node-expandable-p node) (let ((children (ztree-node-children node))) (ztree-do-toggle-expand-state node state) (dolist (child children) (ztree-do-toggle-expand-subtree-iter child state))))) (defun ztree-do-toggle-expand-subtree () "Implements the subtree expand." (let* ((line (line-number-at-pos)) (node (ztree-find-node-in-line line)) ;; save the current window start position (current-pos (window-start))) ;; only for expandable nodes (when (ztree-node-expandable-p node) ;; get the current expand state and invert it (let ((do-expand (not (ztree-is-expanded-node node)))) (ztree-do-toggle-expand-subtree-iter node do-expand)) ;; refresh buffer and scroll back to the saved line (ztree-refresh-buffer line) ;; restore window start position (set-window-start (selected-window) current-pos)))) (defun ztree-do-perform-action (hard) "Toggle expand/collapsed state for nodes or perform an action. HARD specifies (t or nil) if the hard action, binded on RET, should be performed on node." (let* ((line (line-number-at-pos)) (node (ztree-find-node-in-line line))) (when node (if (ztree-node-expandable-p node) ;; only for expandable nodes (ztree-toggle-expand-state node) ;; perform action (ztree-node-action node hard)) ;; save the current window start position (let ((current-pos (window-start))) ;; refresh buffer and scroll back to the saved line (ztree-refresh-buffer line) ;; restore window start position (set-window-start (selected-window) current-pos))))) (defun ztree-perform-action () "Toggle expand/collapsed state for nodes or perform the action. Performs the hard action, binded on RET, on node." (interactive) (ztree-do-perform-action t)) (defun ztree-perform-soft-action () "Toggle expand/collapsed state for nodes or perform the action. Performs the soft action, binded on Space, on node." (interactive) (ztree-do-perform-action nil)) (defun ztree-toggle-expand-subtree() "Toggle Expanded/Collapsed state on all nodes of the subtree" (interactive) (ztree-do-toggle-expand-subtree)) (defun ztree-do-toggle-expand-state (node do-expand) "Set the expanded state of the NODE to DO-EXPAND." (if (not do-expand) (setq ztree-expanded-nodes-list (ztree-filter #'(lambda (x) (not (ztree-node-equal node x))) ztree-expanded-nodes-list)) (push node ztree-expanded-nodes-list))) (defun ztree-toggle-expand-state (node) "Toggle expanded/collapsed state for NODE." (ztree-do-toggle-expand-state node (not (ztree-is-expanded-node node)))) (defun ztree-move-up-in-tree () "Action on Backspace key. Jump to the line of a parent node. If previous key was Backspace then close the node." (interactive) (when ztree-parent-lines-array (let* ((line (line-number-at-pos (point))) (parent (ztree-get-parent-for-line line))) (when parent (if (and (equal last-command 'ztree-move-up-in-tree) (not ztree-count-subsequent-bs)) (let ((node (ztree-find-node-in-line line))) (when (ztree-is-expanded-node node) (ztree-toggle-expand-state node)) (setq ztree-count-subsequent-bs t) (ztree-refresh-buffer line)) (progn (setq ztree-count-subsequent-bs nil) (ztree-scroll-to-line parent))))))) (defun ztree-get-splitted-node-contens (node) "Return pair of 2 elements: list of expandable nodes and list of leafs. Argument NODE node which contents will be returned." (let ((nodes (ztree-node-children node)) (comp #'(lambda (x y) (string< (ztree-node-short-name x) (ztree-node-short-name y))))) (cons (sort (ztree-filter #'(lambda (f) (ztree-node-expandable-p f)) nodes) comp) (sort (ztree-filter #'(lambda (f) (not (ztree-node-expandable-p f))) nodes) comp)))) (defun ztree-draw-char (c x y &optional face) "Draw char C at the position (1-based) (X Y). Optional argument FACE face to use to draw a character." (save-excursion (goto-char (point-min)) (forward-line (1- y)) (beginning-of-line) (goto-char (+ x (-(point) 1))) (delete-char 1) (insert-char c 1) (put-text-property (1- (point)) (point) 'font-lock-face (if face face 'ztreep-arrow-face)))) (defun ztree-vertical-line-char () "Return the character used to draw vertical line." (if ztree-draw-unicode-lines #x2502 ?\|)) (defun ztree-horizontal-line-char () "Return the character used to draw vertical line." (if ztree-draw-unicode-lines #x2500 ?\-)) (defun ztree-left-bottom-corner-char () "Return the character used to draw vertical line." (if ztree-draw-unicode-lines #x2514 ?\`)) (defun ztree-left-intersection-char () "Return left intersection character. It is just vertical bar when unicode disabled" (if ztree-draw-unicode-lines #x251C ?\|)) (defun ztree-draw-vertical-line (y1 y2 x &optional face) "Draw a vertical line of `|' characters from Y1 row to Y2 in X column. Optional argument FACE face to draw line with." (let ((ver-line-char (ztree-vertical-line-char)) (count (abs (- y1 y2)))) (if (> y1 y2) (progn (dotimes (y count) (ztree-draw-char ver-line-char x (+ y2 y) face)) (ztree-draw-char ver-line-char x (+ y2 count) face)) (progn (dotimes (y count) (ztree-draw-char ver-line-char x (+ y1 y) face)) (ztree-draw-char ver-line-char x (+ y1 count) face))))) (defun ztree-draw-vertical-rounded-line (y1 y2 x &optional face) "Draw a vertical line of `|' characters finishing with `\\=`' character. Draws the line from Y1 row to Y2 in X column. Optional argument FACE facet to draw the line with." (let ((ver-line-char (ztree-vertical-line-char)) (corner-char (ztree-left-bottom-corner-char)) (count (abs (- y1 y2)))) (if (> y1 y2) (progn (dotimes (y count) (ztree-draw-char ver-line-char x (+ y2 y) face)) (ztree-draw-char corner-char x (+ y2 count) face)) (progn (dotimes (y count) (ztree-draw-char ver-line-char x (+ y1 y) face)) (ztree-draw-char corner-char x (+ y1 count) face))))) (defun ztree-draw-horizontal-line (x1 x2 y) "Draw the horizontal line from column X1 to X2 in the row Y." (let ((hor-line-char (ztree-horizontal-line-char))) (if (> x1 x2) (dotimes (x (1+ (- x1 x2))) (ztree-draw-char hor-line-char (+ x2 x) y)) (dotimes (x (1+ (- x2 x1))) (ztree-draw-char hor-line-char (+ x1 x) y))))) (defun ztree-draw-tree (tree depth start-offset) "Draw the TREE of lines with parents. Argument DEPTH current depth. Argument START-OFFSET column to start drawing from." (if (atom tree) nil (let* ((root (car tree)) (children (cdr tree)) (offset (+ start-offset (* depth 4))) (line-start (+ 3 offset)) (line-end-leaf (+ 7 offset)) (line-end-node (+ 4 offset)) (corner-char (ztree-left-bottom-corner-char)) (intersection-char (ztree-left-intersection-char)) ;; determine if the line is visible. It is always the case ;; for 1-sided trees; however for 2 sided trees ;; it depends on which side is the actual element ;; and which tree (left with offset 0 or right with offset > 0 ;; we are drawing (visible #'(lambda (line) () (if (not ztree-two-sided-p) t (let ((side (plist-get (gethash line ztree-line-tree-properties) 'side))) (cond ((eq side 'left) (= start-offset 0)) ((eq side 'right) (> start-offset 0)) (t t))))))) (when children ;; draw the line to the last child ;; since we push'd children to the list, it's the first visible line ;; from the children list (let ((last-child (ztree-find children #'(lambda (x) (funcall visible (ztree-car-atom x))))) (x-offset (+ 2 offset))) (when last-child (ztree-draw-vertical-line (1+ root) (ztree-car-atom last-child) x-offset)) ;; draw recursively (dolist (child children) (ztree-draw-tree child (1+ depth) start-offset) (let ((end (if (listp child) line-end-node line-end-leaf)) (row (ztree-car-atom child))) (when (funcall visible (ztree-car-atom child)) (ztree-draw-char intersection-char (1- line-start) row) (ztree-draw-horizontal-line line-start end row)))) ;; finally draw the corner at the end of vertical line (when last-child (ztree-draw-char corner-char x-offset (ztree-car-atom last-child)))))))) (defun ztree-fill-parent-array (tree) "Set the root lines array. Argument TREE nodes tree to create an array of lines from." (let ((root (car tree)) (children (cdr tree))) (dolist (child children) (ztree-set-parent-for-line (ztree-car-atom child) root) (when (listp child) (ztree-fill-parent-array child))))) (defun ztree-insert-node-contents (path) "Insert node contents with initial depth 0. `ztree-insert-node-contents-1' return the tree of line numbers to determine who is parent line of the particular line. This tree is used to draw the graph. Argument PATH start node." (let ((tree (ztree-insert-node-contents-1 path 0)) ;; number of 'rows' in tree is last line minus start line (num-of-items (- (line-number-at-pos (point)) ztree-start-line))) ;; create a parents array to store parents of lines ;; parents array used for navigation with the BS (setq ztree-parent-lines-array (make-vector num-of-items 0)) ;; set the root node in lines parents array (ztree-set-parent-for-line ztree-start-line ztree-start-line) ;; fill the parent arrray from the tree (ztree-fill-parent-array tree) ;; draw the tree starting with depth 0 and offset 0 (ztree-draw-tree tree 0 0) ;; for the 2-sided tree we need to draw the vertical line ;; and an additional tree (if ztree-two-sided-p ; 2-sided tree (let ((width (window-width))) ;; draw the vertical line in the middle of the window (ztree-draw-vertical-line ztree-start-line (1- (+ num-of-items ztree-start-line)) (/ width 2) 'vertical-border) (ztree-draw-tree tree 0 (1+ (/ width 2))))))) (defun ztree-insert-node-contents-1 (node depth) "Recursively insert contents of the NODE with current DEPTH." (let* ((expanded (ztree-is-expanded-node node)) ;; insert node entry with defined depth (root-line (ztree-insert-entry node depth expanded)) ;; children list is the list of lines which are children ;; of the root line (children nil)) (when expanded ;; if expanded we need to add all subnodes (let* ((contents (ztree-get-splitted-node-contens node)) ;; contents is the list of 2 elements: (nodes (car contents)) ; expandable entries - nodes (leafs (cdr contents))) ; leafs - which doesn't have subleafs ;; iterate through all expandable entries to insert them first (dolist (node nodes) ;; if it is not in the filter list (when (ztree-node-visible-p node) ;; insert node on the next depth level ;; and push the returning result (in form (root children)) ;; to the children list (push (ztree-insert-node-contents-1 node (1+ depth)) children))) ;; now iterate through all the leafs (dolist (leaf leafs) ;; if not in filter list (when (ztree-node-visible-p leaf) ;; insert the leaf and add it to children (push (ztree-insert-entry leaf (1+ depth) nil) children))))) ;; result value is the list - head is the root line, ;; rest are children (cons root-line children))) (defun ztree-insert-entry (node depth expanded) "Inselt the NODE to the current line with specified DEPTH and EXPANDED state." (let* ((line (line-number-at-pos)) ;; the properties of the line. they will be updated ;; with the offset of the text and relevant side information (line-properties (gethash line ztree-line-tree-properties)) (expandable (ztree-node-expandable-p node)) (short-name (ztree-node-left-short-name node)) (count-children-left (when (and expandable ztree-show-number-of-children) (ignore-errors (length (cl-remove-if (lambda (n) (and ztree-two-sided-p (eql (ztree-node-side n) 'right))) (ztree-node-children node)))))) (count-children-right (when (and expandable ztree-show-number-of-children) (ignore-errors (length (cl-remove-if (lambda (n) (and ztree-two-sided-p (eql (ztree-node-side n) 'left))) (ztree-node-children node))))))) (if ztree-two-sided-p ; 2-sided tree (let ((right-short-name (ztree-node-right-short-name node)) (side (ztree-node-side node)) (width (window-width))) (when (eq side 'left) (setq right-short-name "")) (when (eq side 'right) (setq short-name "")) (setq line-properties (plist-put line-properties 'offset ;; insert left side and save the offset (ztree-insert-single-entry short-name depth expandable expanded 0 count-children-left (when ztree-two-sided-p (ztree-node-face node))))) ;; right side (ztree-insert-single-entry right-short-name depth expandable expanded (1+ (/ width 2)) count-children-right (when ztree-two-sided-p (ztree-node-face node))) (setq line-properties (plist-put line-properties 'side side))) ;; one sided view (setq line-properties (plist-put line-properties 'offset (ztree-insert-single-entry short-name depth expandable expanded 0 (when expandable count-children-left))))) (puthash line node ztree-line-to-node-table) ;; save the properties for the line - side and text offset (puthash line line-properties ztree-line-tree-properties) (insert "\n") line)) (defun ztree-insert-single-entry (short-name depth expandable expanded offset count-children &optional face) "Writes a SHORT-NAME in a proper position with the type given. Writes a string with given DEPTH, prefixed with [ ] if EXPANDABLE and [-] or [+] depending on if it is EXPANDED from the specified OFFSET. If `ztree-show-number-of-children' is set to t the COUNT-CHILDREN argument is used to present number of entries in the expandable item. COUNT-CHILDREN might be null if the contents of expandable node are not accessible. Optional argument FACE face to write text with. Returns the position where the text starts." (let ((result 0) (node-sign #'(lambda (exp) (let ((sign (concat "[" (if exp "-" "+") "]"))) (insert (propertize sign 'font-lock-face ztreep-expand-sign-face))))) ;; face to use. if FACE is not null, use it, otherwise ;; deside from the node type (entry-face (cond (face face) (expandable 'ztreep-node-face) (t ztreep-leaf-face)))) ;; move-to-column in contrast to insert reuses the last property ;; so need to clear it (let ((start-pos (point))) (move-to-column offset t) (remove-text-properties start-pos (point) '(font-lock-face nil))) (delete-region (point) (line-end-position)) ;; every indentation level is 4 characters (when (> depth 0) (insert-char ?\s (* 4 depth))) ; insert 4 spaces (when (> (length short-name) 0) (let ((start-pos (point))) (if expandable (funcall node-sign expanded)) ; for expandable nodes insert "[+/-]" ;; indentation for leafs 4 spaces from the node name (insert-char ?\s (- 4 (- (point) start-pos)))) ;; save the position of the beginning of the text (setq result (current-column)) (insert (propertize short-name 'font-lock-face entry-face)) ;; optionally add number of children in braces (when (and ztree-show-number-of-children expandable) (let ((count-str (format " [%s]" (if count-children (number-to-string count-children) "N/A")))) (insert (propertize count-str 'font-lock-face ztreep-node-count-children-face))))) result)) (defun ztree-jump-side () "Jump to another side for 2-sided trees." (interactive) (when ztree-two-sided-p ; 2-sided tree (let ((center (/ (window-width) 2))) (if (< (current-column) center) (move-to-column (1+ center)) (move-to-column 1)) ;; just recalculate and move to proper column (ztree-scroll-to-line (line-number-at-pos))))) (defun ztree-save-current-position () "Save the current position into the global variable." (setq ztree-prev-position (cons (line-number-at-pos (point)) (current-column)))) (defun ztree-refresh-buffer (&optional line) "Refresh the buffer. Optional argument LINE scroll to the line given." (interactive) (when (and (equal major-mode 'ztree-mode) (boundp 'ztree-start-node)) (let ((prev-pos ztree-prev-position)) (setq ztree-line-to-node-table (make-hash-table)) ;; create a hash table of node properties for line (setq ztree-line-tree-properties (make-hash-table)) (let ((inhibit-read-only t)) (ztree-save-current-position) (erase-buffer) (ztree-tree-header) (setq ztree-start-line (line-number-at-pos (point))) (ztree-insert-node-contents ztree-start-node) (cond (line ;; local refresh, scroll to line (ztree-scroll-to-line line) (when prev-pos (beginning-of-line) (goto-char (+ (cdr ztree-prev-position) (point))))) ((and (null line) (null prev-pos)) ;; first refresh (ztree-scroll-to-line ztree-start-line) (ztree-save-current-position)) ((and (null line) prev-pos) ;; not first refresh ;; restore cursor position if possible (ztree-scroll-to-line (car ztree-prev-position)) (beginning-of-line) (goto-char (+ (cdr ztree-prev-position) (point))))))) (setq ztree-last-window-width (window-width)))) (defun ztree-change-start-node (node) "Refresh the buffer setting the new root NODE. This will reuse all other settings for the current ztree buffer, but change the root node to the node specified." (setq ztree-start-node node ztree-expanded-nodes-list (list ztree-start-node) ;; then the new root node is given, no sense to preserve ;; a cursor position ztree-prev-position nil) (ztree-refresh-buffer)) (defun ztree-previous-line (arg) "Move the point to ARG lines up" (interactive "^p") (ztree-next-line (- (or arg 1)))) (defun ztree-next-line (arg) "Move the point to ARG lines down" (interactive "^p") (ztree-move-line arg)) (defun ztree-move-line (count) "Move the point COUNT lines and place at the beginning of the node." (ztree-scroll-to-line (+ count (line-number-at-pos)))) ;;;###autoload (defun ztree-view-on-window-configuration-changed () "Hook called then window configuration changed to resize buffer's contents" ;; refresh visible ztree buffers (walk-windows (lambda (win) (with-current-buffer (window-buffer win) (when (derived-mode-p 'ztree-mode) (when (and ztree-last-window-width (/= ztree-last-window-width (window-width))) (ztree-refresh-buffer))))) nil 'visible)) (defun ztree-view (buffer-name header-fun start-node init-function &optional two-sided-p) "Create a ztree view buffer configured with parameters given. Argument BUFFER-NAME Name of the buffer created. Argument HEADER-FUN Function which inserts the header into the buffer before drawing the tree. Argument START-NODE Starting node - the root of the tree. Argument INIT-FUNCTION Function to call just before refreshing the buffer and setting all variables and mode. Could be nil. It could be used to set up a minor mode or build a tree. Function should not expect any arguments. Example: #'ztreedir-mode Optional argument TWO-SIDED-P Determines if the tree is 2-sided (nil by default)" (let ((buf (get-buffer-create buffer-name))) (switch-to-buffer buf) (ztree-mode) ;; configure ztree-view (setq ztree-start-node start-node) (setq ztree-expanded-nodes-list (list ztree-start-node)) (setq ztree-tree-header-fun header-fun) (setq ztree-two-sided-p two-sided-p) (when init-function (funcall init-function)) (ztree-refresh-buffer) (add-hook 'window-configuration-change-hook #'ztree-view-on-window-configuration-changed))) (provide 'ztree-view) ;;; ztree-view.el ends here ztree-1.0.6/ztree.el0000644000175000017500000000222214036000457014151 0ustar dogslegdogsleg;;; ztree.el --- Text mode directory tree -*- lexical-binding: t; -*- ;; Copyright (C) 2013-2021 Free Software Foundation, Inc. ;; ;; Author: Alexey Veretennikov ;; Created: 2013-11-11 ;; Version: 1.0.6 ;; Package-Requires: ((cl-lib "0")) ;; Keywords: files tools ;; URL: https://github.com/fourier/ztree ;; Compatibility: GNU Emacs 24.x ;; ;; This file is part of GNU Emacs. ;; ;; GNU Emacs is free software: you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs. If not, see . ;; ;;; Commentary: ;; ;; ;;; Code: (require 'ztree-dir) (require 'ztree-diff) (provide 'ztree) ;;; ztree.el ends here