annotate lisp/eshell/esh-arg.el @ 30853:5c3610702605

(desktop-save): Don't look at symbol-value of a member of minor-mode-alist, unless it is boundp.
author Eli Zaretskii <eliz@gnu.org>
date Wed, 16 Aug 2000 18:18:08 +0000
parents 34b1ab9d583d
children aab90b31807c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
1 ;;; esh-arg --- argument processing
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
2
29934
34b1ab9d583d Change spelling of the Free Software Foundation.
Gerd Moellmann <gerd@gnu.org>
parents: 29876
diff changeset
3 ;; Copyright (C) 1999, 2000 Free Software Foundation
29876
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
4
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
5 ;; This file is part of GNU Emacs.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
6
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
8 ;; it under the terms of the GNU General Public License as published by
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
9 ;; the Free Software Foundation; either version 2, or (at your option)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
10 ;; any later version.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
11
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
12 ;; GNU Emacs is distributed in the hope that it will be useful,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
15 ;; GNU General Public License for more details.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
16
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
17 ;; You should have received a copy of the GNU General Public License
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
20 ;; Boston, MA 02111-1307, USA.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
21
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
22 (provide 'esh-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
23
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
24 (eval-when-compile (require 'esh-maint))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
25
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
26 (defgroup eshell-arg nil
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
27 "Argument parsing involves transforming the arguments passed on the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
28 command line into equivalent Lisp forms that, when evaluated, will
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
29 yield the values intended."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
30 :tag "Argument parsing"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
31 :group 'eshell)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
32
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
33 ;;; Commentary:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
34
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
35 ;; Parsing of arguments can be extended by adding functions to the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
36 ;; hook `eshell-parse-argument-hook'. For a good example of this, see
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
37 ;; `eshell-parse-drive-letter', defined in eshell-dirs.el.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
38
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
39 (defcustom eshell-parse-argument-hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
40 (list
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
41 ;; a term such as #<buffer NAME>, or #<process NAME> is a buffer
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
42 ;; or process reference
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
43 'eshell-parse-special-reference
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
44
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
45 ;; numbers convert to numbers if they stand alone
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
46 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
47 (lambda ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
48 (when (and (not eshell-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
49 (not eshell-current-quoted)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
50 (looking-at eshell-number-regexp)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
51 (eshell-arg-delimiter (match-end 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
52 (goto-char (match-end 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
53 (string-to-number (match-string 0)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
54
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
55 ;; parse any non-special characters, based on the current context
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
56 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
57 (lambda ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
58 (unless eshell-inside-quote-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
59 (setq eshell-inside-quote-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
60 (format "[^%s]+"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
61 (apply 'string eshell-special-chars-inside-quoting))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
62 (unless eshell-outside-quote-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
63 (setq eshell-outside-quote-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
64 (format "[^%s]+"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
65 (apply 'string eshell-special-chars-outside-quoting))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
66 (when (looking-at (if eshell-current-quoted
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
67 eshell-inside-quote-regexp
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
68 eshell-outside-quote-regexp))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
69 (goto-char (match-end 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
70 (let ((str (match-string 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
71 (if str
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
72 (set-text-properties 0 (length str) nil str))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
73 str))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
74
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
75 ;; whitespace or a comment is an argument delimiter
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
76 (function
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
77 (lambda ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
78 (let (comment-p)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
79 (when (or (looking-at "[ \t]+")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
80 (and (not eshell-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
81 (looking-at "#\\([^<'].*\\|$\\)")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
82 (setq comment-p t)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
83 (if comment-p
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
84 (add-text-properties (match-beginning 0) (match-end 0)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
85 '(comment t)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
86 (goto-char (match-end 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
87 (eshell-finish-arg)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
88
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
89 ;; backslash before a special character means escape it
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
90 'eshell-parse-backslash
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
91
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
92 ;; text beginning with ' is a literally quoted
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
93 'eshell-parse-literal-quote
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
94
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
95 ;; text beginning with " is interpolably quoted
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
96 'eshell-parse-double-quote
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
97
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
98 ;; argument delimiter
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
99 'eshell-parse-delimiter)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
100 "*Define how to process Eshell command line arguments.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
101 When each function on this hook is called, point will be at the
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
102 current position within the argument list. The function should either
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
103 return nil, meaning that it did no argument parsing, or it should
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
104 return the result of the parse as a sexp. It is also responsible for
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
105 moving the point forward to reflect the amount of input text that was
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
106 parsed.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
107
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
108 If no function handles the current character at point, it will be
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
109 treated as a literal character."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
110 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
111 :group 'eshell-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
112
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
113 ;;; Code:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
114
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
115 ;;; User Variables:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
116
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
117 (defcustom eshell-arg-load-hook '(eshell-arg-initialize)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
118 "*A hook that gets run when `eshell-arg' is loaded."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
119 :type 'hook
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
120 :group 'eshell-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
121
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
122 (defcustom eshell-delimiter-argument-list '(?\; ?& ?\| ?\> ? ?\t ?\n)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
123 "List of characters to recognize as argument separators."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
124 :type '(repeat character)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
125 :group 'eshell-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
126
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
127 (defcustom eshell-special-chars-inside-quoting '(?\\ ?\")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
128 "*Characters which are still special inside double quotes."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
129 :type '(repeat character)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
130 :group 'eshell-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
131
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
132 (defcustom eshell-special-chars-outside-quoting
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
133 (append eshell-delimiter-argument-list '(?# ?! ?\\ ?\" ?\'))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
134 "*Characters that require escaping outside of double quotes.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
135 Without escaping them, they will introduce a change in the argument."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
136 :type '(repeat character)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
137 :group 'eshell-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
138
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
139 ;;; Internal Variables:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
140
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
141 (defvar eshell-current-argument nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
142 (defvar eshell-current-modifiers nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
143 (defvar eshell-arg-listified nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
144 (defvar eshell-nested-argument nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
145 (defvar eshell-current-quoted nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
146 (defvar eshell-inside-quote-regexp nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
147 (defvar eshell-outside-quote-regexp nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
148
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
149 ;;; Functions:
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
150
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
151 (defun eshell-arg-initialize ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
152 "Initialize the argument parsing code."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
153 (define-key eshell-command-map [(meta ?b)] 'eshell-insert-buffer-name)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
154 (set (make-local-variable 'eshell-inside-quote-regexp) nil)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
155 (set (make-local-variable 'eshell-outside-quote-regexp) nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
156
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
157 (defun eshell-insert-buffer-name (buffer-name)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
158 "Insert BUFFER-NAME into the current buffer at point."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
159 (interactive "BName of buffer: ")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
160 (insert-and-inherit "#<buffer " buffer-name ">"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
161
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
162 (defsubst eshell-escape-arg (string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
163 "Return STRING with the `escaped' property on it."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
164 (if (stringp string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
165 (add-text-properties 0 (length string) '(escaped t) string))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
166 string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
167
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
168 (defun eshell-resolve-current-argument ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
169 "If there are pending modifications to be made, make them now."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
170 (when eshell-current-argument
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
171 (when eshell-arg-listified
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
172 (let ((parts eshell-current-argument))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
173 (while parts
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
174 (unless (stringp (car parts))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
175 (setcar parts
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
176 (list 'eshell-to-flat-string (car parts))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
177 (setq parts (cdr parts)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
178 (setq eshell-current-argument
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
179 (list 'eshell-convert
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
180 (append (list 'concat) eshell-current-argument))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
181 (setq eshell-arg-listified nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
182 (while eshell-current-modifiers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
183 (setq eshell-current-argument
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
184 (list (car eshell-current-modifiers) eshell-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
185 eshell-current-modifiers (cdr eshell-current-modifiers))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
186 (setq eshell-current-modifiers nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
187
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
188 (defun eshell-finish-arg (&optional argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
189 "Finish the current argument being processed."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
190 (if argument
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
191 (setq eshell-current-argument argument))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
192 (throw 'eshell-arg-done t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
193
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
194 (defsubst eshell-arg-delimiter (&optional pos)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
195 "Return non-nil if POS is an argument delimiter.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
196 If POS is nil, the location of point is checked."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
197 (let ((pos (or pos (point))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
198 (or (= pos (point-max))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
199 (memq (char-after pos) eshell-delimiter-argument-list))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
200
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
201 ;; Argument parsing
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
202
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
203 (defun eshell-parse-arguments (beg end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
204 "Parse all of the arguments at point from BEG to END.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
205 Returns the list of arguments in their raw form.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
206 Point is left at the end of the arguments."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
207 (save-excursion
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
208 (save-restriction
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
209 (goto-char beg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
210 (narrow-to-region beg end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
211 (let ((inhibit-point-motion-hooks t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
212 (args (list t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
213 after-change-functions
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
214 delim)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
215 (remove-text-properties (point-min) (point-max)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
216 '(arg-begin nil arg-end nil))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
217 (if (setq
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
218 delim
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
219 (catch 'eshell-incomplete
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
220 (while (not (eobp))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
221 (let* ((here (point))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
222 (arg (eshell-parse-argument)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
223 (if (= (point) here)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
224 (error "Failed to parse argument '%s'"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
225 (buffer-substring here (point-max))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
226 (and arg (nconc args (list arg)))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
227 (if (listp delim)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
228 (throw 'eshell-incomplete delim)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
229 (throw 'eshell-incomplete
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
230 (list delim (point) (cdr args)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
231 (cdr args)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
232
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
233 (defun eshell-parse-argument ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
234 "Get the next argument. Leave point after it."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
235 (let* ((outer (null eshell-nested-argument))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
236 (arg-begin (and outer (point)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
237 (eshell-nested-argument t)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
238 eshell-current-argument
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
239 eshell-current-modifiers
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
240 eshell-arg-listified)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
241 (catch 'eshell-arg-done
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
242 (while (not (eobp))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
243 (let ((result
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
244 (or (run-hook-with-args-until-success
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
245 'eshell-parse-argument-hook)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
246 (prog1
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
247 (char-to-string (char-after))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
248 (forward-char)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
249 (if (not eshell-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
250 (setq eshell-current-argument result)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
251 (unless eshell-arg-listified
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
252 (setq eshell-current-argument
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
253 (list eshell-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
254 eshell-arg-listified t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
255 (nconc eshell-current-argument (list result))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
256 (when (and outer eshell-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
257 (add-text-properties arg-begin (1+ arg-begin)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
258 '(arg-begin t rear-nonsticky
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
259 (arg-begin arg-end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
260 (add-text-properties (1- (point)) (point)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
261 '(arg-end t rear-nonsticky
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
262 (arg-end arg-begin))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
263 (eshell-resolve-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
264 eshell-current-argument))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
265
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
266 (defsubst eshell-operator (&rest args)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
267 "A stub function that generates an error if a floating operator is found."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
268 (error "Unhandled operator in input text"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
269
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
270 (defsubst eshell-looking-at-backslash-return (pos)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
271 "Test whether a backslash-return sequence occurs at POS."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
272 (and (eq (char-after pos) ?\\)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
273 (or (= (1+ pos) (point-max))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
274 (and (eq (char-after (1+ pos)) ?\n)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
275 (= (+ pos 2) (point-max))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
276
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
277 (defun eshell-quote-backslash (string &optional index)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
278 "Intelligently backslash the character occuring in STRING at INDEX.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
279 If the character is itself a backslash, it needs no escaping."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
280 (let ((char (aref string index)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
281 (if (eq char ?\\)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
282 (char-to-string char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
283 (if (memq char eshell-special-chars-outside-quoting)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
284 (string ?\\ char)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
285
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
286 (defun eshell-parse-backslash ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
287 "Parse a single backslash (\) character, which might mean escape.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
288 It only means escape if the character immediately following is a
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
289 special character that is not itself a backslash."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
290 (when (eq (char-after) ?\\)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
291 (if (eshell-looking-at-backslash-return (point))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
292 (throw 'eshell-incomplete ?\\)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
293 (if (and (not (eq (char-after (1+ (point))) ?\\))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
294 (if eshell-current-quoted
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
295 (memq (char-after (1+ (point)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
296 eshell-special-chars-inside-quoting)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
297 (memq (char-after (1+ (point)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
298 eshell-special-chars-outside-quoting)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
299 (progn
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
300 (forward-char 2)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
301 (list 'eshell-escape-arg
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
302 (char-to-string (char-before))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
303 ;; allow \\<RET> to mean a literal "\" character followed by a
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
304 ;; normal return, rather than a backslash followed by a line
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
305 ;; continuator (i.e., "\\ + \n" rather than "\ + \\n"). This
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
306 ;; is necessary because backslashes in Eshell are not special
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
307 ;; unless they either precede something special, or precede a
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
308 ;; backslash that precedes something special. (Mainly this is
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
309 ;; done to make using backslash on Windows systems more
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
310 ;; natural-feeling).
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
311 (if (eshell-looking-at-backslash-return (1+ (point)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
312 (forward-char))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
313 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
314 "\\"))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
315
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
316 (defun eshell-parse-literal-quote ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
317 "Parse a literally quoted string. Nothing has special meaning!"
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
318 (if (eq (char-after) ?\')
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
319 (let ((end (eshell-find-delimiter ?\' ?\')))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
320 (if (not end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
321 (throw 'eshell-incomplete ?\')
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
322 (let ((string (buffer-substring-no-properties (1+ (point)) end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
323 (goto-char (1+ end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
324 (while (string-match "''" string)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
325 (setq string (replace-match "'" t t string)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
326 (list 'eshell-escape-arg string))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
327
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
328 (defun eshell-parse-double-quote ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
329 "Parse a double quoted string, which allows for variable interpolation."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
330 (when (eq (char-after) ?\")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
331 (forward-char)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
332 (let* ((end (eshell-find-delimiter ?\" ?\" nil nil t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
333 (eshell-current-quoted t))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
334 (if (not end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
335 (throw 'eshell-incomplete ?\")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
336 (prog1
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
337 (save-restriction
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
338 (narrow-to-region (point) end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
339 (list 'eshell-escape-arg
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
340 (eshell-parse-argument)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
341 (goto-char (1+ end)))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
342
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
343 (defun eshell-parse-special-reference ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
344 "Parse a special syntax reference, of the form '#<type arg>'."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
345 (if (and (not eshell-current-argument)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
346 (not eshell-current-quoted)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
347 (looking-at "#<\\(buffer\\|process\\)\\s-"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
348 (let ((here (point)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
349 (goto-char (match-end 0))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
350 (let* ((buffer-p (string= (match-string 1) "buffer"))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
351 (end (eshell-find-delimiter ?\< ?\>)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
352 (if (not end)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
353 (throw 'eshell-incomplete ?\<)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
354 (if (eshell-arg-delimiter (1+ end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
355 (prog1
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
356 (list (if buffer-p 'get-buffer-create 'get-process)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
357 (buffer-substring-no-properties (point) end))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
358 (goto-char (1+ end)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
359 (ignore (goto-char here))))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
360
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
361 (defun eshell-parse-delimiter ()
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
362 "Parse an argument delimiter, which is essentially a command operator."
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
363 ;; this `eshell-operator' keyword gets parsed out by
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
364 ;; `eshell-separate-commands'. Right now the only possibility for
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
365 ;; error is an incorrect output redirection specifier.
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
366 (when (looking-at "[&|;\n]\\s-*")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
367 (let ((end (match-end 0)))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
368 (if eshell-current-argument
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
369 (eshell-finish-arg)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
370 (eshell-finish-arg
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
371 (prog1
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
372 (list 'eshell-operator
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
373 (cond
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
374 ((eq (char-after end) ?\&)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
375 (setq end (1+ end)) "&&")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
376 ((eq (char-after end) ?\|)
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
377 (setq end (1+ end)) "||")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
378 ((eq (char-after) ?\n) ";")
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
379 (t
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
380 (char-to-string (char-after)))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
381 (goto-char end)))))))
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
382
edfec1c0d511 *** empty log message ***
Gerd Moellmann <gerd@gnu.org>
parents:
diff changeset
383 ;;; esh-arg.el ends here