nim-lang / nim-mode

An emacs major mode for the Nim programming language
137 stars 46 forks source link

nim-compile: Something goes wrong because of nim-compile--assert #235

Open mohkale opened 3 years ago

mohkale commented 3 years ago

Basic Info

*Messages*

nim-compile: Something goes wrong

README read?

Yes

Problem

When I run nim-compile nim just echos something goes wrong and nothing happend. I think this is because of nim-compile--assert.

https://github.com/nim-lang/nim-mode/blob/d832d6b1fb5e69fedcdddf442d62251dd0f1f489/nim-compile.el#L136-L140

I'm pretty sure that first and is supposed to be an or (use the current command or read a new one when the current one isn't given) and the latter case just seems to check whether compilation-read-command is bound and return but it doesn't actually read the command.

This alternative implementation works for me:

(defun nim-compile--assert (command)
  "Check COMMAND.
Basically copied from `compile-command's document."
  (or (stringp command)
      (and (bound-and-true-p compilation-read-command)
           (compilation-read-command))))
krux02 commented 3 years ago

I just use compile instead of nim-compile because of problems like this. Here is how it works:

(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)))))))-name buffer-file-name)))))))

[...]
;; in arne--init-nim-mode
(setq-local compile-command (arne--get-nim-compile-command))

I did not minify arne--get-nim-compile-command though at all. You can make it much smaller and you probably should.