2020-10-23 16:57:47 +00:00
|
|
|
;;; funcs.el --- PureScript Layer functions File for Spacemacs
|
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2020-10-23 16:57:47 +00:00
|
|
|
;;
|
|
|
|
;; Author: nobv <6e6f6276@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
2021-03-24 03:31:44 +00:00
|
|
|
;; This program is free software; you can redistribute it and/or modify
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
;; (at your option) any later version.
|
|
|
|
;;
|
|
|
|
;; This program is distributed in the hope that it will be useful,
|
|
|
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;; GNU General Public License for more details.
|
|
|
|
;;
|
|
|
|
;; You should have received a copy of the GNU General Public License
|
|
|
|
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2020-10-23 16:57:47 +00:00
|
|
|
|
2021-02-10 07:51:55 +00:00
|
|
|
(defun spacemacs//purescript-setup-backend ()
|
2020-10-23 16:57:47 +00:00
|
|
|
"Conditionally setup purescript backend."
|
2021-03-18 04:52:22 +00:00
|
|
|
(when (eq purescript-backend 'lsp)
|
2021-06-06 20:25:00 +00:00
|
|
|
(lsp-deferred)))
|
2020-10-23 16:57:47 +00:00
|
|
|
|
|
|
|
(defun spacemacs//purescript-setup-company ()
|
|
|
|
"Conditionally setup company based on backend."
|
2021-04-05 05:22:02 +00:00
|
|
|
(pcase purescript-backend
|
|
|
|
('lsp
|
|
|
|
(spacemacs|add-company-backends ;; Activate lsp company explicitly to activate
|
|
|
|
:backends company-capf ;; standard backends as well
|
|
|
|
:modes purescript-mode))
|
|
|
|
('psc-ide
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
:backends company-psc-ide-backend
|
|
|
|
:modes purescript-mode))))
|
2021-08-20 03:48:29 +00:00
|
|
|
|
|
|
|
(defun spacemacs/purescript-format ()
|
|
|
|
"Call formatting tool specified in `purescript-fmt-tool'."
|
|
|
|
(interactive)
|
|
|
|
(call-interactively
|
|
|
|
(pcase purescript-fmt-tool
|
|
|
|
('purs-tidy 'spacemacs/purescript-purs-tidy-format-buffer)
|
|
|
|
(_ (user-error
|
|
|
|
"%s isn't a valid purescript formatter. Possible values are 'purs-tidy"
|
|
|
|
purescript-fmt-tool)))))
|
|
|
|
|
|
|
|
(defun spacemacs/purescript-purs-tidy-format-buffer ()
|
|
|
|
"Format buffer with purs-tidy."
|
|
|
|
(interactive)
|
|
|
|
(if (executable-find "purs-tidy")
|
|
|
|
(let* ((extension (file-name-extension (or buffer-file-name "tmp.purs") t))
|
|
|
|
(tmpfile (make-temp-file "~fmt-tmp" nil extension))
|
|
|
|
(coding-system-for-read 'utf-8)
|
|
|
|
(coding-system-for-write 'utf-8)
|
|
|
|
(outputbuf (get-buffer-create "*~fmt-tmp.purs*")))
|
|
|
|
(unwind-protect
|
|
|
|
(progn
|
|
|
|
(with-current-buffer outputbuf (erase-buffer))
|
|
|
|
(write-region nil nil tmpfile)
|
|
|
|
(if (zerop (apply #'call-process-region nil nil "purs-tidy" nil
|
|
|
|
`(,outputbuf ,tmpfile) nil
|
|
|
|
`("format")))
|
|
|
|
(let ((p (point)))
|
|
|
|
(save-excursion
|
|
|
|
(with-current-buffer (current-buffer)
|
|
|
|
(replace-buffer-contents outputbuf)))
|
|
|
|
(goto-char p)
|
|
|
|
(message "formatted.")
|
|
|
|
(kill-buffer outputbuf))
|
|
|
|
(message "Formatting failed!")
|
|
|
|
(display-buffer outputbuf)))
|
|
|
|
(delete-file tmpfile)))
|
|
|
|
(error "purs-tidy not found. Run \"npm install -g purs-tidy\"")))
|
|
|
|
|
|
|
|
(defun spacemacs/purescript-fmt-before-save-hook ()
|
|
|
|
(add-hook 'before-save-hook 'spacemacs/purescript-format t t))
|