aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/eshell/esh-cmd.el
diff options
context:
space:
mode:
authorDmitry Gutov2022-08-15 02:22:59 +0300
committerDmitry Gutov2022-08-15 02:22:59 +0300
commitee3a674c7c9e39fe7ff296ce1f9830fc45520de8 (patch)
treee8ba1e7be54314f208454e80e3d31044c913f3eb /lisp/eshell/esh-cmd.el
parentfe0e53d963899a16e0dd1bbc1ba10a6b59f7989e (diff)
parent0a8e88fd83db5398d36064a7f87cff5b57da7284 (diff)
downloademacs-scratch/font_lock_large_files.tar.gz
emacs-scratch/font_lock_large_files.zip
Merge branch 'master' into scratch/font_lock_large_filesscratch/font_lock_large_files
Diffstat (limited to 'lisp/eshell/esh-cmd.el')
-rw-r--r--lisp/eshell/esh-cmd.el85
1 files changed, 48 insertions, 37 deletions
diff --git a/lisp/eshell/esh-cmd.el b/lisp/eshell/esh-cmd.el
index 775e4c1057e..62c95056fd2 100644
--- a/lisp/eshell/esh-cmd.el
+++ b/lisp/eshell/esh-cmd.el
@@ -133,6 +133,10 @@ There are several different kinds of commands, however."
133Such arguments will be passed to `read', and then evaluated." 133Such arguments will be passed to `read', and then evaluated."
134 :type 'regexp) 134 :type 'regexp)
135 135
136(defcustom eshell-lisp-form-nil-is-failure t
137 "If non-nil, Lisp forms like (COMMAND ARGS) treat a nil result as failure."
138 :type 'boolean)
139
136(defcustom eshell-pre-command-hook nil 140(defcustom eshell-pre-command-hook nil
137 "A hook run before each interactive command is invoked." 141 "A hook run before each interactive command is invoked."
138 :type 'hook) 142 :type 'hook)
@@ -541,9 +545,7 @@ implemented via rewriting, rather than as a function."
541 ,(eshell-invokify-arg body t))) 545 ,(eshell-invokify-arg body t)))
542 (setcar for-items (cadr for-items)) 546 (setcar for-items (cadr for-items))
543 (setcdr for-items (cddr for-items))) 547 (setcdr for-items (cddr for-items)))
544 (eshell-close-handles 548 (eshell-close-handles)))))
545 eshell-last-command-status
546 (list 'quote eshell-last-command-result))))))
547 549
548(defun eshell-structure-basic-command (func names keyword test body 550(defun eshell-structure-basic-command (func names keyword test body
549 &optional else) 551 &optional else)
@@ -551,10 +553,11 @@ implemented via rewriting, rather than as a function."
551The first of NAMES should be the positive form, and the second the 553The first of NAMES should be the positive form, and the second the
552negative. It's not likely that users should ever need to call this 554negative. It's not likely that users should ever need to call this
553function." 555function."
554 ;; If the test form begins with `eshell-convert', it means 556 ;; If the test form begins with `eshell-convert' or
555 ;; something data-wise will be returned, and we should let 557 ;; `eshell-escape-arg', it means something data-wise will be
556 ;; that determine the truth of the statement. 558 ;; returned, and we should let that determine the truth of the
557 (unless (eq (car test) 'eshell-convert) 559 ;; statement.
560 (unless (memq (car test) '(eshell-convert eshell-escape-arg))
558 (setq test 561 (setq test
559 `(progn ,test 562 `(progn ,test
560 (eshell-exit-success-p)))) 563 (eshell-exit-success-p))))
@@ -574,9 +577,7 @@ function."
574 `(let ((eshell-command-body '(nil)) 577 `(let ((eshell-command-body '(nil))
575 (eshell-test-body '(nil))) 578 (eshell-test-body '(nil)))
576 (,func ,test ,body ,else) 579 (,func ,test ,body ,else)
577 (eshell-close-handles 580 (eshell-close-handles)))
578 eshell-last-command-status
579 (list 'quote eshell-last-command-result))))
580 581
581(defun eshell-rewrite-while-command (terms) 582(defun eshell-rewrite-while-command (terms)
582 "Rewrite a `while' command into its equivalent Eshell command form. 583 "Rewrite a `while' command into its equivalent Eshell command form.
@@ -1415,43 +1416,53 @@ via `eshell-errorn'."
1415(defun eshell-lisp-command (object &optional args) 1416(defun eshell-lisp-command (object &optional args)
1416 "Insert Lisp OBJECT, using ARGS if a function." 1417 "Insert Lisp OBJECT, using ARGS if a function."
1417 (catch 'eshell-external ; deferred to an external command 1418 (catch 'eshell-external ; deferred to an external command
1419 (setq eshell-last-command-status 0
1420 eshell-last-arguments args)
1418 (let* ((eshell-ensure-newline-p (eshell-interactive-output-p)) 1421 (let* ((eshell-ensure-newline-p (eshell-interactive-output-p))
1422 (command-form-p (functionp object))
1419 (result 1423 (result
1420 (if (functionp object) 1424 (if command-form-p
1421 (progn 1425 (let ((numeric (not (get object
1422 (setq eshell-last-arguments args 1426 'eshell-no-numeric-conversions)))
1423 eshell-last-command-name 1427 (fname-args (get object 'eshell-filename-arguments)))
1428 (when (or numeric fname-args)
1429 (while args
1430 (let ((arg (car args)))
1431 (cond
1432 ((and numeric (stringp arg) (> (length arg) 0)
1433 (text-property-any 0 (length arg)
1434 'number t arg))
1435 ;; If any of the arguments are flagged as
1436 ;; numbers waiting for conversion, convert
1437 ;; them now.
1438 (setcar args (string-to-number arg)))
1439 ((and fname-args (stringp arg)
1440 (string-equal arg "~"))
1441 ;; If any of the arguments match "~",
1442 ;; prepend "./" to treat it as a regular
1443 ;; file name.
1444 (setcar args (concat "./" arg)))))
1445 (setq args (cdr args))))
1446 (setq eshell-last-command-name
1424 (concat "#<function " (symbol-name object) ">")) 1447 (concat "#<function " (symbol-name object) ">"))
1425 (let ((numeric (not (get object
1426 'eshell-no-numeric-conversions)))
1427 (fname-args (get object 'eshell-filename-arguments)))
1428 (when (or numeric fname-args)
1429 (while args
1430 (let ((arg (car args)))
1431 (cond ((and numeric (stringp arg) (> (length arg) 0)
1432 (text-property-any 0 (length arg)
1433 'number t arg))
1434 ;; If any of the arguments are
1435 ;; flagged as numbers waiting for
1436 ;; conversion, convert them now.
1437 (setcar args (string-to-number arg)))
1438 ((and fname-args (stringp arg)
1439 (string-equal arg "~"))
1440 ;; If any of the arguments match "~",
1441 ;; prepend "./" to treat it as a
1442 ;; regular file name.
1443 (setcar args (concat "./" arg)))))
1444 (setq args (cdr args)))))
1445 (eshell-apply object eshell-last-arguments)) 1448 (eshell-apply object eshell-last-arguments))
1446 (setq eshell-last-arguments args 1449 (setq eshell-last-command-name "#<Lisp object>")
1447 eshell-last-command-name "#<Lisp object>")
1448 (eshell-eval object)))) 1450 (eshell-eval object))))
1449 (if (and eshell-ensure-newline-p 1451 (if (and eshell-ensure-newline-p
1450 (save-excursion 1452 (save-excursion
1451 (goto-char eshell-last-output-end) 1453 (goto-char eshell-last-output-end)
1452 (not (bolp)))) 1454 (not (bolp))))
1453 (eshell-print "\n")) 1455 (eshell-print "\n"))
1454 (eshell-close-handles 0 (list 'quote result))))) 1456 (eshell-close-handles
1457 ;; If `eshell-lisp-form-nil-is-failure' is non-nil, Lisp forms
1458 ;; that succeeded but have a nil result should have an exit
1459 ;; status of 2.
1460 (when (and eshell-lisp-form-nil-is-failure
1461 (not command-form-p)
1462 (= eshell-last-command-status 0)
1463 (not result))
1464 2)
1465 (list 'quote result)))))
1455 1466
1456(defalias 'eshell-lisp-command* #'eshell-lisp-command) 1467(defalias 'eshell-lisp-command* #'eshell-lisp-command)
1457 1468