doomemacs/modules/lang/nim/config.el
Henrik Lissner bfe7b9f1c4
lang/nim: fix invalid argument errors
The nimsuggest plugin tries to build a unique path for temporary files
for its flycheck checker. This path contains /tmp/emacs-nim-mode/A/B,
where A is the frame ID and B is the full path to the file being checked.

However, the original `nimsuggest--get-dirty-dir' incorrectly extracts
the frame ID from the string representation of `selected-frame' if
frame-title-format has been modified (which Doom has). The result is the
title of the frame, which can contain illegal path characters in
Windows, which in turn causes invalid argument errors when
`nimsuggest--make-tempdir' tries to use it.

This should really be reported upstream!
2018-08-30 22:35:25 +02:00

32 lines
1.3 KiB
EmacsLisp

;;; lang/nim/config.el -*- lexical-binding: t; -*-
(after! nim-mode
(defun +nim|init-nimsuggest-mode ()
"Conditionally load `nimsuggest-mode', instead of clumsily erroring out if
nimsuggest isn't installed."
(unless (stringp nimsuggest-path)
(setq nimsuggest-path (executable-find "nimsuggest")))
(when (and nimsuggest-path (file-executable-p nimsuggest-path))
(nimsuggest-mode)))
(add-hook 'nim-mode-hook #'+nim|init-nimsuggest-mode)
(defun doom*nimsuggest--get-dirty-dir ()
"The original `nimsuggest--get-dirty-dir' incorrectly extracts the frame
number from the string representation of `selected-frame', which can contain
characters that are illegal on Windows, causing invalid argument errors when
`nimsuggest--make-tempdir' tries to use it."
(let* ((frame-str (format "%s" (selected-frame)))
(frame-num-str (if (string-match " \\(0x[0-9a-z]+\\)>$" frame-str)
(match-string 1 frame-str))))
(file-name-as-directory (concat nimsuggest-dirty-directory frame-num-str))))
(advice-add #'nimsuggest--get-dirty-dir :override #'doom*nimsuggest--get-dirty-dir)
(map! :map nim-mode-map
:localleader
:n "b" #'nim-compile))
(def-package! flycheck-nim
:when (featurep! :feature syntax-checker)
:after nim-mode)