-;;; 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.
;;
;;
;; 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.
;;
"Hidden files regexp.
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 ")t
+
;;
;; Faces
"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))))
+ (ztree-file-short-name filename))))
(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))
- (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)))))
;;;###autoload
(defun ztree-dir (path)
(expand-file-name (substitute-in-file-name path))
'ztree-file-not-hidden
'ztree-insert-buffer-header
- 'file-short-name
+ 'ztree-file-short-name
'file-directory-p
'string-equal
'(lambda (x) (directory-files x 'full))