Open halloleo opened 4 years ago
Also, I think because nim-compile-default-command
is not designed as a file-local variable I cannot add values to the safe-local-variable-values
when opening a nim file.
This is my configuration:
(defun arne--get-nim-compile-command ()
"Calculate a good default compile command for Nim."
(let ((koch-dir (locate-dominating-file buffer-file-name "koch.nim"))
(nimble-dir (arne--locate-dominating-nimble-file)))
(cond
(koch-dir ;; in the compiler
(concat
"cd "
(shell-quote-argument
(file-relative-name koch-dir))
(cond ;; is test file in the test folder?
((string-match "^tests/.*/t[^/]*.nims?$" (file-relative-name buffer-file-name koch-dir))
"; testament/testament run ")
((string-match "nimsuggest/tests/t[^/]*.nim$" (file-relative-name buffer-file-name koch-dir))
"; nimsuggest/tester ")
(t
"; nim c -r "))
(shell-quote-argument
(file-relative-name buffer-file-name koch-dir))))
((string-match "\\.nims$" buffer-file-name)
(concat "nim e "
(shell-quote-argument
(file-relative-name buffer-file-name))))
(t
(concat "nim c -r "
(shell-quote-argument
(file-relative-name buffer-file-name)))))))
(defun arne--init-nim-mode ()
"Define some settings for the nim mode. Some ``imenu'' integration."
(when buffer-file-name
(setq-local compile-command (arne--get-nim-compile-command)))
(add-hook 'nim-mode-hook 'arne--init-nim-mode)
The idea here is: arne--get-nim-compile-command
implements some logic to determine a good default compile command. Then for compilation I am just using compile
, not nim-compile
. I never really understood the point of a distinct mode nim-compile
when compile
with a good default command works just fine. It also allows me to map compile
and recompile
to some keys globally and have this workflow work across programming languages.
The logic in arne--get-nim-compile-command
is not perfect. But it doesn't need to be, it is just a guess that should do what I need.
I try to set my own command line options for
nim-compile
as file local variables (like("js" "-r" "--verbosity:0" "--hint[Processing]:off" "--excessiveStackTrace:on")
.Only way I found to do this is setting
nim-compile-default-command
- despite the fact that this variable has the suffix-default-command
, but the variable contains neither the full command nor is it the default any more.Do I miss something? Or is this the recommended way?
I use Linux, emacs 26.2, nim-mode-20191219.847 and nim 1.2.6.