flycheck / flycheck-inline

Display Flycheck errors inline
GNU General Public License v3.0
137 stars 10 forks source link

doesn't load on initial run with use-package #10

Closed treymerkley closed 5 years ago

treymerkley commented 5 years ago

Thanks for developing this! I can see it making my workflow work that much better. I added this to my init file, along with the quick-peek snippet, to my config using use-package. When I run the daemon, the output states that flycheck-inline has been loaded. However, when I come across an error, I just get flycheck's default functionality.

The weird thing is, when I evaluate the buffer with the same text from within Emacs, everything runs just fine, with errors being displayed inline with the customizations.

How do I get it to work from initial load?

;; flycheck
(use-package flycheck
  :ensure t
  :init (global-flycheck-mode)
  :diminish flycheck-mode)

(use-package quick-peek
  :ensure t)

(use-package flycheck-inline
  :ensure t
  :config
  (global-flycheck-inline-mode)
  (setq flycheck-inline-display-function
        (lambda (msg pos)
          (let* ((ov (quick-peek-overlay-ensure-at pos))
                 (contents (quick-peek-overlay-contents ov)))
            (setf (quick-peek-overlay-contents ov)
                  (concat contents (when contents "\n") msg))
            (quick-peek-update ov)))
        flycheck-inline-clear-function #'quick-peek-hide)
  )
jcmdln commented 5 years ago

When starting emacs via emacsclient -ca '' and viewing my configuration, flycheck-inline appears to be working correctly for me. I don't currently use quick-peek though it does seem nice.

screenshot from 2019-01-03 09-22-14

It's possible I may be abusing use-package in my configuration, though here is an abbreviated look at how I have flycheck-inline configured:

(setq use-package-always-defer      t
      use-package-always-ensure     t
      use-package-check-before-init t)

(use-package flycheck
  :demand t
  :init
  (add-hook 'prog-mode-hook 'flycheck-mode))

(use-package flycheck-inline
  :demand t
  :init
  (add-hook 'flycheck-mode-hook #'turn-on-flycheck-inline))

I think you may want to swap :ensure t with :demand t, though this depends on how you have use-package configured. Here is the source for my config if it should be relevant: https://github.com/jcmdln/config/blob/master/etc/emacs/config.org

I hope this helps!

treymerkley commented 5 years ago

Thanks @jcmdln! Actually, after running through it again, it looks like inline is working everywhere but Lua, which happened to be what I was using to test that it was working. I'll try yours and see if it helps.

fmdkdd commented 5 years ago

@billywade I can reproduce. I'm guessing it it's something about the order between the two global minor modes, since removing the check to flycheck-mode in turn-on-flycheck-inline fixes it.

Adding the use-package for flycheck-inline before the one for flycheck also works. Since the hooks will run with the latest first, flycheck-mode gets a chance to turn on before turn-on-flycheck-inline is called, and checks for it.

This is totally counter-intuitive. Adding the hook as @jcmdln does is the surefire solution. I'm tempted to change the definition of global-flycheck-inline-mode to do just that.

@cpitclaudel Any thoughts of this? Or am I misunderstanding define-global-minor-mode?

cpitclaudel commented 5 years ago

AFAICT, adding to the flycheck-mode hook is a good solution. As an alternative, you could make flycheck-inline-mode do nothing in buffers in which flycheck-mode is disabled (rather than making it refuse to turn itself on).

fmdkdd commented 5 years ago

Thanks, I've pushed cf9eceabff8370f3b834b943a5777b9f914583f9 which adds a hook if flycheck-mode isn't active, so we catch the two possibilities.