This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+checkers/syntax-checking/README.org
Lucius Hu 5ce944a1da
syntax-highlighting: improved docs on pop window configuratin
This commit improved both the layer documentation of pop window configuration
and docstring of relavant layer variables.
2022-07-14 03:53:10 -04:00

7.6 KiB

Syntax Checking layer

/TakeV/spacemacs/media/commit/5ce944a1da462855f86464e5f474fc611ef035f9/layers/+checkers/syntax-checking/img/flycheck.png

Description

This layer adds on the fly syntax checking to all supported language layers.

Features:

  • Support for automatic syntax checking with Flycheck for various language layers
  • Tooltip syntax errors with popwin

Install

Layer

To use this configuration layer, add it to your ~/.spacemacs. You will need to add syntax-checking to the existing dotspacemacs-configuration-layers list in this file.

As this is a support layer you will also have to install at least one supported language layer for it to have any effect.

Enabling/Disabling tooltips

By default tooltips are enabled and used whenever it is possible. You can disable them by setting the variable syntax-checking-enable-tooltips to nil:

  (setq-default dotspacemacs-configuration-layers
    '((syntax-checking :variables syntax-checking-enable-tooltips nil)))

Disabling by default

By default, syntax-checking is enabled in all available major modes (except for emacs-lisp-mode) and may be toggled off with SPC t s. You can default this to off by setting the variable syntax-checking-enable-by-default to nil:

  (setq-default dotspacemacs-configuration-layers
    '((syntax-checking :variables syntax-checking-enable-by-default nil)))

If you want more fine-grained control, you can configure the variable flycheck-global-modes instead. Note that this variable should be manipulated in dotspacemacs/user-config.

Enable flycheck globally

Normally Spacemacs goes a long mile to enable syntax checking only where it makes sense. If syntax checking support is missing it is normally only a matter of declaring it in the layer. The best approach in this case is to open an issue and ask for syntax checking support.

Some guides on the web suggest to enable flycheck globally by setting (global-flycheck-mode) in your dotspacemacs/user-config. This is neither necessary nor is it good for the layer system. In the contrary by doing so the layer system cannot longer decide for which modes activating flycheck would bring any useful outcome. This may result in loading slow or not properly configured checkers as well as break some of the more advanced configuration settings of the layer system.

Enable support for traditional error navigation

By default spacemacs takes care to call the right function to jump to the next or previous error. However if wished flycheck can also override next-error and previous-error respectively allowing to use alternative general emacs bindings instead of the spacemacs specific ones. To do so set syntax-checking-use-standard-error-navigation to non-nil.

  (setq-default dotspacemacs-configuration-layers
    '((syntax-checking :variables syntax-checking-use-standard-error-navigation t)))

Error indication

By default, errors are indicated by a small circle on the left fringe of each window. The position of the indicator changed via flycheck-indication-mode.

If flycheck-indication-mode is set to left-fringe or right-fringe, a bitmap is used for fringe indicator. Where the bitmap is a string or a vector of bits, see define-fringe-bitmap for details. The default fringe bitmap in Spacemacs is a small solid circle.

If flycheck-indication-mode is set to left-margin or right-margin, a string is used for margin indicator. Spacemacs doesn't change the margin string so the default value is defined in flycheck.

If flycheck-indication-mode is nil, no indicator is displayed.

To change the fringe or margin indicator, you can customize syntax-checking-indicatin-symbol, which is cons cell of a fringe bitmap and margin string. When any of the element is nil, it's left to flycheck to determine a default indicator.

For example, if you prefer the original fringe bitmap to Spacemacs's default:

  (setq-default dotspacemacs-configuration-layers
    '((syntax-checking :variables
                       ;; unset the first value to use flycheck's default fringe
                       syntax-checking-indication-symbol '(nil . nil)))

Or say if you want to display the indicator on the left-margin as an asterisk,

  (setq-default dotspacemacs-configuration-layers
    '((syntax-checking :variables
                       flycheck-indication-mode 'left-margin
                       ;; set the second value for custom margin string
                       syntax-checking-indication-symbol '(nil . "*"))))

Auto hide tooltips

You can set time in seconds after which tooltips are automatically hidden by setting the variable syntax-checking-auto-hide-tooltips to a positive number of seconds.

Default value of syntax-checking-auto-hide-tooltips is nil, and in that case tooltips are kept open until the cursor is moved.

  (setq-default dotspacemacs-configuration-layers
    '((syntax-checking :variables syntax-checking-auto-hide-tooltips 10)))

Error list pop window configuration

By default, the flycheck-error-list is displayed in a pop window to the bottom of the frame, with 30% of the frame's height.

You can customize where the pop window is shown by setting the variable syntax-checking-window-position to one of 'bottom, 'top, 'left, and 'right.

You can also set the initial window width and height by setting syntax-checking-window-width and syntax-checking-window-height respectively, where an integer value is the number of columns it takes while a float value is the relative size to the current frame.

For example, to have the pop window appear on the right side of the frame with 60 columns:

  (setq-default dotspacemacs-configuration-layers
    '((syntax-checking :variables
                       syntax-checking-window-position 'right
                       syntax-checking-window-width 60

Key bindings

Key binding Description
SPC e b check for errors now
SPC e c clear errors
SPC e d disable a checker in current buffer
SPC e h describe flycheck checker
SPC e l display a list of all the errors
SPC e L display a list of all the errors and focus the errors buffer
SPC e s set flycheck checker
SPC e S set flycheck checker executable
SPC e v verify flycheck setup
SPC t s toggle flycheck
SPC e x explain the error at point