GNU bug report logs - #28700
25.2; Cannot kill Eshell buffer

Previous Next

Package: emacs;

Reported by: Live System User <nyc4bos <at> aol.com>

Date: Wed, 4 Oct 2017 09:58:01 UTC

Severity: minor

Tags: fixed, patch

Merged with 29153

Found in versions 25.2, 25.3

Fixed in version 26.1

Done: Noam Postavsky <npostavs <at> users.sourceforge.net>

Bug is archived. No further changes may be made.

Full log


Message #60 received at control <at> debbugs.gnu.org (full text, mbox):

From: Noam Postavsky <npostavs <at> users.sourceforge.net>
To: Live System User <nyc4bos <at> aol.com>
Cc: 28700 <at> debbugs.gnu.org
Subject: Re: bug#28700: 25.2; Cannot kill Eshell buffer
Date: Sun, 15 Oct 2017 22:20:52 -0400
[Message part 1 (text/plain, inline)]
tags 28700 = patch
quit

Live System User <nyc4bos <at> 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:

[0001-Ignore-string-properties-when-saving-eshell-history-.patch (text/x-diff, inline)]
From ffaeb09ca6ef9b3d97c8b378c1e5c2b2723dae6f Mon Sep 17 00:00:00 2001
From: Noam Postavsky <npostavs <at> 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


This bug report was last modified 7 years and 204 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.