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

Running global-flycheck-mode errors if no "Tools" menu on startup #2032

Open
AdamDorwart opened this issue Sep 6, 2023 · 3 comments
Open

Comments

@AdamDorwart
Copy link

AdamDorwart commented Sep 6, 2023

Bug description

When I start Doom Emacs I receive the following error on startup

⛔ Error (doom-first-buffer-hook): Error running hook "global-flycheck-mode" because: (wrong-type-argument keymapp nil)

Starting with --debug-init shows the following stacktrace

Debugger entered--Lisp error: (wrong-type-argument keymapp nil)
  #<subr define-key>(nil [menu-bar Tools] ("Tools" keymap "Tools"))
  general-unbind-non-prefix-key(#<subr define-key> nil [menu-bar Tools] ("Tools" keymap "Tools"))
  apply(general-unbind-non-prefix-key #<subr define-key> (nil [menu-bar Tools] ("Tools" keymap "Tools")))
  define-key(nil [menu-bar Tools] ("Tools" keymap "Tools"))
  easy-menu-get-map(nil ("Tools") nil)
  easy-menu-add-item(nil ("Tools") (keymap "Syntax Checking" (Enable\ on-the-fly\ syntax\ checking menu-item "Enable on-the-fly syntax checking" flycheck-mode :enable (or flycheck-mode (seq-find #'flycheck-checker-supports-major-mode-p flycheck-checkers)) :button (:toggle . flycheck-mode)) (Check\ current\ buffer menu-item "Check current buffer" flycheck-buffer :enable flycheck-mode) (Clear\ errors\ in\ buffer menu-item "Clear errors in buffer" flycheck-clear) (nil "--") (Go\ to\ next\ error menu-item "Go to next error" flycheck-next-error :enable flycheck-mode) (Go\ to\ previous\ error menu-item "Go to previous error" flycheck-previous-error :enable flycheck-mode) (Show\ all\ errors menu-item "Show all errors" flycheck-list-errors :enable flycheck-mode) (nil-7 "--") (Copy\ messages\ at\ point menu-item "Copy messages at point" flycheck-copy-errors-as-kill :enable (flycheck-overlays-at (point))) (Explain\ error\ at\ point menu-item "Explain error at point" flycheck-explain-error-at-point) (nil-10 "--") (Select\ syntax\ checker menu-item "Select syntax checker" flycheck-select-checker :enable flycheck-mode) (Disable\ syntax\ checker menu-item "Disable syntax checker" flycheck-disable-checker :enable flycheck-mode) (Set\ executable\ of\ syntax\ checker menu-item "Set executable of syntax checker" flycheck-set-checker-executable :enable flycheck-mode) (nil-14 "--") (Describe\ syntax\ checker menu-item "Describe syntax checker" flycheck-describe-checker) (Verify\ setup menu-item "Verify setup" flycheck-verify-setup) (Show\ Flycheck\ version menu-item "Show Flycheck version" flycheck-version) (Read\ the\ Flycheck\ manual menu-item "Read the Flycheck manual" flycheck-info)) "Spell Checking")
  global-flycheck-mode()
  funcall(global-flycheck-mode)
  (condition-case e (funcall hook) ((debug error) (signal 'doom-hook-error (list hook e))))
  doom-run-hook(global-flycheck-mode)
  run-hook-wrapped(doom-run-hook global-flycheck-mode)
  (let ((doom--hook hook)) (run-hook-wrapped hook #'doom-run-hook))
  (condition-case e (let ((doom--hook hook)) (run-hook-wrapped hook #'doom-run-hook)) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car (cdr e))) (symbol-name (car (cdr e))) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e)))))
  (let ((hook (car tail))) (condition-case e (let ((doom--hook hook)) (run-hook-wrapped hook #'doom-run-hook)) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp (car ...)) (symbol-name (car ...)) (car (cdr e))) (car (cdr (cdr e))))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq tail (cdr tail)))
  (while tail (let ((hook (car tail))) (condition-case e (let ((doom--hook hook)) (run-hook-wrapped hook #'doom-run-hook)) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if (symbolp ...) (symbol-name ...) (car ...)) (car (cdr ...)))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq tail (cdr tail))))
  (let ((tail hooks)) (while tail (let ((hook (car tail))) (condition-case e (let ((doom--hook hook)) (run-hook-wrapped hook #'doom-run-hook)) ((debug doom-hook-error) (if debug-on-error nil (lwarn hook :error "Error running hook %S because: %s" (if ... ... ...) (car ...))) (signal 'doom-hook-error (cons hook (cdr e))))) (setq tail (cdr tail)))))
  doom-run-hooks(doom-first-buffer-hook)
  (progn (setq running? t) (doom-run-hooks hook-var) (set hook-var nil))
  (if (and after-init-time (not running?) (or (daemonp) (and (boundp hook) (symbol-value hook)))) (progn (setq running? t) (doom-run-hooks hook-var) (set hook-var nil)))
  chain-doom-first-buffer-hook-to-doom-switch-buffer-hook-h()
  run-hooks(doom-switch-buffer-hook)
  (let ((gc-cons-threshold most-positive-fixnum) (inhibit-redisplay t)) (run-hooks 'doom-switch-buffer-hook))
  doom-run-switch-buffer-hooks-h(#<frame *doom* – Doom Emacs 0x14526c780>)
  redisplay_internal\ \(C\ function\)()

My personal Doom config.el removes the "Tools" menu-bar like so

(define-key global-map [menu-bar tools] nil)

If I remove that line from my configuration the startup error goes away but I would prefer removing that menu bar item. I'm still a pretty new Emacs user so I might not be aware of a better way to disable that menu bar. I suspect there's at least a problem with flycheck assuming that menu bar should exist because if I M-x global-flycheck-mode after startup it doesn't error but it also adds the "Tools" menu bar back with the "Syntax Checking" menu.

Maybe at a minimum their should be a configuration to disable Flycheck from adding to the "Tools" menu?

@AdamDorwart AdamDorwart changed the title Running global-flycheck-mode errors if no "Tools" menu-bar Running global-flycheck-mode errors if no "Tools" menu on startup Sep 6, 2023
@AdamDorwart
Copy link
Author

For reference, there were a couple other packages that use easy-menu that had configuration to disable their menus

(setq yas-use-menu nil)
(setq projectile-show-menu nil)

https://github.com/bbatsov/projectile/blob/master/projectile.el#L5926C14-L5926C14

@bbatsov
Copy link
Contributor

bbatsov commented Feb 11, 2024

I looked at this issue today, but solving it is a bit trickier than I thought. The main issue is that the menu is added at load-time, which means any config option will have effect only before Flycheck is loaded, which is usually quick confusing for the users. See https://github.com/flycheck/flycheck/blob/master/flycheck.el#L1233

I'm thinking the best solution might be to just suppress errors there, or check for the existence of the parent menu if I manage to find a function that does this.

@bbatsov
Copy link
Contributor

bbatsov commented Feb 11, 2024

There's a function named easy-menu-item-present-p that seems to do what we need, but I can't figure out how to use it. Sadly it's documentation is a bit on the spartan side and I couldn't find a single usage of this function anywhere. :(

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

No branches or pull requests

2 participants