From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Samer Masterson Newsgroups: gmane.emacs.bugs Subject: bug#18108: [PATCH] 24.3.92 : eshell-visual-options fails with some output. Date: Mon, 04 May 2015 05:57:45 -0700 Message-ID: <87mw1ksdo6.fsf@f-box.i-did-not-set--mail-host-address--so-tickle-me> References: <1428293143.15170.1@mail.samertm.com> <87sibgeume.fsf@f-box.i-did-not-set--mail-host-address--so-tickle-me> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1430744366 17309 80.91.229.3 (4 May 2015 12:59:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 4 May 2015 12:59:26 +0000 (UTC) Cc: 18108@debbugs.gnu.org To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon May 04 14:59:15 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1YpFxo-0000fC-FV for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 May 2015 14:59:12 +0200 Original-Received: from localhost ([::1]:34149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpFxn-00032g-QI for geb-bug-gnu-emacs@m.gmane.org; Mon, 04 May 2015 08:59:11 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51451) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpFxk-000318-3G for bug-gnu-emacs@gnu.org; Mon, 04 May 2015 08:59:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YpFxf-0001HK-QT for bug-gnu-emacs@gnu.org; Mon, 04 May 2015 08:59:08 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:51397) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YpFxf-0001H8-M6 for bug-gnu-emacs@gnu.org; Mon, 04 May 2015 08:59:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1YpFxf-0006ks-2i for bug-gnu-emacs@gnu.org; Mon, 04 May 2015 08:59:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Samer Masterson Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 04 May 2015 12:59:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 18108 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 18108-submit@debbugs.gnu.org id=B18108.143074428325882 (code B ref 18108); Mon, 04 May 2015 12:59:02 +0000 Original-Received: (at 18108) by debbugs.gnu.org; 4 May 2015 12:58:03 +0000 Original-Received: from localhost ([127.0.0.1]:33139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YpFwg-0006jN-6g for submit@debbugs.gnu.org; Mon, 04 May 2015 08:58:02 -0400 Original-Received: from mx1.mailbox.org ([80.241.60.212]:43604) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1YpFwb-0006iz-1y for 18108@debbugs.gnu.org; Mon, 04 May 2015 08:57:58 -0400 Original-Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id DCE354002B; Mon, 4 May 2015 14:57:50 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Original-Received: from smtp1.mailbox.org ([80.241.60.240]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id KbhlVlUQ8qTK; Mon, 4 May 2015 14:57:49 +0200 (CEST) In-Reply-To: User-Agent: Notmuch/0.19 (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:102441 Archived-At: Stefan Monnier 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 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.