[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 81b6a4b 49/92: Added delete functionality
From: |
Alexey Veretennikov |
Subject: |
[elpa] master 81b6a4b 49/92: Added delete functionality |
Date: |
Thu, 11 Jun 2015 19:48:06 +0000 |
branch: master
commit 81b6a4b4dc5f766200cfd15becc6f8d42e76bb96
Author: Alexey Veretennikov <address@hidden>
Commit: Alexey Veretennikov <address@hidden>
Added delete functionality
---
README.md | 3 +-
ztree-diff.el | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 0a9f851..8922f4d 100644
--- a/README.md
+++ b/README.md
@@ -29,7 +29,7 @@ Open/close directories with double-click, `RET` or `Space`
keys. To jump to the
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; copying between directories, calling **Ediff** for not
matching files, hiding/showing equal files/directories.
+**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.
@@ -53,6 +53,7 @@ The basic hotkeys are the same as in the **ztree-dir**.
Additionally:
* `TAB` to fast switch between panels
* `h` key toggle show/hide identical files/directories
* `C` key to copy current file or directory to the left or right panel
+ * `D` key to delete current file or directory
* `F5` forces the full rescan.
![ztreediff
emacsx11](https://github.com/fourier/ztree/raw/screenshots/screenshots/emacs_diff_xterm.png
"Emacs in xterm with ztree-diff")
diff --git a/ztree-diff.el b/ztree-diff.el
index c0cc6c0..f04a15b 100644
--- a/ztree-diff.el
+++ b/ztree-diff.el
@@ -71,7 +71,7 @@ including . and ..")
(defvar ztree-diff-filter-list nil
"List of regexp file names to filter out")
(make-variable-buffer-local 'ztree-diff-filter-list)
-
+
(defvar ztree-diff-dirs-pair nil
"Pair of the directories stored. Used to perform the full rescan")
(make-variable-buffer-local 'ztree-diff-dirs-pair)
@@ -91,6 +91,7 @@ including . and ..")
`(
(,(kbd "C") . ztree-diff-copy)
(,(kbd "h") . ztree-diff-toggle-show-equal-files)
+ (,(kbd "D") . ztree-diff-delete-file)
([f5] . ztree-diff-full-rescan)))
@@ -133,7 +134,7 @@ including . and ..")
(substring-no-properties
(ztree-diff-node-short-name node))
" on left and right side are identical"))
- (ediff left right)))))
+ (ediff left right)))))
(defun ztree-diff-copy-file (node source-path destination-path copy-to-right)
@@ -184,10 +185,10 @@ including . and ..")
(ztree-diff-node-set-right-path node
target-full-path)
(ztree-diff-node-set-left-path node
- target-full-path))
+ target-full-path))
(ztree-diff-model-update-node node)
- (ztree-diff-node-update-all-parents-diff node)
- (ztree-refresh-buffer (line-number-at-pos)))))))
+ (ztree-diff-node-update-all-parents-diff node)
+ (ztree-refresh-buffer (line-number-at-pos)))))))
(defun ztree-diff-copy ()
@@ -203,7 +204,7 @@ including . and ..")
(source-path nil)
(destination-path nil)
(parent (ztree-diff-node-parent node)))
- (when parent
+ (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
@@ -236,6 +237,53 @@ including . and ..")
copy-to-right))))))))
+(defun ztree-diff-delete-file ()
+ (interactive)
+ (let ((found (ztree-find-node-at-point)))
+ (when found
+ (let* ((node (car found))
+ (side (cdr found))
+ (node-side (ztree-diff-node-side node))
+ (delete-from-left t)
+ (remove-path nil)
+ (parent (ztree-diff-node-parent node)))
+ (when parent ; do not delete the root 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
+ (setq delete-from-left (if (eq node-side 'both)
+ (eq side 'left)
+ ;; 2) if one of sides is absent, delete
+ ;; from the side where the file is present
+ (eq node-side 'left)))
+ (setq remove-path (if delete-from-left
+ (ztree-diff-node-left-path node)
+ (ztree-diff-node-right-path node)))
+ (when (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 remove-path t)
+ '(delete-file remove-path t)))
+ (children (ztree-diff-node-children parent))
+ (err
+ (condition-case error-trap
+ (progn
+ (eval delete-command)
+ nil)
+ (error error-trap))))
+ (if err (message (concat "Error: " (nth 2 err)))
+ (progn
+ (setq children (ztree-filter
+ #'(lambda (x) (not (ztree-diff-node-equal x
node)))
+ children))
+ (ztree-diff-node-set-children parent children))
+ (ztree-diff-node-update-all-parents-diff node)
+ (ztree-refresh-buffer (line-number-at-pos))))))))))
+
+
+
(defun ztree-node-is-in-filter-list (node)
"Determine if the node is in filter list (and therefore
apparently shall not be visible"
@@ -253,7 +301,7 @@ apparently shall not be visible"
(setq ztree-diff-show-equal-files (not ztree-diff-show-equal-files))
(ztree-refresh-buffer))
-
+
(defun ztree-diff (dir1 dir2)
"Creates an interactive buffer with the directory tree of the path given"
(interactive "DLeft directory \nDRight directory ")
- [elpa] master 900c8fa 38/92: Refactored using defrecord macro, (continued)
- [elpa] master 900c8fa 38/92: Refactored using defrecord macro, Alexey Veretennikov, 2015/06/11
- [elpa] master 6154ab8 21/92: Split view and models - for directory tree and for diff tree, Alexey Veretennikov, 2015/06/11
- [elpa] master 8335785 39/92: Added comment, Alexey Veretennikov, 2015/06/11
- [elpa] master 1ab3b48 43/92: Implemented file copying, Alexey Veretennikov, 2015/06/11
- [elpa] master af28a78 41/92: Started implementation of the copy functionality, Alexey Veretennikov, 2015/06/11
- [elpa] master 75b89a6 48/92: Fixed typo, Alexey Veretennikov, 2015/06/11
- [elpa] master 725f388 42/92: Preparation to copy implementation done, Alexey Veretennikov, 2015/06/11
- [elpa] master f78b859 47/92: Updated readme, Alexey Veretennikov, 2015/06/11
- [elpa] master 20d8217 44/92: Implemented directory copying, Alexey Veretennikov, 2015/06/11
- [elpa] master d590f88 40/92: Added minor mode for ztree diff, to create custom keybindings, Alexey Veretennikov, 2015/06/11
- [elpa] master 81b6a4b 49/92: Added delete functionality,
Alexey Veretennikov <=
- [elpa] master c3580db 46/92: Updated readme; renamed the ztree to ztree-dir, Alexey Veretennikov, 2015/06/11
- [elpa] master 3867ed3 45/92: Implemented support for hiding matched(equal) files, Alexey Veretennikov, 2015/06/11
- [elpa] master 15baed9 50/92: Repaired full rescan; added 'v' keybinding to quickly view files, Alexey Veretennikov, 2015/06/11
- [elpa] master 7f1ec58 53/92: Fixed topmost name in comparison tree, Alexey Veretennikov, 2015/06/11
- [elpa] master 56dce0e 51/92: Updated README, Alexey Veretennikov, 2015/06/11
- [elpa] master d791ebe 54/92: Readme is updated, Alexey Veretennikov, 2015/06/11
- [elpa] master 8ba9ca2 55/92: Added simple diff by using SPACE, Alexey Veretennikov, 2015/06/11
- [elpa] master c816a66 56/92: Updated readme, Alexey Veretennikov, 2015/06/11
- [elpa] master 0c9d8b6 52/92: Added 'd' hotkey and left/light paths to the header, Alexey Veretennikov, 2015/06/11
- [elpa] master a45a108 57/92: Logical operation on the file by pressing either RET or SPC - diff/ediff when different view/open when same, Alexey Veretennikov, 2015/06/11