use-package icon indicating copy to clipboard operation
use-package copied to clipboard

Since switching to this package randomly get "mode disabled in current buffer"

Open berenddeboer opened this issue 6 years ago • 2 comments

I'm switching from el-get to a combination of use-package and straight. However, I'm seeing very odd behaviour for certain buffers. For example this is my php-mode:

(use-package php-mode
  :straight t
  :requires (ggtags flycheck company)
  :config
  (setq php-template-compatibility nil)
  (setq tab-width 2)
  (setq c-basic-offset 2)
  :mode ("\\(\\.php\\|\\.inc\\)$" . php-mode)
  :hook (ggtags-mode company-mode flycheck-mode php-enable-drupal-coding-style)
)

However this often does not enable ggtags-mode or other modes. For example when trying to enable gg-tags-mode with M-x I see: "Ggtags mode disabled in current buffer."

Same for flycheck-mode for example. But it's random. Works in some buffers, not in others. Perhaps even one day it works in a buffer, but after a restart it won't work. Can't find any reason. When I try to debug ggtags-mode it seems ok, but still that message pops up from somewhere.

Any pointers on what's going on?

berenddeboer avatar May 18 '19 05:05 berenddeboer

Are you still seeing this? If so, could you try to provide a minimal example that would reproduce this issue? The above use-package declaration seems to require ggtags, flycheck, and company, but AFAICT you didn't provide the declarations for them?

Thanks.

skangas avatar Nov 29 '22 02:11 skangas

I think the use of :requires is incorrect/unnecessary here as none of these packages are dependencies of php-mode. The :mode line is unnecessary as php-mode already adds these file extensions to auto-mode-alist. In addition, I don't believe there is a ggtags-mode-hook, company-mode-hook or php-enable-drupal-coding-style-hook. There is a flycheck-mode-hook but that is provided to hook into flycheck-mode which I don't think is what you want to do. Instead, I think you want to enable ggtags-mode, company-mode, flycheck-mode and the php-enable-default-coding-style by hooking into php-mode which does provide a php-mode-hook.

Therefore, I believe the following use-package forms achieve what you want (untested):

(use-package php-mode
  :straight t
  :config
  (setq php-template-compatibility nil)
  (setq tab-width 2)  ;; This controls the display width of a TAB character, and not the size of an indentation step.
  (setq c-basic-offset 2)
  :hook (php-mode . php-enable-default-coding-style))

(use-package flycheck                  ;; Note, `php-mode' provides a backend for built-in flymake.
  :straight t
  :hook (php-mode . flycheck-mode))    ;; But would you not rather it be available in other modes?

(use-package ggtags
  :straight t
  :if (executable-find "ctags")        ;; Only loaded if you have universal-ctags installed.
  :hook (php-mode . ggtags-mode))

(use-package company
  :straight t
  :hook (php-mode . company-mode))    ;; But would you not rather it be available globally instead?

(use-package company-gtags            ;; Note it is not `company-ggtags'!
  :after (company ggtags)
  :config
  (add-to-list 'company-backends 'company-gtags))

Edit: With respect to this statement:

For example when trying to enable gg-tags-mode with M-x I see: "Ggtags mode disabled in current buffer."

If you saw this message in the echo area it is likely ggtags-mode was already enabled in the buffer in question and you disabled it when you invoked M-x ggtags-mode. In any case, with the above forms you should not have to enable any of these modes when you open a PHP file which I think is what you want.

doolio avatar Nov 29 '22 22:11 doolio