Mercurial > emacs
annotate lisp/eshell/em-script.el @ 86402:aa024a0d77d4
Fix file name to match @setfilename.
author | Romain Francoise <romain@orebokech.com> |
---|---|
date | Sat, 24 Nov 2007 15:17:05 +0000 |
parents | a1e8300d3c55 |
children | 48c4bb2b7d11 1577bd98c621 f55f9811f5d7 |
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, |
75346 | 4 ;; 2005, 2006, 2007 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 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
78220
a1e8300d3c55
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
75346
diff
changeset
|
12 ;; the Free Software Foundation; either version 3, or (at your option) |
29876 | 13 ;; any later version. |
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 | |
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the | |
64085 | 22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
23 ;; Boston, MA 02110-1301, USA. | |
29876 | 24 |
25 (provide 'em-script) | |
26 | |
27 (eval-when-compile (require 'esh-maint)) | |
28 | |
48578 | 29 (require 'eshell) |
30 | |
29876 | 31 (defgroup eshell-script nil |
32 "This module allows for the execution of files containing Eshell | |
33 commands, as a script file." | |
34 :tag "Running script files." | |
35 :group 'eshell-module) | |
36 | |
37 ;;; Commentary: | |
38 | |
39 ;;; User Variables: | |
40 | |
41 (defcustom eshell-script-load-hook '(eshell-script-initialize) | |
42 "*A list of functions to call when loading `eshell-script'." | |
43 :type 'hook | |
44 :group 'eshell-script) | |
45 | |
46 (defcustom eshell-login-script (concat eshell-directory-name "login") | |
47 "*If non-nil, a file to invoke when starting up Eshell interactively. | |
48 This file should be a file containing Eshell commands, where comment | |
49 lines begin with '#'." | |
50 :type 'file | |
51 :group 'eshell-script) | |
52 | |
53 (defcustom eshell-rc-script (concat eshell-directory-name "profile") | |
54 "*If non-nil, a file to invoke whenever Eshell is started. | |
55 This includes when running `eshell-command'." | |
56 :type 'file | |
57 :group 'eshell-script) | |
58 | |
59 ;;; Functions: | |
60 | |
61 (defun eshell-script-initialize () | |
62 "Initialize the script parsing code." | |
63 (make-local-variable 'eshell-interpreter-alist) | |
64 (setq eshell-interpreter-alist | |
65 (cons '((lambda (file) | |
66 (string= (file-name-nondirectory file) | |
67 "eshell")) . eshell/source) | |
68 eshell-interpreter-alist)) | |
33020 | 69 (make-local-variable 'eshell-complex-commands) |
70 (setq eshell-complex-commands | |
71 (append '("source" ".") eshell-complex-commands)) | |
29876 | 72 ;; these two variables are changed through usage, but we don't want |
73 ;; to ruin it for other modules | |
74 (let (eshell-inside-quote-regexp | |
75 eshell-outside-quote-regexp) | |
76 (and (not eshell-non-interactive-p) | |
77 eshell-login-script | |
78 (file-readable-p eshell-login-script) | |
79 (eshell-do-eval | |
80 (list 'eshell-commands | |
81 (catch 'eshell-replace-command | |
82 (eshell-source-file eshell-login-script))) t)) | |
83 (and eshell-rc-script | |
84 (file-readable-p eshell-rc-script) | |
85 (eshell-do-eval | |
86 (list 'eshell-commands | |
87 (catch 'eshell-replace-command | |
88 (eshell-source-file eshell-rc-script))) t)))) | |
89 | |
90 (defun eshell-source-file (file &optional args subcommand-p) | |
91 "Execute a series of Eshell commands in FILE, passing ARGS. | |
92 Comments begin with '#'." | |
93 (interactive "f") | |
94 (let ((orig (point)) | |
95 (here (point-max)) | |
96 (inhibit-point-motion-hooks t) | |
97 after-change-functions) | |
98 (goto-char (point-max)) | |
99 (insert-file-contents file) | |
100 (goto-char (point-max)) | |
101 (throw 'eshell-replace-command | |
102 (prog1 | |
103 (list 'let | |
104 (list (list 'eshell-command-name (list 'quote file)) | |
105 (list 'eshell-command-arguments | |
106 (list 'quote args))) | |
107 (let ((cmd (eshell-parse-command (cons here (point))))) | |
108 (if subcommand-p | |
109 (setq cmd (list 'eshell-as-subcommand cmd))) | |
110 cmd)) | |
111 (delete-region here (point)) | |
112 (goto-char orig))))) | |
113 | |
114 (defun eshell/source (&rest args) | |
115 "Source a file in a subshell environment." | |
116 (eshell-eval-using-options | |
117 "source" args | |
118 '((?h "help" nil nil "show this usage screen") | |
119 :show-usage | |
120 :usage "FILE [ARGS] | |
121 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1, | |
122 $2, etc.") | |
123 (eshell-source-file (car args) (cdr args) t))) | |
124 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
125 (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
|
126 |
29876 | 127 (defun eshell/. (&rest args) |
128 "Source a file in the current environment." | |
129 (eshell-eval-using-options | |
130 "." args | |
131 '((?h "help" nil nil "show this usage screen") | |
132 :show-usage | |
133 :usage "FILE [ARGS] | |
134 Invoke the Eshell commands in FILE within the current shell | |
135 environment, binding ARGS to $1, $2, etc.") | |
136 (eshell-source-file (car args) (cdr args)))) | |
137 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
138 (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
|
139 |
29876 | 140 ;;; Code: |
141 | |
52401 | 142 ;;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647 |
29876 | 143 ;;; em-script.el ends here |