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

Fix mint-format-file #6

Merged
merged 3 commits into from
Sep 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 9 additions & 5 deletions mint-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
;; For compound type constructors like `Maybe(Number)`
(regex-compound-type-constructors
(mapconcat (lambda (type)
(concat (regexp-quote type) "[[:space:]]*" "("))
(concat "\\b" (regexp-quote type) "[[:space:]]*" "("))

mint-lang-compound-types
"\\|") )
Expand Down Expand Up @@ -217,13 +217,20 @@
:company-doc-buffer (lambda (cand)
(company-doc-buffer (format "'%s' is defined in mint-mode plugin" cand))) )) ))

(defun format-all--locate-file (filename)
"Internal helper to locate dominating copy of FILENAME for current buffer."
(let* ((dir (and (buffer-file-name)
(locate-dominating-file (buffer-file-name) filename))))
(when dir (expand-file-name (concat dir filename)))))

;; Function for reformatting .mint source files
(defun mint-format-file ()
"Formats current file using `mint format`."

(let* ((file buffer-file-name)
(error-file (make-temp-file "mint-format-errors-file"))
(command (concat "mint format " file " > " error-file))
(default-directory (file-name-directory (format-all--locate-file "mint.json")))

;; Error container
(error-buffer (get-buffer-create "*prettier errors*"))
Expand All @@ -237,7 +244,7 @@
(result (call-process-shell-command command nil nil nil)) )

;; Check command result
(if (zerop result)
(if (or (zerop result) (eq 1 result))

;; Update formatted file and destroy error-buffer
(progn
Expand Down Expand Up @@ -265,9 +272,6 @@
;; Register auto complete fn
(push 'mint-keyword-completion-at-point completion-at-point-functions)

;; hook for formatting on save
(add-hook 'mint-mode-hook (lambda () (add-hook 'after-save-hook #'mint-format-file nil 'local)))

;; For correctly formatting ansi terminal color codes
(add-to-list 'comint-output-filter-functions 'ansi-color-process-output)
(add-hook 'compilation-mode-hook 'ansi-color-for-comint-mode-on)
Expand Down