annotate lisp/eshell/em-pred.el @ 42145:77f35c49c817

*** empty log message ***
author Dave Love <fx@gnu.org>
date Tue, 18 Dec 2001 17:25:48 +0000
parents 67b464da13ec
children 7c5bd619612f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38006
diff changeset
1 ;;; em-pred.el --- argument predicates and modifiers (ala zsh)
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
29934
34b1ab9d583d Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents: 29876
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
32526
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 32446
diff changeset
5 ;; Author: John Wiegley <johnw@gnu.org>
8e57189d61b4 Add author information.
Gerd Moellmann <gerd@gnu.org>
parents: 32446
diff changeset
6
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; any later version.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; GNU General Public License for more details.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 (provide 'em-pred)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 (eval-when-compile (require 'esh-maint))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 (defgroup eshell-pred nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 "This module allows for predicates to be applied to globbing
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 patterns (similar to zsh), in addition to string modifiers which can
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 be applied either to globbing results, variable references, or just
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32 ordinary strings."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 :tag "Value modifiers and predicates"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34 :group 'eshell-module)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;;; Commentary:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38 ;; Argument predication is used to affect which members of a list are
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 ;; selected for use as argument. This is most useful with globbing,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 ;; but can be used on any list argument, to select certain members.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; Argument modifiers are used to manipulate argument values. For
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 ;; example, sorting lists, upcasing words, substituting characters,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44 ;; etc.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 ;; Here are some examples of how to use argument predication. Most of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 ;; the predicates and modifiers are modeled after those provided by
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 ;; zsh.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 ;;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 ;; ls -ld *(/) ; list all directories
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 ;; ls -l *(@u'johnw') ; list all symlinks owned by 'johnw'
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 ;; bzip2 -9v **/*(a+30) ; compress everything which hasn't been
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 ;; accessed in 30 days
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54 ;; echo *.c(:o:R) ; a reversed, sorted list of C files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; *(^@:U^u0) ; all non-symlinks not owned by 'root', upcased
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 ;; chmod u-x *(U*) : remove exec bit on all executables owned by user
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 ;;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 ;; See the zsh docs for more on the syntax ([(zsh.info)Filename
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 ;; Generation]).
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60
38414
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38006
diff changeset
61 ;;; Code:
67b464da13ec Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38006
diff changeset
62
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 ;;; User Variables:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 (defcustom eshell-pred-load-hook '(eshell-pred-initialize)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 "*A list of functions to run when `eshell-pred' is loaded."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 :group 'eshell-pred)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (defcustom eshell-predicate-alist
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 '((?/ . (eshell-pred-file-type ?d)) ; directories
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (?. . (eshell-pred-file-type ?-)) ; regular files
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 (?s . (eshell-pred-file-type ?s)) ; sockets
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74 (?p . (eshell-pred-file-type ?p)) ; named pipes
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 (?@ . (eshell-pred-file-type ?l)) ; symbolic links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (?% . (eshell-pred-file-type ?%)) ; allow user to specify (c def.)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (?r . (eshell-pred-file-mode 0400)) ; owner-readable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 (?w . (eshell-pred-file-mode 0200)) ; owner-writable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (?x . (eshell-pred-file-mode 0100)) ; owner-executable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 (?A . (eshell-pred-file-mode 0040)) ; group-readable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 (?I . (eshell-pred-file-mode 0020)) ; group-writable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (?E . (eshell-pred-file-mode 0010)) ; group-executable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 (?R . (eshell-pred-file-mode 0004)) ; world-readable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 (?W . (eshell-pred-file-mode 0002)) ; world-writable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 (?X . (eshell-pred-file-mode 0001)) ; world-executable
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (?s . (eshell-pred-file-mode 4000)) ; setuid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 (?S . (eshell-pred-file-mode 2000)) ; setgid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88 (?t . (eshell-pred-file-mode 1000)) ; sticky bit
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 (?U . '(lambda (file) ; owned by effective uid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 (if (file-exists-p file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91 (= (nth 2 (file-attributes file)) (user-uid)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;;; (?G . '(lambda (file) ; owned by effective gid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 ;;; (if (file-exists-p file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94 ;;; (= (nth 2 (file-attributes file)) (user-uid)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 (?* . '(lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 (and (file-regular-p file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97 (not (file-symlink-p file))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 (file-executable-p file))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 (?l . (eshell-pred-file-links))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 (?u . (eshell-pred-user-or-group ?u "user" 2 'eshell-user-id))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 (?g . (eshell-pred-user-or-group ?g "group" 3 'eshell-group-id))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 (?a . (eshell-pred-file-time ?a "access" 4))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 (?m . (eshell-pred-file-time ?m "modification" 5))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 (?c . (eshell-pred-file-time ?c "change" 6))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 (?L . (eshell-pred-file-size)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 "*A list of predicates than can be applied to a globbing pattern.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107 The format of each entry is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 (CHAR . PREDICATE-FUNC-SEXP)"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 :type '(repeat (cons character sexp))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 :group 'eshell-pred)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 (put 'eshell-predicate-alist 'risky-local-variable t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 (defcustom eshell-modifier-alist
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116 '((?e . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 (lambda (str)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 (eshell-stringify
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121 (car (eshell-parse-argument str))))) lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (?L . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 (mapcar 'downcase lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 (?U . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 (mapcar 'upcase lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126 (?C . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (mapcar 'capitalize lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 (?h . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 (mapcar 'file-name-directory lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 (?i . (eshell-include-members))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131 (?x . (eshell-include-members t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (?r . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (mapcar 'file-name-sans-extension lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 (?e . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 (mapcar 'file-name-extension lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 (?t . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 (mapcar 'file-name-nondirectory lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138 (?q . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 (mapcar 'eshell-escape-arg lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140 (?u . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (eshell-uniqify-list lst)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (?o . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (sort lst 'string-lessp)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (?O . '(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (nreverse (sort lst 'string-lessp))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (?j . (eshell-join-members))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (?S . (eshell-split-members))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148 (?R . 'reverse)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 (?g . (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (if (eq (char-before) ?s)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 (eshell-pred-substitute t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (error "`g' modifier cannot be used alone"))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (?s . (eshell-pred-substitute)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 "*A list of modifiers than can be applied to an argument expansion.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156 The format of each entry is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 (CHAR ENTRYWISE-P MODIFIER-FUNC-SEXP)"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 :type '(repeat (cons character sexp))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 :group 'eshell-pred)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (put 'eshell-modifier-alist 'risky-local-variable t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (defvar eshell-predicate-help-string
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 "Eshell predicate quick reference:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167 - follow symbolic references for predicates after the `-'
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 ^ invert sense of predicates after the `^'
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 FILE TYPE:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 / directories s sockets
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 . regular files p named pipes
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 * executable (files only) @ symbolic links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 %x file type == `x' (as by ls -l; so `c' = char device, etc.)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 PERMISSION BITS (for owner/group/world):
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 r/A/R readable s setuid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 w/I/W writable S setgid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 x/E/X executable t sticky bit
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 OWNERSHIP:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 U owned by effective uid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 u(UID|'user') owned by UID/user
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 g(GID|'group') owned by GID/group
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187 FILE ATTRIBUTES:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 l[+-]N +/-/= N links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 a[Mwhm][+-](N|'FILE') access time +/-/= N mnths/weeks/days/mins
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 if FILE specified, use as comparison basis;
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 so a+'file.c' shows files accessed before
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 file.c was last accessed
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193 m[Mwhm][+-](N|'FILE') modification time...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 c[Mwhm][+-](N|'FILE') change time...
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 L[kmp][+-]N file size +/-/= N Kb/Mb/blocks
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 EXAMPLES:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 *(^@) all non-dot files which are not symlinks
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 .#*(^@) all files which are not symbolic links
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200 **/.#*(*) all executable files, searched recursively
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 ***/*~f*(-/) recursively (though not traversing symlinks),
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202 find all directories (or symlinks referring to
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 directories) whose names do not begin with f.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 e*(*Lk+50) executables 50k or larger beginning with 'e'")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 (defvar eshell-modifier-help-string
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 "Eshell modifier quick reference:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 FOR SINGLE ARGUMENTS, or each argument of a list of strings:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 e evaluate again
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 L lowercase
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 U uppercase
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 C capitalize
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 h dirname
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 t basename
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 e file extension
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 r strip file extension
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 q escape special characters
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 S split string at any whitespace character
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 S/PAT/ split string at each occurance of PAT
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 FOR LISTS OF ARGUMENTS:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 o sort alphabetically
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 O reverse sort alphabetically
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 u uniq list (typically used after :o or :O)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 R reverse list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 j join list members, separated by a space
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 j/PAT/ join list members, separated by PAT
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 i/PAT/ exclude all members not matching PAT
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232 x/PAT/ exclude all members matching PAT
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 s/pat/match/ substitute PAT with MATCH
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 g/pat/match/ substitute PAT with MATCH for all occurances
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 EXAMPLES:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 *.c(:o) sorted list of .c files")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 ;;; Functions:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (defun eshell-display-predicate-help ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (with-electric-help
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (lambda ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (insert eshell-predicate-help-string)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (defun eshell-display-modifier-help ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 (interactive)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (with-electric-help
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (lambda ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 (insert eshell-modifier-help-string)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (defun eshell-pred-initialize ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 "Initialize the predicate/modifier code."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 (make-local-hook 'eshell-parse-argument-hook)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (add-hook 'eshell-parse-argument-hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 'eshell-parse-arg-modifier t t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 (define-key eshell-command-map [(meta ?q)] 'eshell-display-predicate-help)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (define-key eshell-command-map [(meta ?m)] 'eshell-display-modifier-help))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 (defun eshell-apply-modifiers (lst predicates modifiers)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265 "Apply to LIST a series of PREDICATES and MODIFIERS."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (let (stringified)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 (if (stringp lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (setq lst (list lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269 stringified t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (when (listp lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 (setq lst (eshell-winnow-list lst nil predicates))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (while modifiers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (setq lst (funcall (car modifiers) lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 modifiers (cdr modifiers)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (if (and stringified
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276 (= (length lst) 1))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (car lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 lst))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (defun eshell-parse-arg-modifier ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 "Parse a modifier that has been specified after an argument.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 This function is specially for adding onto `eshell-parse-argument-hook'."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (when (eq (char-after) ?\()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285 (let ((end (eshell-find-delimiter ?\( ?\))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (if (not end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 (throw 'eshell-incomplete ?\()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 (when (eshell-arg-delimiter (1+ end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 (save-restriction
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (narrow-to-region (point) end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (let* ((modifiers (eshell-parse-modifiers))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (preds (car modifiers))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (mods (cdr modifiers)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (if (or preds mods)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 ;; has to go at the end, which is only natural since
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 ;; syntactically it can only occur at the end
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (setq eshell-current-modifiers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 (append
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 eshell-current-modifiers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 `(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (eshell-apply-modifiers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 lst (quote ,preds) (quote ,mods)))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 (goto-char (1+ end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 (eshell-finish-arg))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 (defun eshell-parse-modifiers ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 "Parse value modifiers and predicates at point.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 If ALLOW-PREDS is non-nil, predicates will be parsed as well.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 Return a cons cell of the form
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 (PRED-FUNC-LIST . MOD-FUNC-LIST)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 NEW-STRING is STRING minus any modifiers. PRED-FUNC-LIST is a list of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315 predicate functions. MOD-FUNC-LIST is a list of result modifier
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 functions. PRED-FUNCS take a filename and return t if the test
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 succeeds; MOD-FUNCS take any string and preform a modification,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 returning the resultant string."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (let (result negate follow preds mods)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (condition-case err
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (while (not (eobp))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (let ((char (char-after)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 ((eq char ?')
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (if (looking-at "[^|':]")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327 (let ((func (read (current-buffer))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (if (and func (functionp func))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 (setq preds (eshell-add-pred-func func preds
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 negate follow))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (error "Invalid function predicate '%s'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (eshell-stringify func))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (error "Invalid function predicate")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 ((eq char ?^)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (setq negate (not negate)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 ((eq char ?-)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (setq follow (not follow)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 ((eq char ?|)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342 (if (looking-at "[^|':]")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (let ((func (read (current-buffer))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 (if (and func (functionp func))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (setq mods
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (cons `(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 (mapcar (function ,func) lst))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 mods))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 (error "Invalid function modifier '%s'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (eshell-stringify func))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (error "Invalid function modifier")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 ((eq char ?:)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (let ((mod (assq (char-after) eshell-modifier-alist)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (if (not mod)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (error "Unknown modifier character '%c'" (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (setq mods (cons (eval (cdr mod)) mods)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360 (let ((pred (assq char eshell-predicate-alist)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (if (not pred)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 (error "Unknown predicate character '%c'" char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 (setq preds
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 (eshell-add-pred-func (eval (cdr pred)) preds
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 negate follow))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 (end-of-buffer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (error "Predicate or modifier ended prematurely")))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (cons (nreverse preds) (nreverse mods))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 (defun eshell-add-pred-func (pred funcs negate follow)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 "Add the predicate function PRED to FUNCS."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (if negate
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 (setq pred `(lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (not (funcall ,pred file)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 (if follow
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (setq pred `(lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 (funcall ,pred (file-truename file)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (cons pred funcs))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (defun eshell-pred-user-or-group (mod-char mod-type attr-index get-id-func)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382 "Return a predicate to test whether a file match a given user/group id."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 (let (ugid open close end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
384 (if (looking-at "[0-9]+")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
385 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
386 (setq ugid (string-to-number (match-string 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
387 (goto-char (match-end 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
388 (setq open (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
389 (if (setq close (memq open '(?\( ?\[ ?\< ?\{)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
390 (setq close (car (last '(?\) ?\] ?\> ?\})
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
391 (length close))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
392 (setq close open))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
393 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
394 (setq end (eshell-find-delimiter open close))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
395 (unless end
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
396 (error "Malformed %s name string for modifier `%c'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
397 mod-type mod-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
398 (setq ugid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
399 (funcall get-id-func (buffer-substring (point) end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
400 (goto-char (1+ end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
401 (unless ugid
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
402 (error "Unknown %s name specified for modifier `%c'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
403 mod-type mod-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
404 `(lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
405 (let ((attrs (file-attributes file)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
406 (if attrs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
407 (= (nth ,attr-index attrs) ,ugid))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
408
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
409 (defun eshell-pred-file-time (mod-char mod-type attr-index)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
410 "Return a predicate to test whether a file matches a certain time."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
411 (let* ((quantum 86400)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
412 qual amount when open close end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
413 (when (memq (char-after) '(?M ?w ?h ?m))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
414 (setq quantum (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
415 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
416 ((eq quantum ?M)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
417 (setq quantum (* 60 60 24 30)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
418 ((eq quantum ?w)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
419 (setq quantum (* 60 60 24 7)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
420 ((eq quantum ?h)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
421 (setq quantum (* 60 60)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
422 ((eq quantum ?m)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
423 (setq quantum 60))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
424 ((eq quantum ?s)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
425 (setq quantum 1)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
426 (forward-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
427 (when (memq (char-after) '(?+ ?-))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
428 (setq qual (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
429 (forward-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
430 (if (looking-at "[0-9]+")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
431 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
432 (setq when (- (eshell-time-to-seconds (current-time))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
433 (* (string-to-number (match-string 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
434 quantum)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
435 (goto-char (match-end 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
436 (setq open (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
437 (if (setq close (memq open '(?\( ?\[ ?\< ?\{)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
438 (setq close (car (last '(?\) ?\] ?\> ?\})
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
439 (length close))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
440 (setq close open))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
441 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
442 (setq end (eshell-find-delimiter open close))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
443 (unless end
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
444 (error "Malformed %s time modifier `%c'" mod-type mod-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
445 (let* ((file (buffer-substring (point) end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
446 (attrs (file-attributes file)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
447 (unless attrs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
448 (error "Cannot stat file `%s'" file))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
449 (setq when (eshell-time-to-seconds (nth attr-index attrs))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
450 (goto-char (1+ end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
451 `(lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
452 (let ((attrs (file-attributes file)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
453 (if attrs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
454 (,(if (eq qual ?-)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
455 '<
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
456 (if (eq qual ?+)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
457 '>
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
458 '=)) ,when (eshell-time-to-seconds
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
459 (nth ,attr-index attrs))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
460
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
461 (defun eshell-pred-file-type (type)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
462 "Return a test which tests that the file is of a certain TYPE.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
463 TYPE must be a character, and should be one of the possible options
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
464 that 'ls -l' will show in the first column of its display. "
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
465 (when (eq type ?%)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
466 (setq type (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
467 (if (memq type '(?b ?c))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
468 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
469 (setq type ?%)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
470 `(lambda (file)
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
471 (let ((attrs (eshell-file-attributes (directory-file-name file))))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
472 (if attrs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
473 (memq (aref (nth 8 attrs) 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
474 ,(if (eq type ?%)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
475 '(?b ?c)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
476 (list 'quote (list type))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
477
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
478 (defsubst eshell-pred-file-mode (mode)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
479 "Return a test which tests that MODE pertains to the file."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
480 `(lambda (file)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
481 (let ((modes (file-modes file)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
482 (if modes
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
483 (logand ,mode modes)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
484
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
485 (defun eshell-pred-file-links ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
486 "Return a predicate to test whether a file has a given number of links."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
487 (let (qual amount)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
488 (when (memq (char-after) '(?- ?+))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
489 (setq qual (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
490 (forward-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
491 (unless (looking-at "[0-9]+")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
492 (error "Invalid file link count modifier `l'"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
493 (setq amount (string-to-number (match-string 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
494 (goto-char (match-end 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
495 `(lambda (file)
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
496 (let ((attrs (eshell-file-attributes file)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
497 (if attrs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
498 (,(if (eq qual ?-)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
499 '<
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
500 (if (eq qual ?+)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
501 '>
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
502 '=)) (nth 1 attrs) ,amount))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
503
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
504 (defun eshell-pred-file-size ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
505 "Return a predicate to test whether a file is of a given size."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
506 (let ((quantum 1) qual amount)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
507 (when (memq (downcase (char-after)) '(?k ?m ?p))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
508 (setq qual (downcase (char-after)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
509 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
510 ((eq qual ?k)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
511 (setq quantum 1024))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
512 ((eq qual ?m)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
513 (setq quantum (* 1024 1024)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
514 ((eq qual ?p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
515 (setq quantum 512)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
516 (forward-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
517 (when (memq (char-after) '(?- ?+))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
518 (setq qual (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
519 (forward-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
520 (unless (looking-at "[0-9]+")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
521 (error "Invalid file size modifier `L'"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
522 (setq amount (* (string-to-number (match-string 0)) quantum))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
523 (goto-char (match-end 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
524 `(lambda (file)
32446
aab90b31807c Added better remote directory support to Eshell, as well as a few bug
John Wiegley <johnw@newartisans.com>
parents: 29934
diff changeset
525 (let ((attrs (eshell-file-attributes file)))
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
526 (if attrs
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
527 (,(if (eq qual ?-)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
528 '<
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
529 (if (eq qual ?+)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
530 '>
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
531 '=)) (nth 7 attrs) ,amount))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
532
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
533 (defun eshell-pred-substitute (&optional repeat)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
534 "Return a modifier function that will substitute matches."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
535 (let ((delim (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
536 match replace end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
537 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
538 (setq end (eshell-find-delimiter delim delim nil nil t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
539 match (buffer-substring-no-properties (point) end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
540 (goto-char (1+ end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
541 (setq end (eshell-find-delimiter delim delim nil nil t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
542 replace (buffer-substring-no-properties (point) end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
543 (goto-char (1+ end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
544 (if repeat
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
545 `(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
546 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
547 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
548 (lambda (str)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
549 (let ((i 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
550 (while (setq i (string-match ,match str i))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
551 (setq str (replace-match ,replace t nil str))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
552 str)) lst))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
553 `(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
554 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
555 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
556 (lambda (str)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
557 (if (string-match ,match str)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
558 (setq str (replace-match ,replace t nil str)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
559 str)) lst)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
560
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
561 (defun eshell-include-members (&optional invert-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
562 "Include only lisp members matching a regexp."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
563 (let ((delim (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
564 regexp end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
565 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
566 (setq end (eshell-find-delimiter delim delim nil nil t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
567 regexp (buffer-substring-no-properties (point) end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
568 (goto-char (1+ end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
569 `(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
570 (eshell-winnow-list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
571 lst nil '((lambda (elem)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
572 ,(if invert-p
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
573 `(not (string-match ,regexp elem))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
574 `(string-match ,regexp elem))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
575
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
576 (defun eshell-join-members ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
577 "Return a modifier function that join matches."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
578 (let ((delim (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
579 str end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
580 (if (not (memq delim '(?' ?/)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
581 (setq delim " ")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
582 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
583 (setq end (eshell-find-delimiter delim delim nil nil t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
584 str (buffer-substring-no-properties (point) end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
585 (goto-char (1+ end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
586 `(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
587 (mapconcat 'identity lst ,str))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
588
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
589 (defun eshell-split-members ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
590 "Return a modifier function that splits members."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
591 (let ((delim (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
592 sep end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
593 (when (memq delim '(?' ?/))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
594 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
595 (setq end (eshell-find-delimiter delim delim nil nil t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
596 sep (buffer-substring-no-properties (point) end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
597 (goto-char (1+ end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
598 `(lambda (lst)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
599 (mapcar
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
600 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
601 (lambda (str)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
602 (split-string str ,sep))) lst))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
603
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
604 ;;; em-pred.el ends here