Commit e37da5a4 authored by Samer Masterson's avatar Samer Masterson

eshell: Introduce new buffer syntax

The new buffer syntax '#<buffer-name>' is equivalent to '#<buffer
buffer-name>'.  Remove `eshell-buffer-shorthand', as it is no longer
needed (Bug#19319).

* lisp/eshell/esh-io.el (eshell-buffer-shorthand): Remove.
(eshell-get-target): Remove shorthand-specific code.
* lisp/eshell/esh-arg.el (eshell-parse-special-reference): Parse
'#<buffer-name>'.
parent b510a83e
......@@ -675,6 +675,12 @@ command line's password prompt.
*** The new built-in command `clear' can scroll window contents out of sight.
If provided with an optional non-nil argument, the scrollback contents will be cleared.
*** New buffer syntax '#<buffer-name>', which is equivalent to
'#<buffer buffer-name>'. This shorthand makes interacting with
buffers from eshell more convenient. Custom variable
`eshell-buffer-shorthand', which has been broken for a while, has been
removed.
** Browse-url
*** Support for the Conkeror web browser.
......
......@@ -357,22 +357,31 @@ after are both returned."
(goto-char (1+ end)))))))
(defun eshell-parse-special-reference ()
"Parse a special syntax reference, of the form '#<type arg>'."
(if (and (not eshell-current-argument)
(not eshell-current-quoted)
(looking-at "#<\\(buffer\\|process\\)\\s-"))
(let ((here (point)))
(goto-char (match-end 0))
(let* ((buffer-p (string= (match-string 1) "buffer"))
(end (eshell-find-delimiter ?\< ?\>)))
(if (not end)
(throw 'eshell-incomplete ?\<)
(if (eshell-arg-delimiter (1+ end))
(prog1
(list (if buffer-p 'get-buffer-create 'get-process)
(buffer-substring-no-properties (point) end))
(goto-char (1+ end)))
(ignore (goto-char here))))))))
"Parse a special syntax reference, of the form '#<args>'.
args := `type' `whitespace' `arbitrary-args' | `arbitrary-args'
type := \"buffer\" or \"process\"
arbitrary-args := any string of characters.
If the form has no 'type', the syntax is parsed as if 'type' were
\"buffer\"."
(when (and (not eshell-current-argument)
(not eshell-current-quoted)
(looking-at "#<\\(\\(buffer\\|process\\)\\s-\\)?"))
(let ((here (point)))
(goto-char (match-end 0)) ;; Go to the end of the match.
(let ((buffer-p (if (match-string 1)
(string= (match-string 2) "buffer")
t)) ;; buffer-p is non-nil by default.
(end (eshell-find-delimiter ?\< ?\>)))
(when (not end)
(throw 'eshell-incomplete ?\<))
(if (eshell-arg-delimiter (1+ end))
(prog1
(list (if buffer-p 'get-buffer-create 'get-process)
(buffer-substring-no-properties (point) end))
(goto-char (1+ end)))
(ignore (goto-char here)))))))
(defun eshell-parse-delimiter ()
"Parse an argument delimiter, which is essentially a command operator."
......
......@@ -31,6 +31,18 @@
;; consistent with most shells. Therefore, only unique features are
;; mentioned here.
;;
;;;_* Redirect to a Buffer or Process
;;
;; Buffers and processes can be named with '#<buffer buffer-name>' and
;; '#<process process-name>', respectively. As a shorthand,
;; '#<buffer-name>' without the explicit "buffer" arg is equivalent to
;; '#<buffer buffer-name>'.
;;
;; echo hello > #<buffer *scratch*> # Overwrite '*scratch*' with 'hello'.
;; echo hello > #<*scratch*> # Same as the command above.
;;
;; echo hello > #<process shell> # Pipe "hello" into the shell process.
;;
;;;_* Insertion
;;
;; To insert at the location of point in a buffer, use '>>>':
......@@ -98,19 +110,6 @@ other buffers) ."
:type 'integer
:group 'eshell-io)
(defcustom eshell-buffer-shorthand nil
"If non-nil, a symbol name can be used for a buffer in redirection.
If nil, redirecting to a buffer requires buffer name syntax. If this
variable is set, redirection directly to Lisp symbols will be
impossible.
Example:
echo hello > '*scratch* ; works if `eshell-buffer-shorthand' is t
echo hello > #<buffer *scratch*> ; always works"
:type 'boolean
:group 'eshell-io)
(defcustom eshell-print-queue-size 5
"The size of the print queue, for doing buffered printing.
This is basically a speed enhancement, to avoid blocking the Lisp code
......@@ -355,21 +354,14 @@ it defaults to `insert'."
(goto-char (point-max))))
(point-marker))))))
((or (bufferp target)
(and (boundp 'eshell-buffer-shorthand)
(symbol-value 'eshell-buffer-shorthand)
(symbolp target)
(not (memq target '(t nil)))))
(let ((buf (if (bufferp target)
target
(get-buffer-create
(symbol-name target)))))
(with-current-buffer buf
(cond ((eq mode 'overwrite)
(erase-buffer))
((eq mode 'append)
(goto-char (point-max))))
(point-marker))))
((bufferp target)
(with-current-buffer target
(cond ((eq mode 'overwrite)
(erase-buffer))
((eq mode 'append)
(goto-char (point-max))))
(point-marker)))
((functionp target) nil)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment