Mercurial > emacs
annotate lisp/eshell/em-script.el @ 95144:c9d1dab54646
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Tue, 20 May 2008 16:33:58 +0000 |
parents | b5b0801a7637 |
children | ad5d26b1d5d1 |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37661
diff
changeset
|
1 ;;; em-script.el --- Eshell script files |
29876 | 2 |
74509 | 3 ;; Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, |
79707 | 4 ;; 2005, 2006, 2007, 2008 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 |
87073
1577bd98c621
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
23 ;;; Commentary: |
29876 | 24 |
87073
1577bd98c621
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
25 ;;; Code: |
29876 | 26 |
48578 | 27 (require 'eshell) |
28 | |
29876 | 29 (defgroup eshell-script nil |
30 "This module allows for the execution of files containing Eshell | |
31 commands, as a script file." | |
32 :tag "Running script files." | |
33 :group 'eshell-module) | |
34 | |
35 ;;; User Variables: | |
36 | |
37 (defcustom eshell-script-load-hook '(eshell-script-initialize) | |
38 "*A list of functions to call when loading `eshell-script'." | |
39 :type 'hook | |
40 :group 'eshell-script) | |
41 | |
42 (defcustom eshell-login-script (concat eshell-directory-name "login") | |
43 "*If non-nil, a file to invoke when starting up Eshell interactively. | |
44 This file should be a file containing Eshell commands, where comment | |
45 lines begin with '#'." | |
46 :type 'file | |
47 :group 'eshell-script) | |
48 | |
49 (defcustom eshell-rc-script (concat eshell-directory-name "profile") | |
50 "*If non-nil, a file to invoke whenever Eshell is started. | |
51 This includes when running `eshell-command'." | |
52 :type 'file | |
53 :group 'eshell-script) | |
54 | |
55 ;;; Functions: | |
56 | |
57 (defun eshell-script-initialize () | |
58 "Initialize the script parsing code." | |
59 (make-local-variable 'eshell-interpreter-alist) | |
60 (setq eshell-interpreter-alist | |
61 (cons '((lambda (file) | |
62 (string= (file-name-nondirectory file) | |
63 "eshell")) . eshell/source) | |
64 eshell-interpreter-alist)) | |
33020 | 65 (make-local-variable 'eshell-complex-commands) |
66 (setq eshell-complex-commands | |
67 (append '("source" ".") eshell-complex-commands)) | |
29876 | 68 ;; these two variables are changed through usage, but we don't want |
69 ;; to ruin it for other modules | |
70 (let (eshell-inside-quote-regexp | |
71 eshell-outside-quote-regexp) | |
72 (and (not eshell-non-interactive-p) | |
73 eshell-login-script | |
74 (file-readable-p eshell-login-script) | |
75 (eshell-do-eval | |
76 (list 'eshell-commands | |
77 (catch 'eshell-replace-command | |
78 (eshell-source-file eshell-login-script))) t)) | |
79 (and eshell-rc-script | |
80 (file-readable-p eshell-rc-script) | |
81 (eshell-do-eval | |
82 (list 'eshell-commands | |
83 (catch 'eshell-replace-command | |
84 (eshell-source-file eshell-rc-script))) t)))) | |
85 | |
86 (defun eshell-source-file (file &optional args subcommand-p) | |
87 "Execute a series of Eshell commands in FILE, passing ARGS. | |
88 Comments begin with '#'." | |
89 (interactive "f") | |
90 (let ((orig (point)) | |
91 (here (point-max)) | |
92 (inhibit-point-motion-hooks t) | |
93 after-change-functions) | |
94 (goto-char (point-max)) | |
95 (insert-file-contents file) | |
96 (goto-char (point-max)) | |
97 (throw 'eshell-replace-command | |
98 (prog1 | |
99 (list 'let | |
100 (list (list 'eshell-command-name (list 'quote file)) | |
101 (list 'eshell-command-arguments | |
102 (list 'quote args))) | |
103 (let ((cmd (eshell-parse-command (cons here (point))))) | |
104 (if subcommand-p | |
105 (setq cmd (list 'eshell-as-subcommand cmd))) | |
106 cmd)) | |
107 (delete-region here (point)) | |
108 (goto-char orig))))) | |
109 | |
110 (defun eshell/source (&rest args) | |
111 "Source a file in a subshell environment." | |
112 (eshell-eval-using-options | |
113 "source" args | |
114 '((?h "help" nil nil "show this usage screen") | |
115 :show-usage | |
116 :usage "FILE [ARGS] | |
117 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1, | |
118 $2, etc.") | |
119 (eshell-source-file (car args) (cdr args) t))) | |
120 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
121 (put 'eshell/source 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
122 |
29876 | 123 (defun eshell/. (&rest args) |
124 "Source a file in the current environment." | |
125 (eshell-eval-using-options | |
126 "." args | |
127 '((?h "help" nil nil "show this usage screen") | |
128 :show-usage | |
129 :usage "FILE [ARGS] | |
130 Invoke the Eshell commands in FILE within the current shell | |
131 environment, binding ARGS to $1, $2, etc.") | |
132 (eshell-source-file (car args) (cdr args)))) | |
133 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
134 (put 'eshell/. 'eshell-no-numeric-conversions t) |
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
135 |
87073
1577bd98c621
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
136 (provide 'em-script) |
29876 | 137 |
93975
1e3a407766b9
Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
87649
diff
changeset
|
138 ;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647 |
29876 | 139 ;;; em-script.el ends here |