一気に undo したい

入力

今入力した(する)文字がさっき入力した文字と同種(アルファベット, 数字, 空白, 記号, その他 のどれか)か、空白後のアルファベットなら undo の区切りを消す=今のとさっきのをまとめ1発で undo できるようになる、というもの。

(defun char-type (c)
  (unless (characterp c)
    (error 'type-error :datum c :expected-type 'character))
  (let ((code (char-code c)))
    (cond ((< 47 code 58) :number)
          ((or (< 96 code 123) (< 64 code 91)) :alpha)
          ((member c '(#\SPC #\LFD #\TAB)) :space)
          ((or (<= 33 code 47) (<= 58 code 64)
               (<= 91 code 96) (<= 123 code 126)) :symbol)
          (t :other))))

(defparameter *last-command-char-type* nil)

(defun my-self-insert (&optional arg)
  "clear undo-boundary when inserts same type of chars repertedlly."
  (interactive "*p")
  (undo-boundary)
  (let ((type (char-type *last-command-char*)))
    (when (and (eq *last-command* 'my-self-insert)
               (or (eq *last-command-char-type* type)
                   (and (eql type :alpha)
                        (eql *last-command-char-type* :space))))
      (clear-undo-boundary))
    (setq *last-command-char-type* type)
    (call-interactively 'self-insert-command)))

(substitute-key-definition 'self-insert-command 'my-self-insert)

BS とか

与えられたコマンドを、そのコマンドが繰り返されたら undo の区切りを消して元の動作を実行するコマンドにする、というもの。

(defun clear-u/b-when-repeated (command &rest more)
  "make COMMAND clear undo-boundary when it repeated."
  (prog1 command
    (let ((odef (or (get command 'original-def)
                    (setf (get command 'original-def)
                          (symbol-function command)))))
      (setf (symbol-function command)
            (lambda (&optional arg)
              (interactive "P")
              (undo-boundary)
              (when (eq *last-command* *this-command*)
                (clear-undo-boundary))
              (call-interactively odef))))
    (when more (apply #'clear-u/b-when-repeated more))))

(clear-u/b-when-repeated
 'backward-delete-char-untabify-or-selection)

なんか my-kill-line だと上手く動かん。なんでだろ。call-interactively が怪しい予感。