From:	CRDGW2::CRDGW2::MRGATE::"SMTP::PREP.AI.MIT.EDU::INFO-GNU-EMACS-REQUEST" 21-SEP-1989 22:49
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Functions to repeat last command

Received: by life.ai.mit.edu (4.1/AI-4.10) id AA11853; Thu, 21 Sep 89 20:20:03 EDT
Return-Path: <info-gnu-emacs-request@prep.ai.mit.edu>
Received: from tut.cis.ohio-state.edu by life.ai.mit.edu (4.1/AI-4.10) id AA11742; Thu, 21 Sep 89 20:12:35 EDT
Received: by tut.cis.ohio-state.edu (5.61/4.890725)
	id AA00547; Thu, 21 Sep 89 20:05:00 -0400
Received: from USENET by tut.cis.ohio-state.edu with netnews
	for info-gnu-emacs@prep.ai.mit.edu (info-gnu-emacs@prep.ai.mit.edu)
	(contact usenet@tut.cis.ohio-state.edu if you have questions)
Date: 21 Sep 89 17:45:00 GMT
From: primerd!hollin!ds@bloom-beacon.mit.edu
Subject: Functions to repeat last command
Message-Id: <81100004@hollin>
Sender: info-gnu-emacs-request@prep.ai.mit.edu
To: info-gnu-emacs@prep.ai.mit.edu


; GNU EMACS functions to repeat the last EMACS command
; 09/21/89, D. Spector

; --------------------------------------------------------------------
; Copyright (c) 1989 David Spector
; This software may be used, copied, and modified freely, except not
; as part of a product sold for profit, so long as these four copyright
; lines are retained without change.  There is no warranty of any kind.
; --------------------------------------------------------------------

(defun repeat (count)
  "Repeat last command with no query.
Repeats the command as many times as indicated by numeric argument COUNT.
If the last command had a numeric argument, it is ignored; if it had an
argument list (usually happens only for functions that are not invoked by
interactive keypath), the list is omitted; and if it was a self-inserted
character, the invoking keybinding is inserted instead."
  (interactive "p")
  (let (str pos)
    (if (eq last-command 'repeat)
        ()
      (setq pos (- (- (length (recent-keys)) 2)
                   (length (this-command-keys))))
      (setq str (substring (recent-keys) pos (+ pos 2)))
      (setq repeat-complex-flag nil)
      (setq repeat-kill-flag nil)
      (cond
       ((or (equal str "e") (equal str "E"))
        (setq repeat-command 'call-last-kbd-macro))
       ((or (equal str "d") (equal str "D"))
        (setq repeat-command 'kill-word)
        (setq repeat-kill-flag t))
       ((or (equal str "") (equal str ""))
        (setq repeat-command 'backward-kill-word)
        (setq repeat-kill-flag t))
       ((or (eq last-command 'exit-minibuffer) (eq last-command 'kill-region))
        (setq repeat-complex-flag t)
        (setq repeat-command (car command-history)))
       (t
        (setq repeat-command last-command))))
    ;(princ repeat-command)
    (while (> count 0)
      (if repeat-kill-flag
          (append-next-kill))
      (if repeat-complex-flag
          (eval repeat-command)
        (command-execute repeat-command))
      (setq this-command 'repeat)
      (setq count (1- count)))
    (setq last-command 'repeat)))
(global-set-key "\^\\" 'repeat)

(defun again ()
  "Repeat last complex command with no query."
  (interactive)
  (eval (prin1 (car command-history))))
(global-set-key "\^X\^\\" 'again)

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

David Spector
Prime Computer, Inc.
ds@primerd.prime.com (until I get laid off, expected soon)
