From: Samer Masterson <samer@samertm.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 18108@debbugs.gnu.org
Subject: bug#18108: [PATCH] 24.3.92 : eshell-visual-options fails with some output.
Date: Mon, 04 May 2015 05:57:45 -0700 [thread overview]
Message-ID: <87mw1ksdo6.fsf@f-box.i-did-not-set--mail-host-address--so-tickle-me> (raw)
In-Reply-To: <jwv8ud56t1a.fsf-monnier+emacsbugs@gnu.org>
Stefan Monnier <monnier@iro.umontreal.ca> writes:
> No doubt. I think the best way to try and make it work well in "both"
> cases is to try and make the behavior closer to what would happen inside
> an xterm (say). E.g. one possibility is that when the process dies,
> rather than simply deleting the corresponding term buffer, we first copy
> the term buffer's contents to the Eshell's buffer, so as not to lose
> this process output.
> WDYT?
I agree, it's best to emulate xterm when we can. In this case, though,
visual programs are pretty different from "visual" commands in a normal
xterm. The solution you suggested comes close, but visual commands are
"asynchronous" because they don't block the eshell buffer that spawned
them. So it might be confusing if you spawn a visual program, switch
back to eshell and forget about the visual program, and then later kill
the visual program and have its buffer spit into your eshell. It seems a
bit too action-at-a-distance for me, and at the end of the day, it's
more complexity for little gain.
An ideal solution would be to detect when a command is trying to control
the screen and then automatically jump into term mode. I'm not sure how
hard that would be, though.
FWIW, I've been using this patch for the last couple days and it feels
very natural. I've attached a patch that adds a custom var to get the
old behavior, tho the new behavior is default. Let me know if that's the
right direction.
Thanks! I hope you're doing well.
-s
Patch below:
From c58d82ddb2a2b893f39a926a0de98ff8195a8cad Mon Sep 17 00:00:00 2001
From: Samer Masterson <samer@samertm.com>
Date: Mon, 4 May 2015 05:50:57 -0700
Subject: [PATCH] Fix bug#18108
* lisp/eshell/em-term.el (eshell-destroy-buffer-when-process-dies):
New custom to preserve previous behavior.
* lisp/eshell/em-term.el (eshell-term-sentinel): No-op by default,
only kills term if `eshell-destroy-buffer-when-process-dies' is
non-nil.
---
etc/NEWS | 5 +++++
lisp/eshell/em-term.el | 39 +++++++++++++++++++++++++--------------
2 files changed, 30 insertions(+), 14 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index 1193055..e779b1b 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -632,6 +632,11 @@ command line's password prompt.
*** The new built-in command `clear' can scroll window contents out of sight.
If provided with an optional non-nil argument, the scrollback contents will be cleared.
+*** By default, eshell "visual" program buffers (as defined by
+`eshell-custom-program' and the `eshell-term' group) are no longer
+killed when their processes die. For the old behavior, set
+`eshell-destroy-buffer-when-process-dies' to non-nil.
+
** Browse-url
*** Support for the Conkeror web browser.
diff --git a/lisp/eshell/em-term.el b/lisp/eshell/em-term.el
index 4a6ac23..9ac2813 100644
--- a/lisp/eshell/em-term.el
+++ b/lisp/eshell/em-term.el
@@ -132,6 +132,13 @@ character to the invoked process."
:type 'boolean
:group 'eshell-term)
+(defcustom eshell-destroy-buffer-when-process-dies nil
+ "If non-nil, term buffers are destroyed after their processes die.
+WARNING: Setting this to non-nil may result in unexpected
+behavior for short-lived processes, see bug#18108."
+ :type 'boolean
+ :group 'eshell-term)
+
;;; Internal Variables:
(defvar eshell-parent-buffer)
@@ -190,20 +197,24 @@ allowed."
nil)
;; Process sentinels receive two arguments.
-(defun eshell-term-sentinel (proc _string)
- "Destroy the buffer visiting PROC."
- (let ((proc-buf (process-buffer proc)))
- (when (and proc-buf (buffer-live-p proc-buf)
- (not (eq 'run (process-status proc)))
- (= (process-exit-status proc) 0))
- (if (eq (current-buffer) proc-buf)
- (let ((buf (and (boundp 'eshell-parent-buffer)
- eshell-parent-buffer
- (buffer-live-p eshell-parent-buffer)
- eshell-parent-buffer)))
- (if buf
- (switch-to-buffer buf))))
- (kill-buffer proc-buf))))
+(defun eshell-term-sentinel (proc msg)
+ "Clean up the buffer visiting PROC.
+If `eshell-destroy-buffer-when-process-dies' is non-nil, destroy
+the buffer."
+ (term-sentinel proc msg) ;; First call the normal term sentinel.
+ (when eshell-destroy-buffer-when-process-dies
+ (let ((proc-buf (process-buffer proc)))
+ (when (and proc-buf (buffer-live-p proc-buf)
+ (not (eq 'run (process-status proc)))
+ (= (process-exit-status proc) 0))
+ (if (eq (current-buffer) proc-buf)
+ (let ((buf (and (boundp 'eshell-parent-buffer)
+ eshell-parent-buffer
+ (buffer-live-p eshell-parent-buffer)
+ eshell-parent-buffer)))
+ (if buf
+ (switch-to-buffer buf))))
+ (kill-buffer proc-buf)))))
;; jww (1999-09-17): The code below will allow Eshell to send input
;; characters directly to the currently running interactive process.
next prev parent reply other threads:[~2015-05-04 12:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-07-25 19:48 bug#18108: 24.3.92 : eshell-visual-options fails with some output Charles Rendleman
2015-01-19 9:08 ` bug#18108: [PATCH] " samer
2015-02-24 10:54 ` Samer Masterson
2015-04-06 4:05 ` Samer Masterson
2015-04-09 2:22 ` Stefan Monnier
2015-05-01 6:53 ` Samer Masterson
2015-05-04 1:21 ` Stefan Monnier
2015-05-04 12:57 ` Samer Masterson [this message]
2015-05-04 14:14 ` Stefan Monnier
2015-05-04 15:08 ` Samer Masterson
2015-05-04 21:14 ` Stefan Monnier
2015-05-16 3:20 ` Samer Masterson
2015-05-17 22:02 ` Samer Masterson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87mw1ksdo6.fsf@f-box.i-did-not-set--mail-host-address--so-tickle-me \
--to=samer@samertm.com \
--cc=18108@debbugs.gnu.org \
--cc=monnier@iro.umontreal.ca \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).