[gnu.emacs.bug] chistory.el

jack@HPTNJAR.HP.COM (Jack Repenning) (07/26/89)

In GNU Emacs 18.54.1 of Sun May 14 1989 on hpsrdmo (hpux)

SYMPTOM
The code in my echistory.el fails (claims that there's no history,
when in fact there is) when called from an empty buffer.

VERSIONS
Here's the revision stuff from echistory.el:

;; Electric Command History Mode
;; Copyright (C) 1985 Free Software Foundation, Inc.
;; Principal author K. Shane Hartman

The actual problem seems to be in chistory.el, in the function
list-command-history.  Here's chistory's revision info:

;; chistory -- List command history
;; Copyright (C) 1985 Free Software Foundation, Inc.
;; Principal author K. Shane Hartman

The files involved are surprisingly old, and seem to be original
versions.  I'm a little suspicious that I may be working with out of
date ELISP, but all the copies I've been able to locate look the same.

I checked with the guy from whom I got my Emacs, to see what its
pedigree is, and he said:

>      Well, all I can say is that the bug exists in [my version].
> I'm not sure of the genealogy of [my] sources.  I think they
> originated from either "virginal" V18.47, V18.51, or V18.52 sources,
> but I'm not sure.

Not very comforting, nor even very clear, but it's the best I can
offer.

DIAGNOSIS
The problem seems to be that list-command-history builds the command
history list in the *Command History* buffer using
(with-output-to-temp-buffer), then uses (goto-char (point-min)) to see
if any history was generated.  However, at least in the version I have
here, (with-output-to-temp-buffer) doesn't (set-buffer) to the temp
buffer: the (goto-char) acts in the buffer from whence it was called.
So the test actually becomes, "is there anything in the buffer whence
we were called," which is irrelevant, instead of "is there anything in
the command history buffer."

A side-effect is that point gets set to (point-min) in the calling
buffer, but this is generally hidden by various enshrouding
(save-excursion)s.

FIX
My fix is to add a (set-buffer) to list-command-history.  Attached is
a diff -c.

Jack Repenning          (HP-UX: jack@hpda, (Telnet and PacTel:) 447-3380, 43LN)
TCL Productivity Consultant (HPDesk: Jack REPENNING - no one else comes close!)


*** chistory.el.old     Mon Jul 24 19:06:26 1989
--- chistory.el Mon Jul 24 19:05:31 1989
***************
*** 102,107
          (prin1 (car history))
          (terpri))
        (setq history (cdr history))))
      (goto-char (point-min))
      (if (eobp)
        (error "No command history.")

--- 102,108 -----
          (prin1 (car history))
          (terpri))
        (setq history (cdr history))))
+     (set-buffer "*Command History*")
      (goto-char (point-min))
      (if (eobp)
        (error "No command history.")