-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add flymake integration #93
base: master
Are you sure you want to change the base?
Conversation
Flymake is a pretty good backend to report compiler errors to. Better than `compilation-mode`. This commit allows, if user calls `flymake-mode`, to automatically call a zig command. It is `zig build test` but can be `zig ast-check` or similar. The errors are automatically reported to the buffer. This works project-wide with correct locations. However, a small limitation is, that only one process can be spawned. This is because otherwise there would be much more code to check in a alist. (key would be either `(project-current)` or if nil `(current-buffer)`) I don't think it is a huge limitation, as the commands runs project-wide and most people won't run more than one project check at a time. In the reference implementation the command is ran per buffer, which this implementation does not support. And that is why the limitation is here compared to the flymake manual (https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html).
Why not create another package |
Every version of Emacs that zig-mode supports has a compatible modern |
(defun zig--setup-flymake-backend () | ||
(add-hook 'flymake-diagnostic-functions 'zig-flymake nil t)) | ||
|
||
(if zig-flymake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing this once at the top level is not going to work out well because changing zig-flymake after loading the file will make no difference. Better to add the zig--setup-flymake-backend to the default value of zig-mode-hook (which might mean adding an explicit defcustom for zig-mode-hook, or simply omit it and suggest that users call add-hook themselves.
If doing that, then you'd rename the function to zig-setup-flymake-backend because it's now effectively a public function.
zig--flymake-proc | ||
(make-process | ||
:name "zig-flymake" :noquery t :connection-type 'pipe | ||
:buffer (generate-new-buffer "*zig-flymake*") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Worth checking here whether this honours buffer-local exec-path
(ie. $PATH
) settings in the initial source buffer, which is necessary when using direnv
and envrc.el
to put a specific zig
on the path.
"Enable zig flymake integration." | ||
:type 'boolean | ||
:safe #'booleanp | ||
:group 'zig-mode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:group
is redundant in all these defcustom
s because it defaults to the group created by the defgroup
above.
Flymake is a pretty good backend to report compiler errors to. Better than
compilation-mode
. This commit allows, if user callsflymake-mode
, to automatically call a zig command. It iszig build test
but can bezig ast-check
or similar. The errors are automatically reported to the buffer. This works project-wide with correct locations.However, a small limitation is, that only one process can be spawned. This is because otherwise there would be much more code to check in a alist. (key would be either
(project-current)
or if nil(current-buffer)
)I don't think it is a huge limitation, as the commands runs project-wide and most people won't run more than one project check at a time.
In the reference implementation the command is ran per buffer, which this implementation does not support. And that is why the limitation is here compared to the flymake
manual (https://www.gnu.org/software/emacs/manual/html_node/flymake/An-annotated-example-backend.html).