bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#28700: 25.2; Cannot kill Eshell buffer


From: Noam Postavsky
Subject: bug#28700: 25.2; Cannot kill Eshell buffer
Date: Sun, 15 Oct 2017 22:20:52 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.0.90 (gnu/linux)

tags 28700 = patch
quit

Live System User <nyc4bos@aol.com> writes:

>> Thanks, my guess is you have some string with a read-only property in
>> eshell history (probably introduced by copying from another buffer), and
>> this is tripping up eshell-write-history.
>>
>> Can you post the result of
>>
>>     M-x pp-eval-expression RET eshell-history-ring RET
>>
>> If my guess is correct there should be some strings of the form
>>
>>     #("some command" 0 11 (read-only t))
>
>       Yes.  So how do I deal wi'th?

>     #("~/" 0 1
>       (rear-nonsticky
>        (arg-begin arg-end)
>        read-only t arg-begin t)
>       1 2
>       (rear-nonsticky
>        (arg-end arg-begin)
>        read-only t arg-end t))

Ah, there we are.  I can't quite work out exactly how you managed to get
such a string, but stripping properties in eshell-write-history should
take care of it regardless.  If you evaluate the following defun in your
emacs session, it should be able to exit:

(defun eshell-write-history (&optional filename append)
  "Writes the buffer's `eshell-history-ring' to a history file.
The name of the file is given by the variable
`eshell-history-file-name'.  The original contents of the file are
lost if `eshell-history-ring' is not empty.  If
`eshell-history-file-name' is nil this function does nothing.

Useful within process sentinels.

See also `eshell-read-history'."
  (let ((file (or filename eshell-history-file-name)))
    (cond
     ((or (null file)
          (equal file "")
          (null eshell-history-ring)
          (ring-empty-p eshell-history-ring))
      nil)
     ((not (file-writable-p file))
      (message "Cannot write history file %s" file))
     (t
      (let* ((ring eshell-history-ring)
             (index (ring-length ring)))
        ;; Write it all out into a buffer first.  Much faster, but
        ;; messier, than writing it one line at a time.
        (with-temp-buffer
          (while (> index 0)
            (setq index (1- index))
            (let ((start (point)))
              ;; Remove properties before inserting, to avoid trouble
              ;; with read-only strings (Bug#28700).
              (insert (substring-no-properties (ring-ref ring index)) ?\n)
              (subst-char-in-region start (1- (point)) ?\n ?\177)))
          (eshell-with-private-file-modes
           (write-region (point-min) (point-max) file append
                         'no-message))))))))

Here's the corresponding patch:

>From ffaeb09ca6ef9b3d97c8b378c1e5c2b2723dae6f Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs@gmail.com>
Date: Sun, 15 Oct 2017 16:41:17 -0400
Subject: [PATCH] Ignore string properties when saving eshell history
 (Bug#28700)

* lisp/eshell/em-hist.el (eshell-write-history): Remove properties
before inserting history strings.
(eshell-read-history): Remove obsolete comment.
---
 lisp/eshell/em-hist.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/eshell/em-hist.el b/lisp/eshell/em-hist.el
index 1ab3c60b2c..8084c12653 100644
--- a/lisp/eshell/em-hist.el
+++ b/lisp/eshell/em-hist.el
@@ -444,7 +444,6 @@ eshell-read-history
             (ignore-dups eshell-hist-ignoredups))
        (with-temp-buffer
          (insert-file-contents file)
-         ;; Save restriction in case file is already visited...
          ;; Watch for those date stamps in history files!
          (goto-char (point-max))
          (while (and (< count size)
@@ -488,7 +487,9 @@ eshell-write-history
          (while (> index 0)
            (setq index (1- index))
            (let ((start (point)))
-             (insert (ring-ref ring index) ?\n)
+              ;; Remove properties before inserting, to avoid trouble
+              ;; with read-only strings (Bug#28700).
+              (insert (substring-no-properties (ring-ref ring index)) ?\n)
              (subst-char-in-region start (1- (point)) ?\n ?\177)))
          (eshell-with-private-file-modes
           (write-region (point-min) (point-max) file append
-- 
2.11.0


reply via email to

[Prev in Thread] Current Thread [Next in Thread]