]> code.delx.au - gnu-emacs-elpa/blobdiff - packages/ztree/ztree-dir.el
Fix some quoting problems in doc strings
[gnu-emacs-elpa] / packages / ztree / ztree-dir.el
index 47a57cd9cea1dd9388201cebc89abef9c7d6f07e..53617f90509aa85f256e86e5fe7cc15253410ae4 100644 (file)
@@ -1,14 +1,14 @@
-;;; ztree-dir.el --- Text mode directory tree
+;;; ztree-dir.el --- Text mode directory tree -*- lexical-binding: t; -*-
 
-;; Copyright (C) 2013-2015  Free Software Foundation, Inc.
+;; Copyright (C) 2013-2016  Free Software Foundation, Inc.
 ;;
-;; Author: Alexey Veretennikov <alexey dot veretennikov at gmail dot com>
-;; 
-;; Created: 2013-11-1l
+;; Author: Alexey Veretennikov <alexey.veretennikov@gmail.com>
+;;
+;; Created: 2013-11-11
 ;;
 ;; Keywords: files tools
 ;; URL: https://github.com/fourier/ztree
-;; Compatibility: GNU Emacs GNU Emacs 24.x
+;; Compatibility: GNU Emacs 24.x
 ;;
 ;; This file is part of GNU Emacs.
 ;;
@@ -28,7 +28,7 @@
 ;;; Commentary:
 ;;
 ;; Add the following to your .emacs file:
-;; 
+;;
 ;; (push (substitute-in-file-name "path-to-ztree-directory") load-path)
 ;; (require 'ztree-dir)
 ;;
@@ -45,6 +45,7 @@
 
 (require 'ztree-util)
 (require 'ztree-view)
+(eval-when-compile (require 'cl-lib))
 
 ;;
 ;; Constants
 
 (defconst ztree-hidden-files-regexp "^\\."
   "Hidden files regexp.
-By default all filest starting with dot '.', including . and ..")
+By default all filest starting with dot `.', including . and ..")
+
+;;
+;; Configurable variables
+;;
+
+(defvar ztree-dir-move-focus nil
+  "If set to true moves the focus to opened window when the
+user press RETURN on 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.")
 
 
 ;;
@@ -68,6 +88,19 @@ By default all filest starting with dot '.', including . and ..")
 (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)))
+
+
+
+
 ;;
 ;; File bindings to the directory tree control
 ;;
@@ -76,15 +109,19 @@ By default all filest starting with dot '.', including . and ..")
   "Insert the header to the ztree buffer."
   (let ((start (point)))
     (insert "Directory tree")
-    (newline-and-begin)
+    (insert "\n")
     (insert "==============")
     (set-text-properties start (point) '(face ztreep-header-face)))
-  (newline-and-begin))
+  (insert "\n"))
 
 (defun ztree-file-not-hidden (filename)
   "Determines if the file with FILENAME should be visible."
-  (not (string-match ztree-hidden-files-regexp
-                     (file-short-name filename))))
+  (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.
@@ -92,9 +129,23 @@ By default all filest starting with dot '.', including . and ..")
 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))
-    (if hard
-        (save-selected-window (find-file-other-window node))
-      (find-file 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))
+
+
+
 
 ;;;###autoload
 (defun ztree-dir (path)
@@ -104,14 +155,16 @@ Otherwise, the ztree window is used to find the file."
     (let ((buf-name (concat "*Directory " path " tree*")))
       (ztree-view buf-name
                   (expand-file-name (substitute-in-file-name path))
-                  'ztree-file-not-hidden
-                  'ztree-insert-buffer-header
-                  'file-short-name
-                  'file-directory-p
-                  'string-equal
-                  '(lambda (x) (directory-files x 'full))
+                  #'ztree-file-not-hidden
+                  #'ztree-insert-buffer-header
+                  #'ztree-file-short-name
+                  #'file-directory-p
+                  #'string-equal
+                  (lambda (x) (directory-files x 'full))
                   nil                   ; face
-                  'ztree-find-file)))) ; action
+                  #'ztree-find-file)    ; action
+      (ztreedir-mode))))
+
 
 
 (provide 'ztree-dir)