mirror of https://github.com/Chizi123/.emacs.d.git

Chizi123
2018-11-17 5cb5f70b1872a757e93ea333b0e2dca50c6c8957
commit | author | age
5cb5f7 1 ;;; ztree-util.el --- Auxiliary utilities for the ztree package -*- lexical-binding: t; -*-
C 2
3 ;; Copyright (C) 2013-2016  Free Software Foundation, Inc.
4 ;;
5 ;; Author: Alexey Veretennikov <alexey.veretennikov@gmail.com>
6 ;;
7 ;; Created: 2013-11-11
8 ;;
9 ;; Keywords: files tools
10 ;; URL: https://github.com/fourier/ztree
11 ;; Compatibility: GNU Emacs 24.x
12 ;;
13 ;; This file is part of GNU Emacs.
14 ;;
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.
19 ;;
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.
24 ;;
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/>.
27 ;;
28 ;;; Commentary:
29
30 ;;; Code:
31 (defun ztree-find (where which)
32   "Find element of the list WHERE matching predicate WHICH."
33   (catch 'found
34     (dolist (elt where)
35       (when (funcall which elt)
36         (throw 'found elt)))
37     nil))
38
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"
42   (delq nil
43         (mapcar (lambda (x) (and (funcall condp x) x)) lst)))
44
45
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))
50
51
52 (defun ztree-file-short-name (file)
53   "By given FILE name return base file/directory name.
54 Taken from http://lists.gnu.org/archive/html/emacs-devel/2011-01/msg01238.html"
55   (let* ((dir (directory-file-name file))
56          (simple-dir (file-name-nondirectory dir)))
57     ;; check if the root directory
58     (if (string= "" simple-dir)
59         dir
60       (ztree-printable-string simple-dir))))
61
62
63 (defun ztree-car-atom (value)
64   "Return VALUE if value is an atom, otherwise (car value) or nil.
65 Used since `car-safe' returns nil for atoms"
66   (if (atom value) value (car value)))
67
68
69 (defun ztree-insert-with-face (text face)
70   "Insert TEXT with the FACE provided."
71   (let ((start (point)))
72     (insert text)
73     (put-text-property start (point) 'face face)))
74
75 (defun ztree-untrampify-filename (file)
76   "Return FILE as the local file name."
77   (or (file-remote-p file 'localname) file))
78
79 (defun ztree-quotify-string (str)
80   "Surround STR with quotes."
81   (concat "\"" str "\""))
82
83 (defun ztree-same-host-p (file1 file2)
84   "Return t if FILE1 and FILE2 are on the same host."
85   (let ((file1-remote (file-remote-p file1))
86         (file2-remote (file-remote-p file2)))
87     (string-equal file1-remote file2-remote)))
88
89
90 (provide 'ztree-util)
91
92 ;;; ztree-util.el ends here