1

I have a log library that has a autocmd log User hook, to show saved log or set it to a dedicated scratch buffer or etc.

It works quite well, but there is slight nuisance. When inspection/debug done, I clear the hook by au! log User. But then No matching autocommands: log User will show at cmdline constantly. Since the log#log function invoke doa log User.

Problem:
Is there a way to suppress the No matching autocommands: log User message when doa log User but no log User autocmd being set.
Or is there a function to check existence of a specified autocmd, if no one, then do not doa (to avoid No matching autocommands noise).

Failed attempts:

  • use sil doa, then hook that just echoes will never work. Unacceptable.
1
  • 1
    See :h exists()
    – Matt
    Jan 19 at 13:51

1 Answer 1

1

Thx to Matt's comment. Found the answer in :h exists.

the relevant part is.

    #event      autocommand defined for this event
    #event#pattern  autocommand defined for this event and
                    pattern (the pattern is taken
                    literally and compared to the
                    autocommand patterns character by
                    character)
    #group      autocommand group exists
    #group#event    autocommand defined for this group and
                    event.
    #group#event#pattern
                    autocommand defined for this group,
                    event and pattern.
    ##event     autocommand for this event is
                    supported.

thus answer for my case is

    if exists('#log#User')
        doa log User
    endif

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.