Skip to content
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

How to set my own comamnd line options for nim-compile #231

Open
halloleo opened this issue Aug 24, 2020 · 3 comments
Open

How to set my own comamnd line options for nim-compile #231

halloleo opened this issue Aug 24, 2020 · 3 comments

Comments

@halloleo
Copy link

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.

@halloleo
Copy link
Author

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.

@krux02
Copy link
Contributor

krux02 commented Aug 24, 2020

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.

@halloleo
Copy link
Author

Thanks @krux02 for chiming in! :-) Will try your custom compile-command.

Normally I use compile and recompile for all sorts of stuff (like invoke tasks), but I thought if nim-mode has its own compile I might use it...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants