From f1297b82bee836ff50c8d7b922044157ba755752 Mon Sep 17 00:00:00 2001 From: Jim Porter Date: Sun, 8 Jan 2023 13:05:59 -0800 Subject: [PATCH 2/3] Make 'eshell-bol' obsolete Now that Eshell uses fields for its output, 'eshell-bol' is no longer needed, and we can just use 'beginning-of-line'. * lisp/eshell/esh-mode.el (eshell-bol): Mark obsolete. (eshell-mode-map): Remove 'C-a' mapping. (eshell-command-map): Use 'move-beginning-of-line'. (eshell-move-argument, eshell-kill-input): Use 'beginning-of-line'. (eshell-get-old-input): Remove unnecessary call to 'eshell-skip-prompt-function'. * lisp/eshell/em-rebind.el (eshell-rebind-keys-alist): Remove 'C-a' and '' mappings; the global mapping for these ('move-beginning-of-line') does the same thing now. * lisp/eshell/em-cmpl.el (eshell-complete-parse-arguments): * lisp/eshell/em-elecslash.el (eshell-electric-forward-slash): * lisp/eshell/em-hist.el (eshell-hist-word-reference) (eshell-previous-matching-input-from-input, eshell-test-imatch): * lisp/eshell/em-prompt.el (eshell-backward-matching-input): * lisp/eshell/em-rebind.el (eshell-point-within-input-p): * test/lisp/eshell/eshell-tests.el (eshell-test/forward-arg): Use 'beginning-of-line'. * test/lisp/eshell/eshell-tests.el (eshell-test/run-old-command): Rename to... (eshell-test/get-old-input): ... this, and expand the test. --- lisp/eshell/em-cmpl.el | 2 +- lisp/eshell/em-elecslash.el | 2 +- lisp/eshell/em-hist.el | 6 +++--- lisp/eshell/em-prompt.el | 2 +- lisp/eshell/em-rebind.el | 6 ++---- lisp/eshell/esh-mode.el | 31 +++++++++++++------------------ test/lisp/eshell/eshell-tests.el | 15 ++++++++++----- 7 files changed, 31 insertions(+), 33 deletions(-) diff --git a/lisp/eshell/em-cmpl.el b/lisp/eshell/em-cmpl.el index 94ec5e8f1db..4206ad048fa 100644 --- a/lisp/eshell/em-cmpl.el +++ b/lisp/eshell/em-cmpl.el @@ -312,7 +312,7 @@ eshell-complete-parse-arguments (eshell-interactive-process-p)) (eshell--pcomplete-insert-tab)) (let ((end (point-marker)) - (begin (save-excursion (eshell-bol) (point))) + (begin (save-excursion (beginning-of-line) (point))) (posns (list t)) args delim) (when (and pcomplete-allow-modifications diff --git a/lisp/eshell/em-elecslash.el b/lisp/eshell/em-elecslash.el index 80bc0f031ef..2b003f58dc7 100644 --- a/lisp/eshell/em-elecslash.el +++ b/lisp/eshell/em-elecslash.el @@ -72,7 +72,7 @@ eshell-electric-forward-slash (delete-char -1) (let ((tilde-before (eq ?~ (char-before))) (command (save-excursion - (eshell-bol) + (beginning-of-line) (skip-syntax-forward " ") (thing-at-point 'sexp))) (prefix (file-remote-p default-directory))) diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el index 05e9598f530..6e0e471d910 100644 --- a/lisp/eshell/em-hist.el +++ b/lisp/eshell/em-hist.el @@ -555,7 +555,7 @@ eshell-hist-word-reference (defun eshell-hist-parse-arguments (&optional b e) "Parse current command arguments in a history-code-friendly way." (let ((end (or e (point))) - (begin (or b (save-excursion (eshell-bol) (point)))) + (begin (or b (save-excursion (beginning-of-line) (point)))) (posb (list t)) (pose (list t)) (textargs (list t)) @@ -913,7 +913,7 @@ eshell-previous-matching-input-from-input eshell-next-matching-input-from-input))) ;; Starting a new search (setq eshell-matching-input-from-input-string - (buffer-substring (save-excursion (eshell-bol) (point)) + (buffer-substring (save-excursion (beginning-of-line) (point)) (point)) eshell-history-index nil)) (eshell-previous-matching-input @@ -933,7 +933,7 @@ eshell-test-imatch (if (get-text-property (point) 'history) (progn (beginning-of-line) t) (let ((before (point))) - (eshell-bol) + (beginning-of-line) (if (and (not (bolp)) (<= (point) before)) t diff --git a/lisp/eshell/em-prompt.el b/lisp/eshell/em-prompt.el index 866a21540d1..9fad36a3d5e 100644 --- a/lisp/eshell/em-prompt.el +++ b/lisp/eshell/em-prompt.el @@ -163,7 +163,7 @@ eshell-backward-matching-input (progn (message "Not found") (ding)) (goto-char pos) - (eshell-bol)))) + (beginning-of-line)))) (defun eshell-forward-matching-input (regexp arg) "Search forward through buffer for match for REGEXP. diff --git a/lisp/eshell/em-rebind.el b/lisp/eshell/em-rebind.el index 2c95d4fdffb..f147d432300 100644 --- a/lisp/eshell/em-rebind.el +++ b/lisp/eshell/em-rebind.el @@ -50,9 +50,7 @@ eshell-rebind-load-hook :group 'eshell-rebind) (defcustom eshell-rebind-keys-alist - '(([(control ?a)] . eshell-bol) - ([home] . eshell-bol) - ([(control ?d)] . eshell-delchar-or-maybe-eof) + '(([(control ?d)] . eshell-delchar-or-maybe-eof) ([backspace] . eshell-delete-backward-char) ([delete] . eshell-delete-backward-char) ([(control ?w)] . backward-kill-word) @@ -190,7 +188,7 @@ eshell-point-within-input-p (and eshell-remap-previous-input (setq begin (save-excursion - (eshell-bol) + (beginning-of-line) (and (not (bolp)) (point)))) (>= pos begin) (<= pos (line-end-position)) diff --git a/lisp/eshell/esh-mode.el b/lisp/eshell/esh-mode.el index 97edc826c9a..90e003d188b 100644 --- a/lisp/eshell/esh-mode.el +++ b/lisp/eshell/esh-mode.el @@ -262,14 +262,13 @@ eshell-mode-map "C-c" 'eshell-command-map "RET" #'eshell-send-input "M-RET" #'eshell-queue-input - "C-M-l" #'eshell-show-output - "C-a" #'eshell-bol) + "C-M-l" #'eshell-show-output) (defvar-keymap eshell-command-map :prefix 'eshell-command-map "M-o" #'eshell-mark-output "M-d" #'eshell-toggle-direct-send - "C-a" #'eshell-bol + "C-a" #'move-beginning-of-line "C-b" #'eshell-backward-argument "C-e" #'eshell-show-maximum-output "C-f" #'eshell-forward-argument @@ -472,7 +471,7 @@ eshell-find-tag (defun eshell-move-argument (limit func property arg) "Move forward ARG arguments." (catch 'eshell-incomplete - (eshell-parse-arguments (save-excursion (eshell-bol) (point)) + (eshell-parse-arguments (save-excursion (beginning-of-line) (point)) (line-end-position))) (let ((pos (save-excursion (funcall func 1) @@ -505,12 +504,7 @@ eshell-repeat-argument (kill-ring-save begin (point)) (yank))) -(defun eshell-bol () - "Go to the beginning of line, then skip past the prompt, if any." - (interactive) - (beginning-of-line) - (and eshell-skip-prompt-function - (funcall eshell-skip-prompt-function))) +(define-obsolete-function-alias 'eshell-bol #'beginning-of-line "30.1") (defsubst eshell-push-command-mark () "Push a mark at the end of the last input text." @@ -856,7 +850,7 @@ eshell-kill-input (if (> (point) eshell-last-output-end) (kill-region eshell-last-output-end (point)) (let ((here (point))) - (eshell-bol) + (beginning-of-line) (kill-region (point) here)))) (defun eshell-show-maximum-output (&optional interactive) @@ -884,17 +878,18 @@ eshell/clear-scrollback (erase-buffer))) (defun eshell-get-old-input (&optional use-current-region) - "Return the command input on the current line." + "Return the command input on the current line. +If USE-CURRENT-REGION is non-nil, return the current region." (if use-current-region (buffer-substring (min (point) (mark)) (max (point) (mark))) (save-excursion - (beginning-of-line) - (and eshell-skip-prompt-function - (funcall eshell-skip-prompt-function)) - (let ((beg (point))) - (end-of-line) - (buffer-substring beg (point)))))) + (let ((inhibit-field-text-motion t)) + (end-of-line)) + (let ((inhibit-field-text-motion) + (end (point))) + (beginning-of-line) + (buffer-substring (point) end))))) (defun eshell-copy-old-input () "Insert after prompt old input at point as new input to be edited." diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el index be968e1558f..0b0e0701cb4 100644 --- a/test/lisp/eshell/eshell-tests.el +++ b/test/lisp/eshell/eshell-tests.el @@ -117,14 +117,14 @@ eshell-test/forward-arg (with-temp-eshell (eshell-insert-command "echo $(+ 1 (- 4 3)) \"alpha beta\" file" 'ignore) (let ((here (point)) begin valid) - (eshell-bol) + (beginning-of-line) (setq begin (point)) (eshell-forward-argument 4) (setq valid (= here (point))) (eshell-backward-argument 4) (prog1 (and valid (= begin (point))) - (eshell-bol) + (beginning-of-line) (delete-region (point) (point-max)))))) (ert-deftest eshell-test/queue-input () @@ -148,12 +148,17 @@ eshell-test/flush-output (should (eshell-match-output (concat "^" (regexp-quote "*** output flushed ***\n") "$"))))) -(ert-deftest eshell-test/run-old-command () - "Re-run an old command" +(ert-deftest eshell-test/get-old-input () + "Test that we can get the input of a previous command." (with-temp-eshell (eshell-insert-command "echo alpha") (goto-char eshell-last-input-start) - (string= (eshell-get-old-input) "echo alpha"))) + (should (string= (eshell-get-old-input) "echo alpha")) + ;; Make sure that `eshell-get-old-input' works even if the point is + ;; inside the prompt. + (let ((inhibit-field-text-motion t)) + (beginning-of-line)) + (should (string= (eshell-get-old-input) "echo alpha"))))) (provide 'eshell-tests) -- 2.25.1