Skip to content

Commit

Permalink
Merge pull request #6 from zw963/master
Browse files Browse the repository at this point in the history
Fix mint-format-file
  • Loading branch information
creatorrr committed Sep 11, 2022
2 parents 50d849e + 54fd0dc commit e34cd93
Showing 1 changed file with 9 additions and 5 deletions.
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

0 comments on commit e34cd93

Please sign in to comment.