Encouraged by comments in [https://www.reddit.com/r/emacs/comments/vjo43z/improving\_emacs\_performance/](https://www.reddit.com/r/emacs/comments/vjo43z/improving_emacs_performance/) \* I thought I'd have another look at my 'linting on save' snippet and ask the deep-thinkers here how I might improve it. It's almost perfect for me with **bash**(1) scripts - the only sand in the vaseline is that `next-error` skips over **shellcheck**(1) 'notes' and only points me at 'warnings' and worse. For example, in this output from **shellcheck**(1):
foobar:5:18: note: Double quote to prevent globbing and word splitting. [SC2086]
foobar:20:28: warning: ShellCheck can't follow non-constant source. Use a directive to specify location. [SC1090]
I would like `next-error` to visit occurrences of 'note's as well as more serious blues. Do I need to futz with `next-error-function`? If so, does anyone have the code for that?
Or perhaps there's some way to have **shellcheck**(1) promote 'notes' to 'warnings'?
Here's my miserable code:
(defun bh:check-syntax ()
"Check syntax for various languages."
(interactive)
(when (eq major-mode 'lisp-mode)
(progn
(emacs-lisp-byte-compile)))
(when (eq major-mode 'sh-mode)
(compile (format "bash -n %s && shellcheck -f gcc %s" buffer-file-name buffer-file-name) t))
(when (eq major-mode 'ruby-mode)
(shell-command (format "ruby -c %s" buffer-file-name)))
(when (eq major-mode 'python-mode)
(shell-command (format "python -B -m py_compile %s" buffer-file-name)))
(when (eq major-mode 'awk-mode)
(shell-command (format "gawk --source 'BEGIN { exit(0) } END { exit(0) }' --file %s" buffer-file-name))))
(add-hook 'after-save-hook #'bh:check-syntax)
\* the sub-discussion was about disabling flycheck as it's just too distracting - I prefer to do linting on save, and so do others, apparently.
**EDIT:** Finally got something working, thanks to u/ieure Here's my code (sorry if it stinks). It looks like the **shellcheck**(1) code for `next-error` does not support the default syntax nor the `shellcheck -f gcc syntax` (nor any other **shellcheck**(1) output syntax).
(defun bh:check-syntax ()
"Check syntax for various languages."
(interactive)
(when (eq major-mode 'lisp-mode)
(progn
(emacs-lisp-byte-compile)))
(when (eq major-mode 'sh-mode)
(compile (format "bash -n %s && shellcheck -f gcc %s" buffer-file-name buffer-file-name) t))
(when (eq major-mode 'ruby-mode)
(shell-command (format "ruby -c %s" buffer-file-name)))
(when (eq major-mode 'python-mode)
(shell-command (format "python -B -m py_compile %s" buffer-file-name)))
(when (eq major-mode 'awk-mode)
(shell-command (format "gawk --source 'BEGIN { exit(0) } END { exit(0) }' --file %s" buffer-file-name))))
(setq compilation-error-regexp-alist (append '(shellcheck-mine) compilation-error-regexp-alist))
(setq compilation-error-regexp-alist-alist (append '((shellcheck-mine
"^\\([^:]+\\):\\([0-9]+\\):\\([0-9]+\\): .*"
1 2 3)) compilation-error-regexp-alist-alist))
(add-hook 'after-save-hook #'bh:check-syntax)