abo-abo / lispy

Short and sweet LISP editing
http://oremacs.com/lispy/
1.19k stars 129 forks source link

Repeat self-insert-command does not. #654

Open dericbytes opened 1 year ago

dericbytes commented 1 year ago

M-x repeat does not work correctly after a self-insert-command

On a clean setup (code below) In an empty buffer, with lispy enabled. Press i Call repeat

expected response

actual response

my hack

in lispy.el i wrapped calls to self-insert-command to maybe call lispy-repeat-self-insert-dem in function lispy--insert-or-call

...
((lispy--in-string-or-comment-p)
              (setq this-command 'self-insert-command)
          (cond
        ((eq real-this-command 'repeat)
                 (lispy-repeat-self-insert-dem))
        (t
         (call-interactively 'self-insert-command))))
...

(t
              (setq this-command 'self-insert-command)
          (cond
        ((eq real-this-command 'repeat)
                 (lispy-repeat-self-insert-dem))
        (t
         (call-interactively
          (quote
                   ,(or inserter
            'self-insert-command)))))))
(defun lispy-repeat-self-insert-dem ()
     ""
     (interactive)
     (setq last-repeatable-command 'self-insert-command)
     (setq last-command-event (char-before))
     (let ((indirect (indirect-function last-repeatable-command)))
       (if (or (stringp indirect)
           (vectorp indirect))
       ;; Bind last-repeatable-command so that executing the macro does
       ;; not alter it.
       (let ((last-repeatable-command last-repeatable-command))
         (execute-kbd-macro last-repeatable-command))
     (call-interactively last-repeatable-command))))
(package-initialize)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-refresh-contents)
(package-install 'lispy)
(lispy-mode 1)

(defun lispy-setup-dem ()
  (lispy-mode 1))

(add-hook 'emacs-lisp-mode-hook 'lispy-setup-dem)

(defun conditionally-enable-lispy ()
  (when (eq this-command 'eval-expression)
    (lispy-mode 1)))

(add-hook 'minibuffer-setup-hook 'conditionally-enable-lispy)

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, cairo version 1.16.0) of 2023-02-28 built on Slug Repository revision: 316ba78a737f0cc775b60775554591fb67722554 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12101003 System Description: Ubuntu 22.04.2 LTS

Configured using: 'configure --with-mailutils --with-modules --with-imagemagick --prefix /home/dericbytes/installs --bindir=/home/dericbytes/bin --with-native-compilation --with-json --with-tree-sitter'

Configured features: ACL CAIRO DBUS FREETYPE GIF GLIB GMP GNUTLS GPM GSETTINGS HARFBUZZ IMAGEMAGICK JPEG JSON LCMS2 LIBOTF LIBSELINUX LIBSYSTEMD LIBXML2 M17N_FLT MODULES NATIVE_COMP NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER WEBP X11 XDBE XIM XINPUT2 XPM GTK3 ZLIB

Important settings: value of $LANG: en_GB.UTF-8 locale-coding-system: utf-8-unix

Major mode: Lisp Interaction

Minor modes in effect: lispy-mode: t tooltip-mode: t global-eldoc-mode: t eldoc-mode: t show-paren-mode: t electric-indent-mode: t mouse-wheel-mode: t tool-bar-mode: t menu-bar-mode: t file-name-shadow-mode: t global-font-lock-mode: t font-lock-mode: t blink-cursor-mode: t line-number-mode: t indent-tabs-mode: t transient-mark-mode: t auto-composition-mode: t auto-encryption-mode: t auto-compression-mode: t

RuijieYu commented 1 year ago

There are two setups from your description, only one of which triggers the issue you described.

1

$ emacs -L lispy/master
i C-x z
=> "iz"

2

$ emacs -L lispy/master
i M-x repeat RET
=> "ii"

Can you confirm that you see the same behavior in both cases? Or are you talking about a third case?

dericbytes commented 1 year ago

I get the same behaviour as you.

Case 3 - my own personal repeat key bound to a key binding. The original repeat has same behaviour

(global-set-key (kbd "C-;") 'repeat)
i C-;
=> "i"
RuijieYu commented 1 year ago

Can reproduce, but I am not sure how to fix it, not even how to write a regression test for it. This is likely going to sit for a while until the owner comes back.

dericbytes commented 1 year ago

Thanks for the feedback. The code I included above fixes the problem I had.

Yasnippet has some useful ert tests for simulating key presses. https://github.com/joaotavora/yasnippet/blob/master/yasnippet-tests.el