bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#64901: 29.1; use-package fails to require bind-key at runtime in com


From: John Wiegley
Subject: bug#64901: 29.1; use-package fails to require bind-key at runtime in compiled files
Date: Thu, 03 Aug 2023 15:16:39 -0700
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (darwin)

>>>>> Eli Zaretskii <eliz@gnu.org> writes:

> Thanks.  Is the below what you had in mind?
> 
> diff --git a/lisp/use-package/bind-key.el b/lisp/use-package/bind-key.el
> index 0ab72ea..4affd8f 100644
> --- a/lisp/use-package/bind-key.el
> +++ b/lisp/use-package/bind-key.el
> @@ -180,6 +180,7 @@ bind-key
>  Emacs can evaluate this form at any time that it does redisplay
>  or operates on menu data structures, so you should write it so it
>  can safely be called at any time."
> +  (require 'bind-key)
>    (let ((namevar (make-symbol "name"))
>          (keyvar (make-symbol "key"))
>          (kmapvar (make-symbol "kmap"))

That’s too early, it would be:

  (let ((namevar (make-symbol "name"))
        (keyvar (make-symbol "key"))
        (kmapvar (make-symbol "kmap"))
        (kdescvar (make-symbol "kdesc"))
        (bindingvar (make-symbol "binding")))
    `(let* ((,namevar ,key-name)
            (,keyvar ,(if (stringp key-name) (read-kbd-macro key-name)
                        `(if (vectorp ,namevar) ,namevar
                           (read-kbd-macro ,namevar))))
            (,kmapvar (or (if (and ,keymap (symbolp ,keymap))
                              (symbol-value ,keymap) ,keymap)
                          global-map))
            (,kdescvar (cons (if (stringp ,namevar) ,namevar
                               (key-description ,namevar))
                             (if (symbolp ,keymap) ,keymap (quote ,keymap))))
            (,bindingvar (lookup-key ,kmapvar ,keyvar)))
       (require 'bind-key)      ; ensure `personal-keybindings' is in scope
       (let ((entry (assoc ,kdescvar personal-keybindings))
             (details (list ,command
                            (unless (numberp ,bindingvar)
                              ,bindingvar))))
         (if entry
             (setcdr entry details)
           (add-to-list 'personal-keybindings (cons ,kdescvar details))))
       ,(if predicate
            `(define-key ,kmapvar ,keyvar
               '(menu-item "" nil :filter (lambda (&optional _)
                                            (when ,predicate
                                              ,command))))
          `(define-key ,kmapvar ,keyvar ,command))))

-- 
John Wiegley                  GPG fingerprint = 4710 CF98 AF9B 327B B80F
http://newartisans.com                          60E1 46C4 BD1A 7AC1 4BA2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]