Kungsgeten/ryo-modal

use-package integration broke during the merge

Closed this issue · 3 comments

Sorry for not testing this any sooner, but it looks like the use-package integration broke during the clean-up when you merged it. To illustrate what goes wrong I use the following example:

(use-package ryo-modal-core-keys
  :ensure nil
  :ryo
  ;; digit mappings
  (:norepeat t)
  ("1" "M-1" :name "1")
  ("2" "M-2" :name "2")

  ;; modal insert editing maps
  (:exit t)
  ("a" forward-char :name "append")
  ("A" move-end-of-line :name "append end of line")

  ;; modal editing
  (:norepeat nil)
  ("p" "C-y" :name "paste")
  ("x" delete-char :name "delete char"))

When expanding this using M-x pp-macroexpand-last-sexp I get:

(progn
  (use-package-ensure-elpa 'ryo-modal-core-keys
                           '(nil)
                           'nil)
  (defvar use-package--warning18
    #'(lambda
        (keyword err)
        (let
            ((msg
              (format "%s/%s: %s" 'ryo-modal-core-keys keyword
                      (error-message-string err))))
          (display-warning 'use-package msg :error))))
  (condition-case-unless-debug err
      (ignore
       (ryo-modal-key "x" 'delete-char :name "delete char" :norepeat nil :package 'ryo-modal-core-keys)
       (ryo-modal-key "p" "C-y" :name "paste" :norepeat nil :package 'ryo-modal-core-keys)
       (ryo-modal-key "A" 'move-end-of-line :name "append end of line" :exit t :package 'ryo-modal-core-keys)
       (ryo-modal-key "a" 'forward-char :name "append" :exit t :package 'ryo-modal-core-keys)
       (ryo-modal-key "2" "M-2" :name "2" :norepeat t :package 'ryo-modal-core-keys)
       (ryo-modal-key "1" "M-1" :name "1" :norepeat t :package 'ryo-modal-core-keys))
    (error
     (funcall use-package--warning18 :catch err))))

This isn't correct as it should have a block that lazy-binds the commands that are being used, i.e. in this case the delete-char, move-end-of-line and forward char. The function ryo-modal--extract-commands-from is responsible for extracting this from the original :ryo definition and returning the list of these commands, so that is where the error is likely to be as I guess it now returns nil instead of the commands.

I'll investigate when I have a bit more time, but it might be that you immediately spot what goes wrong.

Narrowed it down a bit more.

One of the problems is that now ryo-modal--extract-commands-from returns a list of lists, i.e.

( (delete-char) (move-end-of-line) (forward-char) ),

while use-package-plist-append needs to get the following for the value behind :commands

( delete-char move-end-of-line forward-char )

That should not be too hard to fix, but unfortunately the extraction of the commands from the hydra also broke in that same edit.

I think I managed to fix it, but please try it out :)

The output that is being generated for :ryo now looks very similar to what I saw for general.el, which is what I looked at to see how this is supposed to work. So this indeed looks fixed to me.

The disclaimer is that I'm really not sure whether those autoloads are actually needed as I don't see that written in the guide on how to write extensions for use-package: https://github.com/jwiegley/use-package#how-to-create-an-extension

btw) As the generated autoloads refer to the package-name that the :ryo is used in I suspect that those only make sense for keys that use commands in the package itself. Hard to tell as I can't trigger errors in any case...