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

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

Open
mohkale opened this issue Jan 11, 2021 · 1 comment
Open

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

mohkale opened this issue Jan 11, 2021 · 1 comment

Comments

@mohkale
Copy link

mohkale commented Jan 11, 2021

Basic Info

  • uname -a: Linux mk-desktop 5.9.14-arch1-1 #1 SMP PREEMPT Sat, 12 Dec 2020 14:37:12 +0000 x86_64 GNU/Linux
  • emacs: GNU Emacs 27.1 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.22, cairo version 1.17.3) of 2020-08-28
  • nim: Nim Compiler Version 1.4.2 [Linux: amd64]
  • nimsuggest: Nim Compiler Version 1.4.2 [Linux: amd64], but I'm using nimlsp with eglot instead of this.

*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.

nim-mode/nim-compile.el

Lines 136 to 140 in d832d6b

(defun nim-compile--assert (command)
"Check COMMAND.
Basically copied from `compile-command's document."
(and (stringp command)
(or (not (boundp (quote compilation-read-command))) compilation-read-command)))

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
Copy link
Contributor

krux02 commented Jan 13, 2021

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.

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