Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow god-literal-key to be toggled #159

Merged
merged 3 commits into from
Aug 12, 2024

Conversation

federkamm
Copy link
Contributor

The changes allow god-literal-key to be toggled. This is necessary when modified keys follow literal keys in a key sequence. E.g. C-x r M-y for copy-rectangle-as-kill can now be entered as x SPC r SPC g y.

Should the version be bumped to 2.19.0?

Shortcomings: C-SPC can still not be entered within a key sequence. E.g. C-x r C-SPC for point-to-register can't currently be entered in god-mode.

Beside the Ecukes test, the code was verified with

(defun god-mode-translate (key-string)
  (let* ((key-list (cl-coerce key-string 'list))
         (pop-key-list (lambda (&rest _) (pop key-list)))
         god-literal-sequence string-so-far)
    (advice-add 'read-event :override pop-key-list)
    (unwind-protect (cl-loop for key = (read-event) unless key return string-so-far
                             do (let ((sanitized-key (god-mode-sanitized-key-string key)))
                                  (setq string-so-far (god-key-string-after-consuming-key sanitized-key string-so-far))))
      (advice-remove 'read-event pop-key-list))))

(let ((god-mode-tests '("x x x" "C-x x C-x"
                        "x xx" "C-x x x"
                        "xxx" "C-x C-x C-x"
                        "x xx xx x" "C-x x x C-x C-x x"
                        "x x gx" "C-x x M-x"
                        "x xgx" "C-x x g x"
                        "x  x" "C-x C-x"
                        "x   x" "C-x x")))
  (cl-loop for (input output) on god-mode-tests by #'cddr
           for translation = (god-mode-translate input)
           for success = (string= translation output)
           count (not success)
           unless success do (message "%S => %S =/= %S" input translation output)))

Copy link
Collaborator

@darth10 darth10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this great improvement!

I've added a couple comments regarding indentation.

Generally, it would be good to keep new features behind a custom var, but I think in this case it would be more effort than it's worth.
We can always add a var later if needed.

Should the version be bumped to 2.19.0?

Let's not worry about that for now - version bumps are for stable versions anyways.
I'll bump it after some time, once others have had a chance to try out these changes.

god-mode.el Outdated Show resolved Hide resolved
god-mode.el Outdated Show resolved Hide resolved
@darth10 darth10 merged commit 9ace725 into emacsorphanage:master Aug 12, 2024
6 checks passed
@darth10
Copy link
Collaborator

darth10 commented Aug 12, 2024

Closes #135.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants