1 ;;; em-script.el --- Eshell script files
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
5 ;; Author: John Wiegley <johnw@gnu.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 (eval-when-compile (require 'esh-maint
))
30 (defgroup eshell-script nil
31 "This module allows for the execution of files containing Eshell
32 commands, as a script file."
33 :tag
"Running script files."
34 :group
'eshell-module
)
40 (defcustom eshell-script-load-hook
'(eshell-script-initialize)
41 "*A list of functions to call when loading `eshell-script'."
43 :group
'eshell-script
)
45 (defcustom eshell-login-script
(concat eshell-directory-name
"login")
46 "*If non-nil, a file to invoke when starting up Eshell interactively.
47 This file should be a file containing Eshell commands, where comment
48 lines begin with '#'."
50 :group
'eshell-script
)
52 (defcustom eshell-rc-script
(concat eshell-directory-name
"profile")
53 "*If non-nil, a file to invoke whenever Eshell is started.
54 This includes when running `eshell-command'."
56 :group
'eshell-script
)
60 (defun eshell-script-initialize ()
61 "Initialize the script parsing code."
62 (make-local-variable 'eshell-interpreter-alist
)
63 (setq eshell-interpreter-alist
64 (cons '((lambda (file)
65 (string= (file-name-nondirectory file
)
66 "eshell")) . eshell
/source
)
67 eshell-interpreter-alist
))
68 (make-local-variable 'eshell-complex-commands
)
69 (setq eshell-complex-commands
70 (append '("source" ".") eshell-complex-commands
))
71 ;; these two variables are changed through usage, but we don't want
72 ;; to ruin it for other modules
73 (let (eshell-inside-quote-regexp
74 eshell-outside-quote-regexp
)
75 (and (not eshell-non-interactive-p
)
77 (file-readable-p eshell-login-script
)
79 (list 'eshell-commands
80 (catch 'eshell-replace-command
81 (eshell-source-file eshell-login-script
))) t
))
83 (file-readable-p eshell-rc-script
)
85 (list 'eshell-commands
86 (catch 'eshell-replace-command
87 (eshell-source-file eshell-rc-script
))) t
))))
89 (defun eshell-source-file (file &optional args subcommand-p
)
90 "Execute a series of Eshell commands in FILE, passing ARGS.
91 Comments begin with '#'."
95 (inhibit-point-motion-hooks t
)
96 after-change-functions
)
97 (goto-char (point-max))
98 (insert-file-contents file
)
99 (goto-char (point-max))
100 (throw 'eshell-replace-command
103 (list (list 'eshell-command-name
(list 'quote file
))
104 (list 'eshell-command-arguments
106 (let ((cmd (eshell-parse-command (cons here
(point)))))
108 (setq cmd
(list 'eshell-as-subcommand cmd
)))
110 (delete-region here
(point))
113 (defun eshell/source
(&rest args
)
114 "Source a file in a subshell environment."
115 (eshell-eval-using-options
117 '((?h
"help" nil nil
"show this usage screen")
120 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1,
122 (eshell-source-file (car args
) (cdr args
) t
)))
124 (put 'eshell
/source
'eshell-no-numeric-conversions t
)
126 (defun eshell/.
(&rest args
)
127 "Source a file in the current environment."
128 (eshell-eval-using-options
130 '((?h
"help" nil nil
"show this usage screen")
133 Invoke the Eshell commands in FILE within the current shell
134 environment, binding ARGS to $1, $2, etc.")
135 (eshell-source-file (car args
) (cdr args
))))
137 (put 'eshell
/.
'eshell-no-numeric-conversions t
)
141 ;;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647
142 ;;; em-script.el ends here