1 ;;; em-script.el --- Eshell script files
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005, 2006 Free Software Foundation, Inc.
6 ;; Author: John Wiegley <johnw@gnu.org>
8 ;; This file is part of GNU Emacs.
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
12 ;; the Free Software Foundation; either version 2, or (at your option)
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.
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
22 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 (eval-when-compile (require 'esh-maint
))
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
)
41 (defcustom eshell-script-load-hook
'(eshell-script-initialize)
42 "*A list of functions to call when loading `eshell-script'."
44 :group
'eshell-script
)
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 '#'."
51 :group
'eshell-script
)
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'."
57 :group
'eshell-script
)
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
))
69 (make-local-variable 'eshell-complex-commands
)
70 (setq eshell-complex-commands
71 (append '("source" ".") eshell-complex-commands
))
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
)
78 (file-readable-p eshell-login-script
)
80 (list 'eshell-commands
81 (catch 'eshell-replace-command
82 (eshell-source-file eshell-login-script
))) t
))
84 (file-readable-p eshell-rc-script
)
86 (list 'eshell-commands
87 (catch 'eshell-replace-command
88 (eshell-source-file eshell-rc-script
))) t
))))
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 '#'."
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
104 (list (list 'eshell-command-name
(list 'quote file
))
105 (list 'eshell-command-arguments
107 (let ((cmd (eshell-parse-command (cons here
(point)))))
109 (setq cmd
(list 'eshell-as-subcommand cmd
)))
111 (delete-region here
(point))
114 (defun eshell/source
(&rest args
)
115 "Source a file in a subshell environment."
116 (eshell-eval-using-options
118 '((?h
"help" nil nil
"show this usage screen")
121 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1,
123 (eshell-source-file (car args
) (cdr args
) t
)))
125 (put 'eshell
/source
'eshell-no-numeric-conversions t
)
127 (defun eshell/.
(&rest args
)
128 "Source a file in the current environment."
129 (eshell-eval-using-options
131 '((?h
"help" nil nil
"show this usage screen")
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
))))
138 (put 'eshell
/.
'eshell-no-numeric-conversions t
)
142 ;;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647
143 ;;; em-script.el ends here