1 ;;; ztree-util.el --- Auxiliary utilities for the ztree package -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2013-2016 Free Software Foundation, Inc.
5 ;; Author: Alexey Veretennikov <alexey.veretennikov@gmail.com>
9 ;; Keywords: files tools
10 ;; URL: https://github.com/fourier/ztree
11 ;; Compatibility: GNU Emacs 24.x
13 ;; This file is part of GNU Emacs.
15 ;; GNU Emacs is free software: you can redistribute it and/or modify
16 ;; it under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation, either version 3 of the License, or
18 ;; (at your option) any later version.
20 ;; GNU Emacs is distributed in the hope that it will be useful,
21 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 ;; GNU General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
31 (defun ztree-find (where which)
32 "Find element of the list WHERE matching predicate WHICH."
35 (when (funcall which elt)
39 (defun ztree-filter (condp lst)
40 "Filter out elements not satisfying predicate CONDP in the list LST.
41 Taken from http://www.emacswiki.org/emacs/ElispCookbook#toc39"
43 (mapcar (lambda (x) (and (funcall condp x) x)) lst)))
46 (defun ztree-printable-string (string)
47 "Strip newline character from file names, like 'Icon\n.
48 Argument STRING string to process.'."
49 (replace-regexp-in-string "\n" "" string))
51 (defun ztree-file-short-name (file)
52 "By given FILE name return base file/directory name.
53 Taken from http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01238.html"
54 (ztree-printable-string (file-name-nondirectory (directory-file-name file))))
56 (defun ztree-car-atom (value)
57 "Return VALUE if value is an atom, otherwise (car value) or nil.
58 Used since `car-safe' returns nil for atoms"
59 (if (atom value) value (car value)))
62 (defun ztree-insert-with-face (text face)
63 "Insert TEXT with the FACE provided."
64 (let ((start (point)))
66 (put-text-property start (point) 'face face)))
70 ;;; ztree-util.el ends here