1- ; ;; neotree.el --- summary
1+ ; ;; neotree.el --- A emacs tree plugin like NerdTree for Vim
22
33; ; Copyright (C) 2014 jaypei
44
55; ; Author: jaypei <[email protected] >6- ; ; Version: 0.1.3
6+ ; ; Version: 0.1.4
7+ ; ; URL: https://github.com/jaypei/emacs-neotree
78
89; ; This program is free software; you can redistribute it and/or modify
910; ; it under the terms of the GNU General Public License as published by
3435
3536; ;; Code:
3637
37- (require 'neotree-util )
38-
39-
4038; ;
4139; ; Constants
4240; ;
@@ -70,19 +68,22 @@ including . and ..")
7068; ;
7169
7270(defface neo-header-face
73- '((t :foreground " lightblue" :weight bold ))
71+ '((((background dark )) (:foreground " lightblue" :weight bold ))
72+ (t (:foreground " DarkMagenta" )))
7473 " *Face used for the header in neotree buffer."
7574 :group 'neotree :group 'font-lock-highlighting-faces )
7675(defvar neo-header-face 'neo-header-face )
7776
7877(defface neo-dir-link-face
79- '((t (:foreground " DeepSkyBlue" )))
78+ '((((background dark )) (:foreground " DeepSkyBlue" ))
79+ (t (:foreground " MediumBlue" )))
8080 " *Face used for expand sign [+] in neotree buffer."
8181 :group 'neotree :group 'font-lock-highlighting-faces )
8282(defvar neo-dir-link-face 'neo-dir-link-face )
8383
8484(defface neo-file-link-face
85- '((t (:foreground " White" )))
85+ '((((background dark )) (:foreground " White" ))
86+ (t (:foreground " Black" )))
8687 " *Face used for open file/dir in neotree buffer."
8788 :group 'neotree :group 'font-lock-highlighting-faces )
8889(defvar neo-file-link-face 'neo-file-link-face )
@@ -93,7 +94,7 @@ including . and ..")
9394 " *Face used for open file/dir in neotree buffer."
9495 :group 'neotree :group 'font-lock-highlighting-faces )
9596(defvar neo-expand-btn-face 'neo-expand-btn-face )
96-
97+
9798(defface neo-button-face
9899 '((t (:underline nil )))
99100 " *Face used for open file/dir in neotree buffer."
@@ -157,6 +158,119 @@ including . and ..")
157158 (lambda (arg ) 'no-indent ) nil 'local )))
158159
159160
161+ ; ;
162+ ; ; internal utility functions
163+ ; ;
164+
165+ (defun neo-filter (condp lst )
166+ (delq nil
167+ (mapcar (lambda (x ) (and (funcall condp x) x)) lst)))
168+
169+ (defun neo-find (where which )
170+ " find element of the list `where` matching predicate `which`"
171+ (catch 'found
172+ (dolist (elt where)
173+ (when (funcall which elt)
174+ (throw 'found elt)))
175+ nil ))
176+
177+ (defun neo-newline-and-begin ()
178+ (newline )
179+ (beginning-of-line ))
180+
181+ (defun neo-scroll-to-line (line &optional wind start-pos )
182+ " Recommended way to set the cursor to specified line"
183+ (goto-char (point-min ))
184+ (forward-line (1- line))
185+ (if start-pos (set-window-start wind start-pos)))
186+
187+ (defun neo-file-short-name (file )
188+ " Base file/directory name. Taken from
189+ http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01238.html"
190+ (or (if (string= file " /" ) " /" )
191+ (neo-printable-string (file-name-nondirectory (directory-file-name file)))))
192+
193+ (defun neo-printable-string (string )
194+ " Strip newline character from file names, like 'Icon\n '"
195+ (replace-regexp-in-string " \n " " " string))
196+
197+ (defun neo-insert-with-face (content face )
198+ (let ((pos-start (point )))
199+ (insert content)
200+ (set-text-properties pos-start
201+ (point )
202+ (list 'face face))))
203+
204+ (defun neo-file-truename (path )
205+ (let ((rlt (file-truename path)))
206+ (if (not (null rlt))
207+ (progn
208+ (if (and (file-directory-p rlt)
209+ (> (length rlt) 0 )
210+ (not (equal (substring rlt -1 ) " /" )))
211+ (setq rlt (concat rlt " /" )))
212+ rlt)
213+ nil )))
214+
215+ (defun neo-path-expand-name (path &optional current-dir )
216+ (or (if (file-name-absolute-p path) path)
217+ (let ((r-path path))
218+ (setq r-path (substitute-in-file-name r-path))
219+ (setq r-path (expand-file-name r-path current-dir))
220+ r-path)))
221+
222+ (defun neo-path-join (root &rest dirs )
223+ " Joins a series of directories together, like Python's os.path.join,
224+ (neo-path-join \" /tmp\" \" a\" \" b\" \" c\" ) => /tmp/a/b/c"
225+ (or (if (not dirs) root)
226+ (let ((tdir (car dirs))
227+ (epath nil ))
228+ (setq epath
229+ (or (if (equal tdir " ." ) root)
230+ (if (equal tdir " .." ) (neo-path-updir root))
231+ (neo-path-expand-name tdir root)))
232+ (apply 'neo-path-join
233+ epath
234+ (cdr dirs)))))
235+
236+ (defun neo-path-updir (path )
237+ (let ((r-path (neo-path-expand-name path)))
238+ (if (and (> (length r-path) 0 )
239+ (equal (substring r-path -1 ) " /" ))
240+ (setq r-path (substring r-path 0 -1 )))
241+ (if (eq (length r-path) 0 )
242+ (setq r-path " /" ))
243+ (directory-file-name
244+ (file-name-directory r-path))))
245+
246+ (defun neo-walk-dir (path )
247+ (let* ((full-path (neo-file-truename path)))
248+ (directory-files path 'full
249+ directory-files-no-dot-files-regexp)))
250+
251+ (defun neo-directory-has-file (dir )
252+ " To determine whether a directory(DIR) contains files"
253+ (and (file-exists-p dir)
254+ (file-directory-p dir)
255+ (neo-walk-dir dir)
256+ t ))
257+
258+ (defun neo-match-path-directory (path )
259+ (let ((true-path (neo-file-truename path))
260+ (rlt-path nil ))
261+ (setq rlt-path
262+ (catch 'rlt
263+ (if (file-directory-p true-path)
264+ (throw 'rlt true-path))
265+ (setq true-path
266+ (file-name-directory true-path))
267+ (if (file-directory-p true-path)
268+ (throw 'rlt true-path))))
269+ (if (not (null rlt-path))
270+ (setq rlt-path (neo-path-join " ." rlt-path " ./" )))
271+ rlt-path))
272+
273+
160274; ;
161275; ; Privates functions
162276; ;
@@ -180,6 +294,9 @@ including . and ..")
180294 (select-window (window-at 0 0 ))
181295 (split-window-horizontally )
182296 (switch-to-buffer (neo-get-buffer))
297+ (if (and (boundp 'linum-mode )
298+ (not (null linum-mode)))
299+ (linum-mode -1 ))
183300 (setf neo-window (get-buffer-window ))
184301 (select-window (window-right (get-buffer-window )))
185302 (neo-set-window-width neo-width)
@@ -243,9 +360,9 @@ including . and ..")
243360 (insert-char ?\s (* (- depth 1 ) 2 )) ; indent
244361 (setq btn-start-pos (point ))
245362 (neo-insert-with-face (if expanded " -" " +" )
246- neo-expand-btn-face)
363+ ' neo-expand-btn-face )
247364 (neo-insert-with-face (concat " " node-short-name " /" )
248- neo-dir-link-face)
365+ ' neo-dir-link-face )
249366 (setq btn-end-pos (point ))
250367 (make-button btn-start-pos
251368 btn-end-pos
0 commit comments