syntax-checking: added support for margin indicator

Before this commit, users are not informed of the option to use margins, in
addition to fringes, to display flycheck indicators. This commit provides
clearer information on customizing this. Specifically:

- Added instruction on how to change the location of flycheck indicator.
- Added a new layer variable `syntax-checking-indication-symbol` which allows
  customization for symbol used for flycheck indication.
- Deprecated the layer variable `syntax-checking-use-original-bitmaps` in favour
  of `syntax-checking-indication-symbol`, because the latter allows a finer
  control of both fringe bitmap and margin string.
This commit is contained in:
Lucius Hu 2022-07-14 02:08:01 -04:00
parent 09698dc8fa
commit 57d7cfee5c
No known key found for this signature in database
GPG key ID: 7E474E82E29B5A7A
3 changed files with 78 additions and 50 deletions

View file

@ -13,7 +13,7 @@
- [[#disabling-by-default][Disabling by default]]
- [[#enable-flycheck-globally][Enable flycheck globally]]
- [[#enable-support-for-traditional-error-navigation][Enable support for traditional error navigation]]
- [[#bitmaps][Bitmaps]]
- [[#error-indication][Error indication]]
- [[#auto-hide-tooltips][Auto hide tooltips]]
- [[#window-position-and-size][Window position and size]]
- [[#key-bindings][Key bindings]]
@ -86,13 +86,43 @@ to non-nil.
'((syntax-checking :variables syntax-checking-use-standard-error-navigation t)))
#+END_SRC
** Bitmaps
If the original flycheck fringe bitmaps are more to your liking, you can set the
variable =syntax-checking-use-original-bitmaps= to =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:
#+BEGIN_SRC emacs-lisp
(setq-default dotspacemacs-configuration-layers
'((syntax-checking :variables syntax-checking-use-original-bitmaps t)))
'((syntax-checking :variables
;; unset the first value to use flycheck's default fringe
syntax-checking-indication-symbol '(nil . nil)))
#+END_SRC
Or say if you want to display the indicator on the =left-margin= as an asterisk,
#+BEGIN_SRC emacs-lisp
(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 . "*"))))
#+END_SRC
** Auto hide tooltips

View file

@ -20,6 +20,25 @@
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; a small circle used for flycheck-indication-mode
(define-fringe-bitmap 'syntax-checking--fringe-indicator
(vector #b00000000
#b00000000
#b00000000
#b00000000
#b00000000
#b00000000
#b00000000
#b00011100
#b00111110
#b00111110
#b00111110
#b00011100
#b00000000
#b00000000
#b00000000
#b00000000
#b00000000))
;; Variables
@ -35,9 +54,24 @@
"Enable syntax-checking by default."
'(boolean))
(spacemacs|defc syntax-checking-use-original-bitmaps nil
"If non-nil, use the original bitmaps from flycheck."
'(boolean))
(define-obsolete-variable-alias 'syntax-checking-use-original-bitmaps
'syntax-checking-indication-symbol "July 2022"
"If non-nil, use the original bitmaps from flycheck.")
(spacemacs|defc syntax-checking-indication-symbol
'(syntax-checking--fringe-indicator . nil)
"The fringe bitmap or margin symbol used for `flycheck-indication-mode'.
The value is a cons cell (BITMAP . MARGIN-STR), in which a nil value means the default
symbol is chosen by `flycheck'.
BITMAP is a bitmap displayed in left or right fringe, which defaults to
a small circle as defined in `syntax-checking--fringe-indicator'.
MARGIN-STR is a string to be displayed in the margin (Defaults to nil).
Note only one of BITMAP and MARGIN-STR is used, which is dictated by
`flycheck-indication-mode'."
'(cons symbol string))
(spacemacs|defc syntax-checking-use-standard-error-navigation nil
"If non-nil hook into emacs standard error navigation."

View file

@ -59,48 +59,12 @@
:config
(progn
(spacemacs|diminish flycheck-mode "" " s")
;; Custom fringe indicator
(when (and (fboundp 'define-fringe-bitmap)
(not syntax-checking-use-original-bitmaps))
(define-fringe-bitmap 'my-flycheck-fringe-indicator
(vector #b00000000
#b00000000
#b00000000
#b00000000
#b00000000
#b00000000
#b00000000
#b00011100
#b00111110
#b00111110
#b00111110
#b00011100
#b00000000
#b00000000
#b00000000
#b00000000
#b00000000)))
(let ((bitmap (if syntax-checking-use-original-bitmaps
'flycheck-fringe-bitmap-double-arrow
'my-flycheck-fringe-indicator)))
(flycheck-define-error-level 'error
:severity 2
:overlay-category 'flycheck-error-overlay
:fringe-bitmap bitmap
:error-list-face 'flycheck-error-list-error
:fringe-face 'flycheck-fringe-error)
(flycheck-define-error-level 'warning
:severity 1
:overlay-category 'flycheck-warning-overlay
:fringe-bitmap bitmap
:error-list-face 'flycheck-error-list-warning
:fringe-face 'flycheck-fringe-warning)
(flycheck-define-error-level 'info
:severity 0
:overlay-category 'flycheck-info-overlay
:fringe-bitmap bitmap
:error-list-face 'flycheck-error-list-info
:fringe-face 'flycheck-fringe-info))
;; Custom fringe/margin indicator
(pcase-let ((`(,bitmap . ,margin-str) syntax-checking-indication-symbol))
(when (booleanp syntax-checking-use-original-bitmaps)
(warn "`syntax-checking-use-original-bitmaps' is deprecated. Use `syntax-checking-indication-symbol' instead.")
(setq bitmap (unless syntax-checking-use-original-bitmaps 'syntax-checking--fringe-indicator)))
(flycheck-redefine-standard-error-levels margin-str bitmap))
(evilified-state-evilify-map flycheck-error-list-mode-map
:mode flycheck-error-list-mode