Mercurial > emacs
annotate lisp/eshell/em-basic.el @ 110170:5e7ec1dda5c0
gnus-html.el: Remove more white space before <pre_int> image spacers; Decode entities at the end. So that entities inside the tags don't mess up the rest of the "parsing".
author | Katsumi Yamaoka <yamaoka@jpl.org> |
---|---|
date | Sat, 04 Sep 2010 00:36:13 +0000 |
parents | ed16fdd2685a |
children | f57f72bb4757 376148b31b5e |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
32526
diff
changeset
|
1 ;;; em-basic.el --- basic shell builtin commands |
29876 | 2 |
95150
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
106815 | 4 ;; 2008, 2009, 2010 Free Software Foundation, Inc. |
29876 | 5 |
32526 | 6 ;; Author: John Wiegley <johnw@gnu.org> |
7 | |
29876 | 8 ;; This file is part of GNU Emacs. |
9 | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
10 ;; GNU Emacs is free software: you can redistribute it and/or modify |
29876 | 11 ;; it under the terms of the GNU General Public License as published by |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
12 ;; the Free Software Foundation, either version 3 of the License, or |
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; (at your option) any later version. |
29876 | 14 |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
94661
b5b0801a7637
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
29876 | 22 |
23 ;;; Commentary: | |
24 | |
25 ;; There are very few basic Eshell commands -- so-called builtins. | |
26 ;; They are: echo, umask, and version. | |
27 ;; | |
28 ;;;_* `echo' | |
29 ;; | |
30 ;; The `echo' command repeats its arguments to the screen. It is | |
31 ;; optional whether this is done in a Lisp-friendly fashion (so that | |
32 ;; the value of echo is useful to a Lisp command using the result of | |
33 ;; echo as an argument), or whether it should try to act like a normal | |
34 ;; shell echo, and always result in a flat string being returned. | |
35 | |
36 ;; An example of the difference is the following: | |
37 ;; | |
38 ;; echo Hello world | |
39 ;; | |
40 ;; If `eshell-plain-echo-behavior' is non-nil, this will yield the | |
41 ;; string "Hello world". If Lisp behavior is enabled, however, it | |
42 ;; will yield a list whose two elements are the strings "Hello" and | |
43 ;; "world". The way to write an equivalent expression for both would | |
44 ;; be: | |
45 ;; | |
46 ;; echo "Hello world" | |
47 ;; | |
48 ;; This always returns a single string. | |
49 ;; | |
50 ;;;_* `umask' | |
51 ;; | |
52 ;; The umask command changes the default file permissions for newly | |
53 ;; created files. It uses the same syntax as bash. | |
54 ;; | |
55 ;;;_* `version' | |
56 ;; | |
57 ;; This command reports the version number for Eshell and all its | |
58 ;; dependent module, including the date when those modules were last | |
59 ;; modified. | |
60 | |
61 ;;; Code: | |
62 | |
87064
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
63 (eval-when-compile |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
64 (require 'esh-util)) |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
65 |
95150
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
66 (require 'eshell) |
29876 | 67 (require 'esh-opt) |
68 | |
95150
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
69 ;;;###autoload |
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
70 (eshell-defgroup eshell-basic nil |
87064
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
71 "The \"basic\" code provides a set of convenience functions which |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
72 are traditionally considered shell builtins. Since all of the |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
73 functionality provided by them is accessible through Lisp, they are |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
74 not really builtins at all, but offer a command-oriented way to do the |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
75 same thing." |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
76 :tag "Basic shell commands" |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
77 :group 'eshell-module) |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
78 |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
79 (defcustom eshell-plain-echo-behavior nil |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
80 "*If non-nil, `echo' tries to behave like an ordinary shell echo. |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
81 This comes at some detriment to Lisp functionality. However, the Lisp |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
82 equivalent of `echo' can always be achieved by using `identity'." |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
83 :type 'boolean |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
84 :group 'eshell-basic) |
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
85 |
29876 | 86 ;;; Functions: |
87 | |
88 (defun eshell-echo (args &optional output-newline) | |
89 "Implementation code for a Lisp version of `echo'. | |
90 It returns a formatted value that should be passed to `eshell-print' | |
91 or `eshell-printn' for display." | |
92 (if eshell-plain-echo-behavior | |
93 (concat (apply 'eshell-flatten-and-stringify args) "\n") | |
94 (let ((value | |
95 (cond | |
96 ((= (length args) 0) "") | |
97 ((= (length args) 1) | |
98 (car args)) | |
99 (t | |
100 (mapcar | |
101 (function | |
102 (lambda (arg) | |
103 (if (stringp arg) | |
104 (set-text-properties 0 (length arg) nil arg)) | |
105 arg)) | |
106 args))))) | |
107 (if output-newline | |
108 (cond | |
109 ((stringp value) | |
110 (concat value "\n")) | |
111 ((listp value) | |
112 (append value (list "\n"))) | |
113 (t | |
114 (concat (eshell-stringify value) "\n"))) | |
115 value)))) | |
116 | |
117 (defun eshell/echo (&rest args) | |
118 "Implementation of `echo'. See `eshell-plain-echo-behavior'." | |
119 (eshell-eval-using-options | |
120 "echo" args | |
121 '((?n nil nil output-newline "terminate with a newline") | |
122 (?h "help" nil nil "output this help screen") | |
123 :preserve-args | |
124 :usage "[-n] [object]") | |
125 (eshell-echo args output-newline))) | |
126 | |
127 (defun eshell/printnl (&rest args) | |
107517
ed16fdd2685a
Fix typos in docstrings.
Juanma Barranquero <lekktu@gmail.com>
parents:
106815
diff
changeset
|
128 "Print out each of the arguments, separated by newlines." |
29876 | 129 (let ((elems (eshell-flatten-list args))) |
130 (while elems | |
131 (eshell-printn (eshell-echo (list (car elems)))) | |
132 (setq elems (cdr elems))))) | |
133 | |
134 (defun eshell/listify (&rest args) | |
135 "Return the argument(s) as a single list." | |
136 (if (> (length args) 1) | |
137 args | |
138 (if (listp (car args)) | |
139 (car args) | |
140 (list (car args))))) | |
141 | |
142 (defun eshell/umask (&rest args) | |
143 "Shell-like implementation of `umask'." | |
144 (eshell-eval-using-options | |
145 "umask" args | |
146 '((?S "symbolic" nil symbolic-p "display umask symbolically") | |
147 (?h "help" nil nil "display this usage message") | |
148 :usage "[-S] [mode]") | |
149 (if (or (not args) symbolic-p) | |
150 (let ((modstr | |
151 (concat "000" | |
152 (format "%o" | |
153 (logand (lognot (default-file-modes)) | |
154 511))))) | |
155 (setq modstr (substring modstr (- (length modstr) 3))) | |
156 (when symbolic-p | |
157 (let ((mode (default-file-modes))) | |
158 (setq modstr | |
159 (format | |
160 "u=%s,g=%s,o=%s" | |
161 (concat (and (= (logand mode 64) 64) "r") | |
162 (and (= (logand mode 128) 128) "w") | |
163 (and (= (logand mode 256) 256) "x")) | |
164 (concat (and (= (logand mode 8) 8) "r") | |
165 (and (= (logand mode 16) 16) "w") | |
166 (and (= (logand mode 32) 32) "x")) | |
167 (concat (and (= (logand mode 1) 1) "r") | |
168 (and (= (logand mode 2) 2) "w") | |
169 (and (= (logand mode 4) 4) "x")))))) | |
170 (eshell-printn modstr)) | |
171 (setcar args (eshell-convert (car args))) | |
172 (if (numberp (car args)) | |
173 (set-default-file-modes | |
174 (- 511 (car (read-from-string | |
175 (concat "?\\" (number-to-string (car args))))))) | |
176 (error "setting umask symbolically is not yet implemented")) | |
177 (eshell-print | |
178 "Warning: umask changed for all new files created by Emacs.\n")) | |
179 nil)) | |
180 | |
87064
ce46e8bcbccd
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
181 (provide 'em-basic) |
29876 | 182 |
95150
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
183 ;; Local Variables: |
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
184 ;; generated-autoload-file: "esh-groups.el" |
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
185 ;; End: |
7986c1ee0292
Require eshell, for eshell-defgroup.
Glenn Morris <rgm@gnu.org>
parents:
94661
diff
changeset
|
186 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
187 ;; arch-tag: 385a31b1-cb95-46f0-9829-9d352ee77db8 |
29876 | 188 ;;; em-basic.el ends here |