Fix C-g during `make-network-process'. (Reported by Mark Plaksin.)
[emacs.git] / lisp / eshell / em-script.el
blobd67c5e063c9b3971d0212994c057865a438a6d54
1 ;;; em-script.el --- Eshell script files
3 ;; Copyright (C) 1999, 2000, 2002, 2003, 2004,
4 ;; 2005 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)
13 ;; any later version.
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.
25 (provide 'em-script)
27 (eval-when-compile (require 'esh-maint))
29 (require 'eshell)
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)
37 ;;; Commentary:
39 ;;; User Variables:
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)
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)
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)
59 ;;; Functions:
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)
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))))
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)))))
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)))
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
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))))
138 (put 'eshell/. 'eshell-no-numeric-conversions t)
140 ;;; Code:
142 ;;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647
143 ;;; em-script.el ends here