emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] master 4e0df28 7/7: 1) Implemented feature: narrow/widen director


From: Alexey Veretennikov
Subject: [elpa] master 4e0df28 7/7: 1) Implemented feature: narrow/widen directories in ztree-dir
Date: Thu, 5 Jan 2017 10:12:06 +0000 (UTC)

branch: master
commit 4e0df28dfdaeb9a21cc394983d1c5a3ae424bef8
Merge: 4f9c5f4 3a4df17
Author: Alexey Veretennikov <address@hidden>
Commit: Alexey Veretennikov <address@hidden>

    1) Implemented feature: narrow/widen directories in ztree-dir
    2) Fixed regression in TRAMP mode while in ztree-diff
    3) Updated docstrings.
    
    Merge commit '3a4df17edddef84160194802acc034cfa2dbd678'
---
 packages/ztree/ztree-diff-model.el |   14 ++++++++-----
 packages/ztree/ztree-diff.el       |    2 +-
 packages/ztree/ztree-dir.el        |   40 +++++++++++++++++++++++++++++-------
 packages/ztree/ztree-util.el       |   16 ++++++++++++++-
 packages/ztree/ztree-view.el       |   27 ++++++++++++++----------
 packages/ztree/ztree.el            |    2 +-
 6 files changed, 75 insertions(+), 26 deletions(-)

