summaryrefslogtreecommitdiff
path: root/eshell-conf.el
diff options
context:
space:
mode:
authorJSDurand <mmemmew@gmail.com>2026-05-06 23:50:53 +0800
committerJSDurand <mmemmew@gmail.com>2026-05-06 23:50:53 +0800
commitef6b5c2f6f1a54ad3af5c32c0e6ab2e269173646 (patch)
treee300e60f62fdd031567102acf6560ab119b145e5 /eshell-conf.el
parentc5ec16b6ef88248213ce1438ac78ffea28b90a9e (diff)
eshell: adapt to emacs 30
* eshell-conf.el (durand-eshell-emit-prompt): Adapt to the next prompt-emitting function. This caused my Eshell to be unusable for a while, until I realized it was my function laggin behind the new Eshell function. (eshell-clear): This function deletes the region between the buffer start and a specific line beginning. Since Eshell starts to use fields, we have to take fields into consideration (or to stop taking them into consideration) to know the true position of the beginning of lines then.
Diffstat (limited to 'eshell-conf.el')
-rw-r--r--eshell-conf.el92
1 files changed, 71 insertions, 21 deletions
diff --git a/eshell-conf.el b/eshell-conf.el
index c8c2605..216b003 100644
--- a/eshell-conf.el
+++ b/eshell-conf.el
@@ -95,6 +95,7 @@
(remove-hook 'eshell-post-command-hook #'eshell-current-command-stop t)
(remove-hook 'eshell-mode-hook #'eshell-current-command-time-track))
+;; This is for GNU Emacs 30.2.50 of 2026-05-05
;;;###autoload
(defun durand-eshell-emit-prompt ()
"Emit a prompt if eshell is being used interactively.
@@ -105,29 +106,75 @@ Add a time information at the beginning. -- Modified by Durand."
(if (not eshell-prompt-function)
(set-marker eshell-last-output-end (point))
(let ((prompt (funcall eshell-prompt-function)))
- (and eshell-highlight-prompt
- (add-text-properties 0 (length prompt)
- '(read-only t
- font-lock-face eshell-prompt
- front-sticky (font-lock-face read-only)
- rear-nonsticky (font-lock-face read-only))
- prompt))
- (eshell-interactive-print
- (mapconcat #'identity
- (delq
- nil
- (list
- (cond ((> (length eshell-prompt-time-string) 0)
- (propertize eshell-prompt-time-string
- 'font-lock-face 'modus-themes-heading-1
- 'read-only t
- 'front-sticky '(font-lock-face read-only)
- 'rear-nonsticky '(font-lock-face read-only))) )
- prompt))
- " "))
+ (add-text-properties
+ 0 (length prompt)
+ (if eshell-highlight-prompt
+ '( read-only t
+ field prompt
+ font-lock-face eshell-prompt
+ front-sticky (read-only field font-lock-face)
+ rear-nonsticky (read-only field font-lock-face))
+ '( field prompt
+ front-sticky (field)
+ rear-nonsticky (field)))
+ prompt)
+ (eshell-interactive-filter
+ nil
+ (cond
+ ((not (string-empty-p eshell-prompt-time-string))
+ (concat
+ (cond
+ (eshell-highlight-prompt
+ (propertize
+ (concat eshell-prompt-time-string (string 32))
+ 'read-only t
+ 'field 'prompt
+ 'font-lock-face 'modus-themes-heading-1
+ 'front-sticky '(read-only field font-lock-face)
+ 'rear-nonsticky '(read-only field font-lock-face)))
+ ((propertize
+ (concat eshell-prompt-time-string (string 32))
+ 'field 'prompt
+ 'front-sticky '(field)
+ 'rear-nonsticky '(field))))
+ prompt))
+ (prompt)))
(setq eshell-prompt-time-string "")))
(run-hooks 'eshell-after-prompt-hook))
+;; For Emacs 29
+;; (defun durand-eshell-emit-prompt ()
+;; "Emit a prompt if eshell is being used interactively.
+;; Modified by Durand."
+;; (when (boundp 'ansi-color-context-region)
+;; (setq ansi-color-context-region nil))
+;; (run-hooks 'eshell-before-prompt-hook)
+;; (if (not eshell-prompt-function)
+;; (set-marker eshell-last-output-end (point))
+;; (let ((prompt (funcall eshell-prompt-function)))
+;; (and eshell-highlight-prompt
+;; (add-text-properties 0 (length prompt)
+;; '(read-only t
+;; font-lock-face eshell-prompt
+;; front-sticky (font-lock-face read-only)
+;; rear-nonsticky (font-lock-face read-only))
+;; prompt))
+;; (setq
+;; prompt
+;; (cond
+;; ((not (string-empty-p eshell-prompt-time-string))
+;; (concat
+;; (propertize
+;; (concat eshell-prompt-time-string (string 32))
+;; 'read-only t
+;; 'font-lock-face 'modus-themes-heading-1
+;; 'front-sticky '(font-lock-face read-only)
+;; 'rear-nonsticky '(font-lock-face read-only))
+;; prompt))
+;; (prompt)))
+;; (eshell-interactive-print prompt)))
+;; (run-hooks 'eshell-after-prompt-hook))
+
(advice-add #'eshell-emit-prompt :override #'durand-eshell-emit-prompt)
;;; Eshell sets the keymap in the major mode function
@@ -179,7 +226,10 @@ Do NUM times `eshell-previous-prompt' before deleting."
(interactive
(list (cond ((null current-prefix-arg) 0)
((prefix-numeric-value current-prefix-arg)))))
- (let ((inhibit-read-only t))
+ ;; We have to set this to obtain the true line-beginning position,
+ ;; instead of the prompt start position.
+ (let ((inhibit-field-text-motion t)
+ (inhibit-read-only t))
(delete-region
(point-min)
(save-excursion