Desired behaviour
While editing code blocks with org-mode
by pressing C-c ' I'd like Flycheck to resolve relevant configuration
the same way it does for normal files. I'm using JavaScript, and these are .jshintrc
files within the same ancestry.
To be more specific, I'd like the .jshintrc
settings to be picked up while editing code if I had my project arranged like this:
~/project/file.org
~/project/.jshintrc
This doesn't work, but is my ideal behavior.
Lame solution
The following setup works:
~/project/file.org
~/.jshintrc
But it's not desirable because it sets defaults across all my projects.
Possible solutions
I'm not sure if the following solutions are good ideas, and I'm unsure how implement them:
Set
buffer-file-name
of local buffer when editing source code blocks inorg-mode
.Add another function to
flycheck-locate-config-file-functions
.
Rationale
Looking at the Flycheck source, my "lame solution" works because Flycheck looks at the home directory in case other attempts to look up the configuration fail. This behavior is defined by flycheck-locate-config-file-functions
.
flycheck-locate-config-file-ancestor-directories
looks like the function I'd like to succeed in finding the configuration file. It looks like this:
(defun flycheck-locate-config-file-ancestor-directories (filename _checker)
"Locate a configuration FILENAME in ancestor directories.
If the current buffer has a file name, search FILENAME in the
directory of the current buffer and all ancestors thereof (see
`locate-dominating-file'). If the file is found, return its
absolute path. Otherwise return nil.
_CHECKER is ignored."
(-when-let* ((basefile (buffer-file-name))
(directory (locate-dominating-file basefile filename)))
(expand-file-name filename directory)))
So, if buffer-file-name
is set to an appropriate value we should be good. So what is its value for my code buffer? nil
. OK, so what are the effects of setting this variable locally for Org code buffers (and how do I do this whenever I enter from org-mode
with C-c ')?
Also, if I add my own look-up function to flycheck-locate-config-file-functions
, that may solve the problem. But how would I resolve the directory of the current .org
file from the buffer that lets me edit the JavaScript source?
A simpler solution is welcome as well.