Subject: 23.2; `comint-history-isearch' with value 'dwim causes error when comint process is finished

From: Wesley Dawson <[email-masked]>
Date: Wed, 11 Apr 2012 02:49:06 -0700

Setting `comint-history-isearch' to 'dwim causes comint buffers where
the process has exited to give the following error:

(comint-after-pmark-p: Wrong type argument: processp, nil)

isearch works as expected after the message, however. Following is a fix
to `comint-after-pmark-p', which makes it simply return nil if the
process has already ended:

(defun comint-after-pmark-p ()
  "Return t if point is after the process output marker.
Return nil if the process has ended."
  (let* ((process (get-buffer-process (current-buffer)))
         (pmark (and process (process-mark process))))
    (and pmark (<= (marker-position pmark) (point)))))

It seems it is currently impossible to recover the input history once
the process exits, so I believe this is the sensible thing to do. In
addition, `async-shell-command' is often used to execute arbitrary
long-running processes that don't require input but that you don't want
to hang emacs, and so an input history won't even be available in those
cases.

Recipe for emacs -Q:

(setq comint-history-isearch 'dwim)
C-j
M-x async-shell-command : RET
C-x o
C-s (comint-after-pmark-p: Wrong type argument: processp, nil)

In GNU Emacs 23.2.1 (i486-pc-linux-gnu)
 of 2010-12-11 on raven, modified by Debian
configured using `configure  '--build' 'i486-linux-gnu' '--build' 'i486-linux-gnu' '--prefix=/usr' '--sharedstatedir=/var/lib' '--libexecdir=/usr/lib' '--localstatedir=/var/lib' '--infodir=/usr/share/info' '--mandir=/usr/share/man' '--with-pop=yes' '--enable-locallisppath=/etc/emacs23:/etc/emacs:/usr/local/share/emacs/23.2/site-lisp:/usr/local/share/emacs/site-lisp:/usr/share/emacs/23.2/site-lisp:/usr/share/emacs/site-lisp:/usr/share/emacs/23.2/leim' '--with-x=no' '--without-gconf' 'build_alias=i486-linux-gnu' 'CFLAGS=-DDEBIAN -g -O2' 'LDFLAGS=-g' 'CPPFLAGS=''

Important settings:
  value of $LC_ALL: en_US.UTF-8
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_US.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Shell

Minor modes in effect:
  shell-dirtrack-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
ESC [ > 0 ; 2 7 7 ; 0 c ESC ] 1 1 ; r g b : a 5 a 5 
/ 2 a 2 a / 2 a 2 a ESC \ ( s e t q SPC c o m i n t 
- h i s t o r y - i s e a r c h SPC ' d w i m ) C-j 
ESC & : RET C-x o C-s ESC x r e p o r t - e m a c s 
- b u g RET

Recent messages:
("emacs")
For information about GNU Emacs and the GNU system, type C-h C-a.
:: finished.
comint-after-pmark-p: Wrong type argument: processp, nil

Load-path shadows:
/usr/share/emacs/23.2/site-lisp/debian-startup hides /usr/share/emacs/site-lisp/debian-startup

Features:
(shadow sort mail-extr message sendmail regexp-opt ecomplete rfc822 mml
easymenu mml-sec password-cache mm-decode mm-bodies mm-encode mailcap
mail-parse rfc2231 rfc2047 rfc2045 qp ietf-drums mailabbrev nnheader
gnus-util netrc time-date mm-util mail-prsvr gmm-utils wid-edit
mailheader canlock sha1 hex-util hashcash mail-utils emacsbug shell
comint ring ediff-hook vc-hooks lisp-float-type lisp-mode register page
menu-bar rfn-eshadow timer select mldrag mouse jit-lock font-lock syntax
facemenu font-core frame cham georgian utf-8-lang misc-lang vietnamese
tibetan thai tai-viet lao korean japanese hebrew greek romanian slovak
czech european ethiopic indian cyrillic chinese case-table epa-hook
jka-cmpr-hook help simple abbrev loaddefs button minibuffer faces
cus-face files text-properties overlay md5 base64 format env code-pages
mule custom widget hashtable-print-readable backquote
make-network-process dbusbind multi-tty emacs)