Subject: bug#31236: closed (Re: bug#31236: [PATCH] Fix pre- and post-command-hook errors in term.el)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 22 Apr 2018 17:10:02 +0000

Your bug report

#31236: [PATCH] Fix pre- and post-command-hook errors in term.el

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
31236: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=31236
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: bug#31236: [PATCH] Fix pre- and post-command-hook errors in term.el
From: Eli Zaretskii <[email-masked]>
To: Phil Sainty <[email-masked]>
Cc: [email-masked], [email-masked]
Date: Sun, 22 Apr 2018 20:09:22 +0300
List-Id: <debbugs-submit.debbugs.gnu.org>

> Date: Sun, 22 Apr 2018 23:48:38 +1200
> From: Phil Sainty <[email-masked]>
> Cc: bug-gnu-emacs <bug-gnu-emacs-bounces+psainty=[email-masked]>,
> 	[email-masked]
> 
> Bug and proposed fix confirmed and tested here.
> 
> This was an oversight on my part from #24837.
> 
> The suggested patch seems sensible to me.  If others agree, I think
> this should be committed to the emacs-26 branch.

Pushed, thanks.

Karl, in the future please include a commit log message according to
the instructions in CONTRIBUTE.  (I fixed that for you this time.)

Subject: [PATCH] Fix pre- and post-command-hook errors in term.el
From: Karl Otness <[email-masked]>
To: [email-masked]
Date: Sat, 21 Apr 2018 23:41:51 -0400
List-Id: <debbugs-submit.debbugs.gnu.org>

As far as I can tell there isn't an existing bug report for this
issue. It is very minor but I have attached a fix. This affects Emacs
26.1-rc1 `term' and `ansi-term'. In char mode term installs functions
in both pre- and post-command-hooks. After the process exits both of
these hooks produce errors and then are removed by Emacs after
printing a message.

Both of these hooks are re-installed when entering char mode and
removing them if they are not present will do nothing. To produce this
change, I took the remove-hook lines used when entering line mode and
placed them in `term-handle-exit'.

To reproduce the issue in 26.1, M-x term, exit the running process and
execute any command (i.e. move point). In *Messages* there should be
the following lines:

Error in pre-command-hook (term-set-goto-process-mark):
(wrong-type-argument processp nil)
Error in post-command-hook (term-goto-process-mark-maybe):
(wrong-type-argument processp nil)

The error seems to come up from `process-mark'. After this change,
these errors no longer appear as the hooks are removed. I have
attached a patch which applies this change to current master.

Thank you,
Karl
From e988914505a694b00eaff60ca226400d998c19aa Mon Sep 17 00:00:00 2001
From: Karl Otness <[email-masked]>
Date: Sat, 21 Apr 2018 23:01:11 -0400
Subject: [PATCH] Fix pre- and post-command-hook errors in term.el

Before this patch, after the terminal process dies the command hooks
added in term-mode's char mode would produce errors. This fix removes
these hooks when the process dies.
---
 lisp/term.el | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lisp/term.el b/lisp/term.el
index cfb39c34e5..017b0221ec 100644
--- a/lisp/term.el
+++ b/lisp/term.el
@@ -1456,6 +1456,9 @@ term-handle-exit
   (let ((buffer-read-only nil)
 	(omax (point-max))
 	(opoint (point)))
+    ;; Remove hooks to avoid errors due to dead process.
+    (remove-hook 'pre-command-hook #'term-set-goto-process-mark t)
+    (remove-hook 'post-command-hook #'term-goto-process-mark-maybe t)
     ;; Record where we put the message, so we can ignore it
     ;; later on.
     (goto-char omax)
-- 
2.17.0