diff --git a/packages/ztree/ztree-diff-model.el 
b/packages/ztree/ztree-diff-model.el
index 1f78d62..6f4c951 100644
--- a/packages/ztree/ztree-diff-model.el
+++ b/packages/ztree/ztree-diff-model.el
@@ -145,9 +145,9 @@ Returns t if equal."
     (error "Compared files are not on the same host"))
   (let* ((file1-untrampified (ztree-untrampify-filename file1))
          (file2-untrampified (ztree-untrampify-filename file2)))
-    (if (or 
-         (/= (nth 7 (file-attributes file1-untrampified))
-            (nth 7 (file-attributes file2-untrampified)))
+    (if (or
+         (/= (nth 7 (file-attributes file1))
+            (nth 7 (file-attributes file2)))
          (/= 0 (process-file diff-command nil nil nil "-q"
                            file1-untrampified
                            file2-untrampified)))
@@ -374,8 +374,12 @@ which returns t if the node should be ignored (like files 
starting
 with dot etc)."
   (setf ztree-diff-model-ignore-fun ignore-p))
 
-(defun ztree-diff-model-set-progress-fun (progess-fun)
-  (setf ztree-diff-model-progress-fun progess-fun))
+
+(defun ztree-diff-model-set-progress-fun (progress-fun)
+  "Setter for the buffer-local PROGRESS-FUN callback.
+This callback is called to indicate the ongoing activity.
+Callback is a function without arguments."
+  (setf ztree-diff-model-progress-fun progress-fun))
 
 (provide 'ztree-diff-model)
 
diff --git a/packages/ztree/ztree-diff.el b/packages/ztree/ztree-diff.el
index c454709..a4bd012 100644
--- a/packages/ztree/ztree-diff.el
+++ b/packages/ztree/ztree-diff.el
@@ -499,7 +499,7 @@ unless it is a parent node."
 
 
 (defun ztree-diff-update-wait-message (&optional msg)
-  "Update the wait mesage with one more `.' progress indication."
+  "Update the wait message MSG with one more `.' progress indication."
   (if msg
       (setq ztree-diff-wait-message msg)
     (when ztree-diff-wait-message
diff --git a/packages/ztree/ztree-dir.el b/packages/ztree/ztree-dir.el
index 7d866ff..dada7d0 100644
--- a/packages/ztree/ztree-dir.el
+++ b/packages/ztree/ztree-dir.el
@@ -45,7 +45,7 @@
 
 (require 'ztree-util)
 (require 'ztree-view)
-(eval-when-compile (require 'cl-lib))
+(require 'cl-lib)
 
 ;;
 ;; Constants
@@ -60,8 +60,7 @@ By default all filest starting with dot `.', including . and 
..")
 ;;
 
 (defvar ztree-dir-move-focus nil
-  "If set to true moves the focus to opened window when the
-user press RETURN on file ")
+  "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.
@@ -96,7 +95,9 @@ One could add own filters in the following way:
   " Dir"
   ;; The minor mode keymap
   `(
-    (,(kbd "H") . ztree-dir-toggle-show-filtered-files)))
+    (,(kbd "H") . ztree-dir-toggle-show-filtered-files)
+    (,(kbd ">") . ztree-dir-narrow-to-dir)
+    (,(kbd "<") . ztree-dir-widen-to-parent)))
 
 
 
@@ -146,13 +147,38 @@ Otherwise, the ztree window is used to find the file."
 
 
 (defun ztree-dir-directory-files (path)
-  "Returns the list of files/directories for the given PATH"
+  "Return the list of files/directories for the given PATH."
   ;; remove . and .. from the list of files to avoid infinite
   ;; recursion
-  (remove-if (lambda (x) (string-match-p "/\\.\\.?$" x))
-             (directory-files path 'full)))
+  (cl-remove-if (lambda (x) (string-match-p "/\\.\\.?$" x))
+                (directory-files path 'full)))
 
 
+(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-change-start-node node)
+      (when parent
+        (ztree-change-start-node (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-change-start-node parent))))
+
 
 ;;;###autoload
 (defun ztree-dir (path)
diff --git a/packages/ztree/ztree-util.el b/packages/ztree/ztree-util.el
index 39975b0..5ac764b 100644
--- a/packages/ztree/ztree-util.el
+++ b/packages/ztree/ztree-util.el
@@ -48,10 +48,17 @@ Taken from 
http://www.emacswiki.org/emacs/ElispCookbook#toc39";
 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";
-  (ztree-printable-string (file-name-nondirectory (directory-file-name file))))
+  (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.
@@ -79,6 +86,13 @@ Used since `car-safe' returns nil for atoms"
         (file2-remote (file-remote-p file2)))
     (string-equal file1-remote file2-remote)))
 
+
+(defun ztree-scroll-to-line (line)
+  "Recommended way to set the cursor to specified LINE."
+  (goto-char (point-min))
+  (forward-line (1- line)))
+
+
 (provide 'ztree-util)
 
 ;;; ztree-util.el ends here
diff --git a/packages/ztree/ztree-view.el b/packages/ztree/ztree-view.el
index f1a9afd..8cf0ced 100644
--- a/packages/ztree/ztree-view.el
+++ b/packages/ztree/ztree-view.el
@@ -192,17 +192,13 @@ or nil if there is no node"
   "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 scroll-to-line (line)
-  "Recommended way to set the cursor to specified LINE."
-  (goto-char (point-min))
-  (forward-line (1- line)))
-
 
 (defun ztree-do-toggle-expand-subtree-iter (node state)
   "Iteration in expanding subtree.
@@ -303,7 +299,7 @@ then close the node."
               (setq ztree-count-subsequent-bs t)
               (ztree-refresh-buffer line))
           (progn (setq ztree-count-subsequent-bs nil)
-                 (scroll-to-line parent)))))))
+                 (ztree-scroll-to-line parent)))))))
 
 
 (defun ztree-get-splitted-node-contens (node)
@@ -327,7 +323,7 @@ Argument NODE node which contents will be returned."
   "Draw char C at the position (1-based) (X Y).
 Optional argument FACE face to use to draw a character."
   (save-excursion
-    (scroll-to-line y)
+    (ztree-scroll-to-line y)
     (beginning-of-line)
     (goto-char (+ x (-(point) 1)))
     (delete-char 1)
@@ -335,15 +331,15 @@ Optional argument FACE face to use to draw a character."
     (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"
+  "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"
+  "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"
+  "Return the character used to draw vertical line."
   (if ztree-draw-unicode-lines #x2514 ?\`))
 
 (defun ztree-left-intersection-char ()
@@ -614,7 +610,16 @@ Optional argument LINE scroll to the line given."
       (funcall ztree-tree-header-fun)
       (setq ztree-start-line (line-number-at-pos (point)))
       (ztree-insert-node-contents ztree-start-node))
-    (scroll-to-line (if line line ztree-start-line))))
+    (ztree-scroll-to-line (if line line ztree-start-line))))
+
+
+(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))
+  (ztree-refresh-buffer))
 
 
 (defun ztree-view (
diff --git a/packages/ztree/ztree.el b/packages/ztree/ztree.el
index dbe9911..d615f64 100644
--- a/packages/ztree/ztree.el
+++ b/packages/ztree/ztree.el
@@ -4,7 +4,7 @@
 ;;
 ;; Author: Alexey Veretennikov <address@hidden>
 ;; Created: 2013-11-11
-;; Version: 1.0.4
+;; Version: 1.0.5
 ;; Package-Requires: ((cl-lib "0"))
 ;; Keywords: files tools
 ;; URL: https://github.com/fourier/ztree



reply via email to

[Prev in Thread] Current Thread [Next in Thread]