Mercurial > emacs
annotate lisp/eshell/em-script.el @ 87967:8582a4cb24e3
*** empty log message ***
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Fri, 25 Jan 2008 15:46:07 +0000 |
parents | 107ccd98fa12 |
children | 606f2d163a64 1e3a407766b9 |
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, |
79707 | 4 ;; 2005, 2006, 2007, 2008 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 |
87073
1577bd98c621
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
25 ;;; Commentary: |
29876 | 26 |
87073
1577bd98c621
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
27 ;;; Code: |
29876 | 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 ;;; User Variables: | |
38 | |
39 (defcustom eshell-script-load-hook '(eshell-script-initialize) | |
40 "*A list of functions to call when loading `eshell-script'." | |
41 :type 'hook | |
42 :group 'eshell-script) | |
43 | |
44 (defcustom eshell-login-script (concat eshell-directory-name "login") | |
45 "*If non-nil, a file to invoke when starting up Eshell interactively. | |
46 This file should be a file containing Eshell commands, where comment | |
47 lines begin with '#'." | |
48 :type 'file | |
49 :group 'eshell-script) | |
50 | |
51 (defcustom eshell-rc-script (concat eshell-directory-name "profile") | |
52 "*If non-nil, a file to invoke whenever Eshell is started. | |
53 This includes when running `eshell-command'." | |
54 :type 'file | |
55 :group 'eshell-script) | |
56 | |
57 ;;; Functions: | |
58 | |
59 (defun eshell-script-initialize () | |
60 "Initialize the script parsing code." | |
61 (make-local-variable 'eshell-interpreter-alist) | |
62 (setq eshell-interpreter-alist | |
63 (cons '((lambda (file) | |
64 (string= (file-name-nondirectory file) | |
65 "eshell")) . eshell/source) | |
66 eshell-interpreter-alist)) | |
33020 | 67 (make-local-variable 'eshell-complex-commands) |
68 (setq eshell-complex-commands | |
69 (append '("source" ".") eshell-complex-commands)) | |
29876 | 70 ;; these two variables are changed through usage, but we don't want |
71 ;; to ruin it for other modules | |
72 (let (eshell-inside-quote-regexp | |
73 eshell-outside-quote-regexp) | |
74 (and (not eshell-non-interactive-p) | |
75 eshell-login-script | |
76 (file-readable-p eshell-login-script) | |
77 (eshell-do-eval | |
78 (list 'eshell-commands | |
79 (catch 'eshell-replace-command | |
80 (eshell-source-file eshell-login-script))) t)) | |
81 (and eshell-rc-script | |
82 (file-readable-p eshell-rc-script) | |
83 (eshell-do-eval | |
84 (list 'eshell-commands | |
85 (catch 'eshell-replace-command | |
86 (eshell-source-file eshell-rc-script))) t)))) | |
87 | |
88 (defun eshell-source-file (file &optional args subcommand-p) | |
89 "Execute a series of Eshell commands in FILE, passing ARGS. | |
90 Comments begin with '#'." | |
91 (interactive "f") | |
92 (let ((orig (point)) | |
93 (here (point-max)) | |
94 (inhibit-point-motion-hooks t) | |
95 after-change-functions) | |
96 (goto-char (point-max)) | |
97 (insert-file-contents file) | |
98 (goto-char (point-max)) | |
99 (throw 'eshell-replace-command | |
100 (prog1 | |
101 (list 'let | |
102 (list (list 'eshell-command-name (list 'quote file)) | |
103 (list 'eshell-command-arguments | |
104 (list 'quote args))) | |
105 (let ((cmd (eshell-parse-command (cons here (point))))) | |
106 (if subcommand-p | |
107 (setq cmd (list 'eshell-as-subcommand cmd))) | |
108 cmd)) | |
109 (delete-region here (point)) | |
110 (goto-char orig))))) | |
111 | |
112 (defun eshell/source (&rest args) | |
113 "Source a file in a subshell environment." | |
114 (eshell-eval-using-options | |
115 "source" args | |
116 '((?h "help" nil nil "show this usage screen") | |
117 :show-usage | |
118 :usage "FILE [ARGS] | |
119 Invoke the Eshell commands in FILE in a subshell, binding ARGS to $1, | |
120 $2, etc.") | |
121 (eshell-source-file (car args) (cdr args) t))) | |
122 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
123 (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
|
124 |
29876 | 125 (defun eshell/. (&rest args) |
126 "Source a file in the current environment." | |
127 (eshell-eval-using-options | |
128 "." args | |
129 '((?h "help" nil nil "show this usage screen") | |
130 :show-usage | |
131 :usage "FILE [ARGS] | |
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)))) | |
135 | |
37661
6d7c89c79996
Set the property `eshell-no-numeric-conversions' on the following
John Wiegley <johnw@newartisans.com>
parents:
33020
diff
changeset
|
136 (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
|
137 |
87073
1577bd98c621
Require individual files if needed when compiling, rather than
Glenn Morris <rgm@gnu.org>
parents:
78220
diff
changeset
|
138 (provide 'em-script) |
29876 | 139 |
52401 | 140 ;;; arch-tag: a346439d-5ba8-4faf-ac2b-3aacfeaa4647 |
29876 | 141 ;;; em-script.el ends here |