Open yantar92 opened 5 years ago
Right. Flycheck checks full buffers and. It doesn't understand mixed code. The fix might be simple if flycheck allows checking for regions then flycheck function could be re-bound to sniff only inner modes, but it would be very hard if there is no such provision.
Uninformed question here: how hard would it be for inner mode buffers to only contain the text in that inner section rather than the full buffer text?
For instance, imagine you had some file, file.org:
file.org:
#+title: some title
some text
#+begin_src c
int main()
{}
#+end_src
other text
Where the file.org[c] file would only consist of
int main()
{}
It seems like this could solve a number of existing as well as potential issues related to the one brought up here and that wouldn't rely on the capabilities of external tools. I believe I experienced a thematically-similar issue when using aggressive-indent-mode
with polymode, although it's been a while since I tried this. Code formatters come to mind as well.
I appreciate that I understand nothing of how polymode is implemented so please let me know if that's the case. However, I am curious about this.
Polymode relies on indirect buffers. All the inner mode buffers are inirect buffers derived from the initial buffer. Unfortunately, all indirect buffers must contain all the text of the initial buffer and all the changes in the indirect buffers automatically propagate to the initial buffer. I don't know any obvious way to make the text in the indirrect buffers differ from the initial buffer as in your example.
@vspinu On a side note, I am currently working (very very slowly, though) on a way to achieve indirect buffer-like functionality, which operates on regions of text. How feasible would it be to adapt polymode to such kind of functionality?
That's for sure not possible and I don't believe it's useful. In most of the non-trivial cases code in one chunk depends on the code in previous chunks. So isolating it in separate buffer is useless even for the flycheck example here.
What flycheck support for polymode should do, is to send to flycheck a temporary buffer/file with all the other spans except of the curent mode's ones commented out. This part should be straightforward enough. Unfortunately I am so busy till the end of the year and maybe beyond that I won't be able to look at this any time soon.
Is there a way to disable flycheck
while editing chunks
What flycheck support for polymode should do, is to send to flycheck a temporary buffer/file with all the other spans except of the curent mode's ones commented out.
I'd be happy to help with that. But commenting out may not be enough, since some checkers return errors as an offset from the start of the buffer, not as a line and column number.
Here's what I use for now, which disables Flycheck in indirect buffers.
(defun flycheck-buffer-not-indirect-p (&rest _)
"Ensure that the current buffer is not indirect."
(null (buffer-base-buffer)))
(advice-add 'flycheck-may-check-automatically
:before-while #'flycheck-buffer-not-indirect-p)
When flycheck is enabled in the major mode of code blocks, it actually checks all the org buffer when in poly-org mode. As a result, many flycheck errors are actually triggering on the text in buffer.