diff options
| -rw-r--r-- | lisp/eshell/esh-cmd.el | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el index dceb061c8f4..04b54d9d791 100644 --- a/lisp/eshell/esh-cmd.el +++ b/lisp/eshell/esh-cmd.el | |||
| @@ -350,6 +350,36 @@ This only returns external (non-Lisp) processes." | |||
| 350 | 350 | ||
| 351 | (defvar eshell--sep-terms) | 351 | (defvar eshell--sep-terms) |
| 352 | 352 | ||
| 353 | (defmacro eshell-with-temp-command (command &rest body) | ||
| 354 | "Narrow the buffer to COMMAND and execute the forms in BODY. | ||
| 355 | COMMAND can either be a string, or a cons cell demarcating a | ||
| 356 | buffer region. If COMMAND is a string, temporarily insert it | ||
| 357 | into the buffer before narrowing. Point will be set to the | ||
| 358 | beginning of the narrowed region. | ||
| 359 | |||
| 360 | The value returned is the last form in BODY." | ||
| 361 | (declare (indent 1)) | ||
| 362 | `(let ((cmd ,command)) | ||
| 363 | (if (stringp cmd) | ||
| 364 | ;; Since parsing relies partly on buffer-local state | ||
| 365 | ;; (e.g. that of `eshell-parse-argument-hook'), we need to | ||
| 366 | ;; perform the parsing in the Eshell buffer. | ||
| 367 | (let ((begin (point)) end | ||
| 368 | (inhibit-point-motion-hooks t)) | ||
| 369 | (with-silent-modifications | ||
| 370 | (insert cmd) | ||
| 371 | (setq end (point)) | ||
| 372 | (unwind-protect | ||
| 373 | (save-restriction | ||
| 374 | (narrow-to-region begin end) | ||
| 375 | (goto-char begin) | ||
| 376 | ,@body) | ||
| 377 | (delete-region begin end)))) | ||
| 378 | (save-restriction | ||
| 379 | (narrow-to-region (car cmd) (cdr cmd)) | ||
| 380 | (goto-char (car cmd)) | ||
| 381 | ,@body)))) | ||
| 382 | |||
| 353 | (defun eshell-parse-command (command &optional args toplevel) | 383 | (defun eshell-parse-command (command &optional args toplevel) |
| 354 | "Parse the COMMAND, adding ARGS if given. | 384 | "Parse the COMMAND, adding ARGS if given. |
| 355 | COMMAND can either be a string, or a cons cell demarcating a buffer | 385 | COMMAND can either be a string, or a cons cell demarcating a buffer |
| @@ -361,15 +391,9 @@ hooks should be run before and after the command." | |||
| 361 | (append | 391 | (append |
| 362 | (if (consp command) | 392 | (if (consp command) |
| 363 | (eshell-parse-arguments (car command) (cdr command)) | 393 | (eshell-parse-arguments (car command) (cdr command)) |
| 364 | (let ((here (point)) | 394 | (eshell-with-temp-command command |
| 365 | (inhibit-point-motion-hooks t)) | 395 | (goto-char (point-max)) |
| 366 | (with-silent-modifications | 396 | (eshell-parse-arguments (point-min) (point-max)))) |
| 367 | ;; FIXME: Why not use a temporary buffer and avoid this | ||
| 368 | ;; "insert&delete" business? --Stef | ||
| 369 | (insert command) | ||
| 370 | (prog1 | ||
| 371 | (eshell-parse-arguments here (point)) | ||
| 372 | (delete-region here (point)))))) | ||
| 373 | args)) | 397 | args)) |
| 374 | (commands | 398 | (commands |
| 375 | (mapcar | 399 | (mapcar |