all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* command-execute: Wrong type argument: commandp, helm-command-prefix
@ 2023-05-05  0:34 Hongyi Zhao
  2023-05-05  1:40 ` Platon Pronko
  0 siblings, 1 reply; 8+ messages in thread
From: Hongyi Zhao @ 2023-05-05  0:34 UTC (permalink / raw)
  To: help-gnu-emacs

Hi here,

I'm using the following configuration for `helm-bibtex`:

```
(use-package helm-bibtex
  :init
  (setq

   ;; bibtex-completion-bibliography (directory-files-recursively
   ;;                     (concat (getenv "HOME")
"/texmf/bibtex/bib/local") "^[A-Za-z].+.bib$")


   ;;bibtex-completion-library-path (concat (getenv "HOME") "/pdf")
   ;;bibtex-completion-notes-path (concat (getenv "HOME") "/notes")
   bibtex-completion-pdf-field "File"
   ;;https://github.com/tmalsburg/helm-bibtex#insert-latex-cite-commands
   bibtex-completion-cite-prompt-for-optional-arguments nil)


  :config
  (require 'helm-config)
  :bind
  (("<menu>" . helm-command-prefix)
   :map helm-command-map
   ("b" . helm-bibtex)
   ("B" . helm-bibtex-with-local-bibliography)
   ("n" . helm-bibtex-with-notes)
   ("<menu>" . helm-resume))

  :config
  ;;https://github.com/tmalsburg/helm-bibtex#application-used-for-opening-pdfs
  ;;https://github.com/tmalsburg/helm-bibtex/issues/386
  (defun bibtex-completion-open-pdf-external (keys &optional fallback-action)
    (let ((bibtex-completion-pdf-open-function
       (lambda (fpath) (start-process "evince" "*helm-bibtex-evince*"
"/usr/bin/evince" fpath))))
      (bibtex-completion-open-pdf keys fallback-action)))

  (helm-bibtex-helmify-action bibtex-completion-open-pdf-external
helm-bibtex-open-pdf-external)

  (helm-add-action-to-source
   'helm-bibtex
   '(("P" helm-bibtex-open-pdf-external "Open PDF file in external
viewer (if present)")))

  ;;https://github.com/tmalsburg/helm-bibtex#browser-used-for-opening-urls-and-dois
  (setq bibtex-completion-browser-function
    (lambda (url _) (start-process "firefox" "*firefox*" "firefox" url)))

  )
```

When I hit <menu> hey for the first time, the following error will be triggered:

command-execute: Wrong type argument: commandp, helm-command-prefix

If I hit this key once more, the problem doesn't appear. I'm very
puzzled by this problem. Any tips will be appreciated.

See https://github.com/tmalsburg/helm-bibtex/issues/429#issuecomment-1535010227
for the related discussion.

Regards,
Zhao
-- 
Assoc. Prof. Hongsheng Zhao <hongyi.zhao@gmail.com>
Theory and Simulation of Materials
Hebei Vocational University of Technology and Engineering
No. 473, Quannan West Street, Xindu District, Xingtai, Hebei province



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: command-execute: Wrong type argument: commandp, helm-command-prefix
  2023-05-05  0:34 command-execute: Wrong type argument: commandp, helm-command-prefix Hongyi Zhao
@ 2023-05-05  1:40 ` Platon Pronko
  2023-05-05  2:45   ` Ruijie Yu via Users list for the GNU Emacs text editor
  0 siblings, 1 reply; 8+ messages in thread
From: Platon Pronko @ 2023-05-05  1:40 UTC (permalink / raw)
  To: Hongyi Zhao, help-gnu-emacs

On 2023-05-05 08:34, Hongyi Zhao wrote:
> Hi here,
> 
> I'm using the following configuration for `helm-bibtex`:
> 
> ```
> (use-package helm-bibtex
>    :init
>    (setq
> 
>     ;; bibtex-completion-bibliography (directory-files-recursively
>     ;;                     (concat (getenv "HOME")
> "/texmf/bibtex/bib/local") "^[A-Za-z].+.bib$")
> 
> 
>     ;;bibtex-completion-library-path (concat (getenv "HOME") "/pdf")
>     ;;bibtex-completion-notes-path (concat (getenv "HOME") "/notes")
>     bibtex-completion-pdf-field "File"
>     ;;https://github.com/tmalsburg/helm-bibtex#insert-latex-cite-commands
>     bibtex-completion-cite-prompt-for-optional-arguments nil)
> 
> 
>    :config
>    (require 'helm-config)
>    :bind
>    (("<menu>" . helm-command-prefix)
>     :map helm-command-map
>     ("b" . helm-bibtex)
>     ("B" . helm-bibtex-with-local-bibliography)
>     ("n" . helm-bibtex-with-notes)
>     ("<menu>" . helm-resume))
> 
>    :config
>    ;;https://github.com/tmalsburg/helm-bibtex#application-used-for-opening-pdfs
>    ;;https://github.com/tmalsburg/helm-bibtex/issues/386
>    (defun bibtex-completion-open-pdf-external (keys &optional fallback-action)
>      (let ((bibtex-completion-pdf-open-function
>         (lambda (fpath) (start-process "evince" "*helm-bibtex-evince*"
> "/usr/bin/evince" fpath))))
>        (bibtex-completion-open-pdf keys fallback-action)))
> 
>    (helm-bibtex-helmify-action bibtex-completion-open-pdf-external
> helm-bibtex-open-pdf-external)
> 
>    (helm-add-action-to-source
>     'helm-bibtex
>     '(("P" helm-bibtex-open-pdf-external "Open PDF file in external
> viewer (if present)")))
> 
>    ;;https://github.com/tmalsburg/helm-bibtex#browser-used-for-opening-urls-and-dois
>    (setq bibtex-completion-browser-function
>      (lambda (url _) (start-process "firefox" "*firefox*" "firefox" url)))
> 
>    )
> ```
> 
> When I hit <menu> hey for the first time, the following error will be triggered:
> 
> command-execute: Wrong type argument: commandp, helm-command-prefix
> 
> If I hit this key once more, the problem doesn't appear. I'm very
> puzzled by this problem. Any tips will be appreciated.
> 
> See https://github.com/tmalsburg/helm-bibtex/issues/429#issuecomment-1535010227
> for the related discussion.
> 
> Regards,
> Zhao

Hi!

Can you provide a minimal test config for this issue? I tried to reproduce it with the following, but it doesn't throw any errors for me:

```(require 'package)
(setq package-archives '(
   ("gnu" . "http://elpa.gnu.org/packages/")
   ("melpa" . "https://melpa.org/packages/")))
(package-initialize)

(require 'helm)

(use-package helm-bibtex
   :init
   (setq
    bibtex-completion-bibliography (directory-files-recursively
                         (concat (getenv "HOME")
                                 "/texmf/bibtex/bib/local") "^[A-Za-z].+.bib$")


    ;;bibtex-completion-library-path (concat (getenv "HOME") "/pdf")
    ;;bibtex-completion-notes-path (concat (getenv "HOME") "/notes")
    bibtex-completion-pdf-field "File"
    ;;https://github.com/tmalsburg/helm-bibtex#insert-latex-cite-commands
    bibtex-completion-cite-prompt-for-optional-arguments nil)


   :config
   (require 'helm-config)
   :bind
   (("<f8>" . helm-command-prefix)
    :map helm-command-map
    ("b" . helm-bibtex)
    ("B" . helm-bibtex-with-local-bibliography)
    ("n" . helm-bibtex-with-notes)
    ("<f8>" . helm-resume))

   :config
   (defun bibtex-completion-open-pdf-external (keys &optional fallback-action)
     (let ((bibtex-completion-pdf-open-function
        (lambda (fpath) (start-process "evince" "*helm-bibtex-evince*"
"/usr/bin/evince" fpath))))
       (bibtex-completion-open-pdf keys fallback-action)))

   (helm-bibtex-helmify-action bibtex-completion-open-pdf-external
helm-bibtex-open-pdf-external)

   (helm-add-action-to-source
    'helm-bibtex
    '(("P" helm-bibtex-open-pdf-external "Open PDF file in external
viewer (if present)")))

   ;;https://github.com/tmalsburg/helm-bibtex#browser-used-for-opening-urls-and-dois
   (setq bibtex-completion-browser-function
     (lambda (url _) (start-process "firefox" "*firefox*" "firefox" url)))

   )
```

-- 
Best regards,
Platon Pronko
PGP 2A62D77A7A2CB94E




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: command-execute: Wrong type argument: commandp, helm-command-prefix
  2023-05-05  1:40 ` Platon Pronko
@ 2023-05-05  2:45   ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-05-05  4:18     ` Hongyi Zhao
  2023-05-05  5:04     ` Michael Heerdegen
  0 siblings, 2 replies; 8+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-05-05  2:45 UTC (permalink / raw)
  To: Platon Pronko; +Cc: Hongyi Zhao, help-gnu-emacs


Platon Pronko <platon7pronko@gmail.com> writes:

> On 2023-05-05 08:34, Hongyi Zhao wrote:

>>    :bind
>>    (("<menu>" . helm-command-prefix)
>>     :map helm-command-map
>>     ("b" . helm-bibtex)
>>     ("B" . helm-bibtex-with-local-bibliography)
>>     ("n" . helm-bibtex-with-notes)
>>     ("<menu>" . helm-resume))
>> ```
>> When I hit <menu> hey for the first time, the following error will be
>> triggered:
>> command-execute: Wrong type argument: commandp, helm-command-prefix
>> If I hit this key once more, the problem doesn't appear. I'm very
>> puzzled by this problem. Any tips will be appreciated.
>> See
>> https://github.com/tmalsburg/helm-bibtex/issues/429#issuecomment-1535010227
>> for the related discussion.
>> Regards,
>> Zhao

>   :bind
>   (("<f8>" . helm-command-prefix)
>    :map helm-command-map
>    ("b" . helm-bibtex)
>    ("B" . helm-bibtex-with-local-bibliography)
>    ("n" . helm-bibtex-with-notes)
>    ("<f8>" . helm-resume))

When I macroexpand

    (use-package helm-bibtex :bind ("<f8>" . helm-command-prefix))

I get this:

```emacs-lisp
(progn
  (unless
      (fboundp 'helm-command-prefix)
    (autoload #'helm-command-prefix "helm-bibtex" nil t))
  (bind-keys :package helm-bibtex
             ("<f8>" . helm-command-prefix)))
```

When I macroexpand

    (use-package helm-bibtex :bind-keymap ("<f8>" . helm-command-prefix))

I get this:

```emacs-lisp
(bind-key "<f8>"
  #'(lambda nil
      (interactive)
      (use-package-autoload-keymap 'helm-command-prefix 'helm-bibtex nil)))
```

Looking at the docstring of `bind-keys', it seems to me that the fact
that :bind happens to work sometimes is unintended, and we should prefer
:bind-keymap instead.  Hongyi, try to move your keybind to
`helm-command-prefix' into a :bind-keymap section and see if that helps.

FTR, I wasn't able to reproduce the error with :bind "<f9>" either.  I
don't have "<menu>" key set, so I can't test that.

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: command-execute: Wrong type argument: commandp, helm-command-prefix
  2023-05-05  2:45   ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-05-05  4:18     ` Hongyi Zhao
  2023-05-05  5:04     ` Michael Heerdegen
  1 sibling, 0 replies; 8+ messages in thread
From: Hongyi Zhao @ 2023-05-05  4:18 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Platon Pronko, help-gnu-emacs

On Fri, May 5, 2023 at 10:59 AM Ruijie Yu <ruijie@netyu.xyz> wrote:
>
>
> Platon Pronko <platon7pronko@gmail.com> writes:
>
> > On 2023-05-05 08:34, Hongyi Zhao wrote:
>
> >>    :bind
> >>    (("<menu>" . helm-command-prefix)
> >>     :map helm-command-map
> >>     ("b" . helm-bibtex)
> >>     ("B" . helm-bibtex-with-local-bibliography)
> >>     ("n" . helm-bibtex-with-notes)
> >>     ("<menu>" . helm-resume))
> >> ```
> >> When I hit <menu> hey for the first time, the following error will be
> >> triggered:
> >> command-execute: Wrong type argument: commandp, helm-command-prefix
> >> If I hit this key once more, the problem doesn't appear. I'm very
> >> puzzled by this problem. Any tips will be appreciated.
> >> See
> >> https://github.com/tmalsburg/helm-bibtex/issues/429#issuecomment-1535010227
> >> for the related discussion.
> >> Regards,
> >> Zhao
>
> >   :bind
> >   (("<f8>" . helm-command-prefix)
> >    :map helm-command-map
> >    ("b" . helm-bibtex)
> >    ("B" . helm-bibtex-with-local-bibliography)
> >    ("n" . helm-bibtex-with-notes)
> >    ("<f8>" . helm-resume))
>
> When I macroexpand
>
>     (use-package helm-bibtex :bind ("<f8>" . helm-command-prefix))
>
> I get this:
>
> ```emacs-lisp
> (progn
>   (unless
>       (fboundp 'helm-command-prefix)
>     (autoload #'helm-command-prefix "helm-bibtex" nil t))
>   (bind-keys :package helm-bibtex
>              ("<f8>" . helm-command-prefix)))
> ```
>
> When I macroexpand
>
>     (use-package helm-bibtex :bind-keymap ("<f8>" . helm-command-prefix))
>
> I get this:
>
> ```emacs-lisp
> (bind-key "<f8>"
>   #'(lambda nil
>       (interactive)
>       (use-package-autoload-keymap 'helm-command-prefix 'helm-bibtex nil)))
> ```
>
> Looking at the docstring of `bind-keys', it seems to me that the fact
> that :bind happens to work sometimes is unintended, and we should prefer
> :bind-keymap instead.  Hongyi, try to move your keybind to
> `helm-command-prefix' into a :bind-keymap section and see if that helps.
>
> FTR, I wasn't able to reproduce the error with :bind "<f9>" either.  I
> don't have "<menu>" key set, so I can't test that.

Nice trick and it works. I've tried with several keys, such as,
<menu>, <f8>, etc., to set helm-command-prefix, and they all works
smoothly this way. The following is revised configuration according to
the above advice:

(use-package helm-bibtex
  :init
  (setq
   bibtex-completion-pdf-field "File"
   ;;https://github.com/tmalsburg/helm-bibtex#insert-latex-cite-commands
   bibtex-completion-cite-prompt-for-optional-arguments nil)

  :bind-keymap
  ("<menu>" . helm-command-prefix)
  :bind
  (
   :map helm-command-map
   ("b" . helm-bibtex)
   ("B" . helm-bibtex-with-local-bibliography)
   ("n" . helm-bibtex-with-notes)
   ("<menu>" . helm-resume)
   )

  :config
  (require 'helm-config)
  ;;https://github.com/tmalsburg/helm-bibtex#application-used-for-opening-pdfs
  ;;https://github.com/tmalsburg/helm-bibtex/issues/386
  (defun bibtex-completion-open-pdf-external (keys &optional fallback-action)
    (let ((bibtex-completion-pdf-open-function
       (lambda (fpath) (start-process "evince" "*helm-bibtex-evince*"
"/usr/bin/evince" fpath))))
      (bibtex-completion-open-pdf keys fallback-action)))

  (helm-bibtex-helmify-action bibtex-completion-open-pdf-external
helm-bibtex-open-pdf-external)

  (helm-add-action-to-source
   'helm-bibtex
   '(("P" helm-bibtex-open-pdf-external "Open PDF file in external
viewer (if present)")))

  ;;https://github.com/tmalsburg/helm-bibtex#browser-used-for-opening-urls-and-dois
  (setq bibtex-completion-browser-function
    (lambda (url _) (start-process "firefox" "*firefox*" "firefox" url)))

  )

> --
> Best,
>
>
> RY

Regards,
Zhao

> [Please note that this mail might go to spam due to some
> misconfiguration in my mail server -- still investigating.]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: command-execute: Wrong type argument: commandp, helm-command-prefix
  2023-05-05  2:45   ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-05-05  4:18     ` Hongyi Zhao
@ 2023-05-05  5:04     ` Michael Heerdegen
  2023-05-05  5:13       ` Hongyi Zhao
  2023-05-05  5:18       ` Ruijie Yu via Users list for the GNU Emacs text editor
  1 sibling, 2 replies; 8+ messages in thread
From: Michael Heerdegen @ 2023-05-05  5:04 UTC (permalink / raw)
  To: help-gnu-emacs

Ruijie Yu via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

>     (autoload #'helm-command-prefix "helm-bibtex" nil t))
                                                    ^^^^^

Is this expected to work reliably?  AFAIU, the thing to be autoloaded is
a keymap, not an interactive function.

Michael.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: command-execute: Wrong type argument: commandp, helm-command-prefix
  2023-05-05  5:04     ` Michael Heerdegen
@ 2023-05-05  5:13       ` Hongyi Zhao
  2023-05-05  5:18       ` Ruijie Yu via Users list for the GNU Emacs text editor
  1 sibling, 0 replies; 8+ messages in thread
From: Hongyi Zhao @ 2023-05-05  5:13 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

On Fri, May 5, 2023 at 1:04 PM Michael Heerdegen
<michael_heerdegen@web.de> wrote:
>
> Ruijie Yu via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
> >     (autoload #'helm-command-prefix "helm-bibtex" nil t))
>                                                     ^^^^^
>
> Is this expected to work reliably?  AFAIU, the thing to be autoloaded is
> a keymap, not an interactive function.

But it really works smoothly, and you can check the example
configuration provided by the author of this package here [1]:

(require 'helm-config)

(global-set-key (kbd "<menu>") 'helm-command-prefix)

(define-key helm-command-map "b" 'helm-bibtex)
(define-key helm-command-map "B" 'helm-bibtex-with-local-bibliography)
(define-key helm-command-map "n" 'helm-bibtex-with-notes)
(define-key helm-command-map (kbd "<menu>") 'helm-resume)


[1] https://github.com/tmalsburg/helm-bibtex#key-bindings

> Michael.

Zhao



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: command-execute: Wrong type argument: commandp, helm-command-prefix
  2023-05-05  5:04     ` Michael Heerdegen
  2023-05-05  5:13       ` Hongyi Zhao
@ 2023-05-05  5:18       ` Ruijie Yu via Users list for the GNU Emacs text editor
  2023-05-05  5:59         ` Hongyi Zhao
  1 sibling, 1 reply; 8+ messages in thread
From: Ruijie Yu via Users list for the GNU Emacs text editor @ 2023-05-05  5:18 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs


Michael Heerdegen <michael_heerdegen@web.de> writes:

> Ruijie Yu via Users list for the GNU Emacs text editor
> <help-gnu-emacs@gnu.org> writes:
>
>>     (autoload #'helm-command-prefix "helm-bibtex" nil t))
>                                                     ^^^^^
>
> Is this expected to work reliably?  AFAIU, the thing to be autoloaded is
> a keymap, not an interactive function.
>
> Michael.

Exactly, hence my recommendation against using :bind for keymap
prefices.  Note that `helm-command-prefix' isn't even a function, yet
`use-package' marks it with function quote.

Note that the :bind-keymap expansion does not introduce this confusion.

-- 
Best,


RY

[Please note that this mail might go to spam due to some
misconfiguration in my mail server -- still investigating.]



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: command-execute: Wrong type argument: commandp, helm-command-prefix
  2023-05-05  5:18       ` Ruijie Yu via Users list for the GNU Emacs text editor
@ 2023-05-05  5:59         ` Hongyi Zhao
  0 siblings, 0 replies; 8+ messages in thread
From: Hongyi Zhao @ 2023-05-05  5:59 UTC (permalink / raw)
  To: Ruijie Yu; +Cc: Michael Heerdegen, help-gnu-emacs

On Fri, May 5, 2023 at 1:22 PM Ruijie Yu via Users list for the GNU
Emacs text editor <help-gnu-emacs@gnu.org> wrote:
>
>
> Michael Heerdegen <michael_heerdegen@web.de> writes:
>
> > Ruijie Yu via Users list for the GNU Emacs text editor
> > <help-gnu-emacs@gnu.org> writes:
> >
> >>     (autoload #'helm-command-prefix "helm-bibtex" nil t))
> >                                                     ^^^^^
> >
> > Is this expected to work reliably?  AFAIU, the thing to be autoloaded is
> > a keymap, not an interactive function.
> >
> > Michael.
>
> Exactly, hence my recommendation against using :bind for keymap
> prefices.  Note that `helm-command-prefix' isn't even a function, yet
> `use-package' marks it with function quote.
>
> Note that the :bind-keymap expansion does not introduce this confusion.

Please also refer to the document of use-package [1]:

Normally :bind expects that commands are functions that will be
autoloaded from the given package. However, this does not work if one
of those commands is actually a keymap, since keymaps are not
functions, and cannot be autoloaded using Emacs' autoload mechanism.

To handle this case, use-package offers a special, limited variant of
:bind called :bind-keymap. The only difference is that the "commands"
bound to by :bind-keymap must be keymaps defined in the package,
rather than command functions. This is handled behind the scenes by
generating custom code that loads the package containing the keymap,
and then re-executes your keypress after the first load, to
reinterpret that keypress as a prefix key.

For example:

(use-package projectile
  :bind-keymap
  ("C-c p" . projectile-command-map))

[1] https://github.com/jwiegley/use-package#binding-to-keymaps

> --
> Best,
>
>
> RY

Zhao

> [Please note that this mail might go to spam due to some
> misconfiguration in my mail server -- still investigating.]



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-05-05  5:59 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-05  0:34 command-execute: Wrong type argument: commandp, helm-command-prefix Hongyi Zhao
2023-05-05  1:40 ` Platon Pronko
2023-05-05  2:45   ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-05-05  4:18     ` Hongyi Zhao
2023-05-05  5:04     ` Michael Heerdegen
2023-05-05  5:13       ` Hongyi Zhao
2023-05-05  5:18       ` Ruijie Yu via Users list for the GNU Emacs text editor
2023-05-05  5:59         ` Hongyi Zhao

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.