1 ;;; em-script.el --- Eshell script files
3 ;; Copyright (C) 1999-2011 Free Software Foundation, Inc.
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 3 of the License, or
12 ;; (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>.
29 (eshell-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)
37 (defcustom eshell-script-load-hook '(eshell-script-initialize)
38 "A list of functions to call when loading `eshell-script'."
40 :group 'eshell-script)
42 (defcustom eshell-login-script (expand-file-name "login" eshell-directory-name)
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 '#'."
47 :group 'eshell-script)
49 (defcustom eshell-rc-script (expand-file-name "profile" eshell-directory-name)
50 "If non-nil, a file to invoke whenever Eshell is started.
51 This includes when running `eshell-command'."
53 :group 'eshell-script)
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))
65 (make-local-variable 'eshell-complex-commands)
66 (setq eshell-complex-commands
67 (append '("source" ".") eshell-complex-commands))
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)
74 (file-readable-p eshell-login-script)
76 (list 'eshell-commands
77 (catch 'eshell-replace-command
78 (eshell-source-file eshell-login-script))) t))
80 (file-readable-p eshell-rc-script)
82 (list 'eshell-commands
83 (catch 'eshell-replace-command
84 (eshell-source-file eshell-rc-script))) t))))
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 '#'."
92 (inhibit-point-motion-hooks t))
93 (goto-char (point-max))
94 (with-silent-modifications
95 ;; FIXME: Why not use a temporary buffer and avoid this
96 ;; "insert&delete" business? --Stef
97 (insert-file-contents file)
98 (goto-char (point-max))
99 (throw 'eshell-replace-command
102 (list (list 'eshell-command-name (list 'quote file))
103 (list 'eshell-command-arguments
105 (let ((cmd (eshell-parse-command (cons here (point)))))
107 (setq cmd (list 'eshell-as-subcommand cmd)))
109 (delete-region here (point))
110 (goto-char orig))))))
112 (defun eshell/source (&rest args)
113 "Source a file in a subshell environment."
114 (eshell-eval-using-options
116 '((?h "help" nil nil "show this usage screen")
119 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1,
121 (eshell-source-file (car args) (cdr args) t)))
123 (put 'eshell/source 'eshell-no-numeric-conversions t)
125 (defun eshell/. (&rest args)
126 "Source a file in the current environment."
127 (eshell-eval-using-options
129 '((?h "help" nil nil "show this usage screen")
132 Invoke the Eshell commands in FILE within the current shell
133 environment, binding ARGS to $1, $2, etc.")
134 (eshell-source-file (car args) (cdr args))))
136 (put 'eshell/. 'eshell-no-numeric-conversions t)
141 ;; generated-autoload-file: "esh-groups.el"
144 ;;; em-script.el ends here