<commit_before>;;; 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)
<commit_msg>lang/nim: fix invalid chars in nimsuggest tmp path<commit_after>;;; 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)

  (when IS-WINDOWS
    ;; TODO File PR/report upstream (https://github.com/nim-lang/nim-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)
    
    ;; TODO File PR/report upstream (https://github.com/nim-lang/nim-mode)
    (defun doom*nimsuggest--get-temp-file-name (path)
      "Removes invalid characters from the temp file path, including the unicode
character that colon is replaced with, which is known to cause issues on
windows."
      (replace-regexp-in-string "[꞉* |<>\"?*]" "" path))
    (advice-remove #'nimsuggest--get-temp-file-name :filter-return #'doom*nimsuggest--get-temp-file-name))

  (map! :map nim-mode-map
        :localleader
        :n "b" #'nim-compile))


(def-package! flycheck-nim
  :when (featurep! :feature syntax-checker)
  :after nim-mode)

{'fraction_non_alphanumeric': 0.14940783480109324, 'fraction_numerical': 0.0024293956878226543, 'mean_word_length': 3.38031914893617, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6508989', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1094, 'n_words': 268}