spacemacs/layers/+lang/typescript/funcs.el
Miciah Dashiel Butler Masters 78297be625 Fix various typos
* Fix various isolated typos

"apppend" -> "append"

"availabe" -> "available"

"Descripti using ternon" -> "Description"

"you have not them" -> "you don't have them"

"new on" -> "new one"

"plained" -> "curved"

"repel" -> "REPL"

"vairable" -> "variable"

* Fix a few errors in the CoffeeScript layer readme

Add a missing "the".

Correct a reference to the layer as "javascript" to "coffeescript".

Fix the syntax on the link to CoffeeLint.

* Fix typos: "dofile" -> "dotfile"

* Fix typos: "formated" and "formating"

"formated" -> "formatted"

"formating" -> "formatting"

* hy: Fix docstrings in funcs.el

Fix copy-and-pasted docstring text for
spacemacs/hy-shell-eval-current-form-and-go and
spacemacs/hy-shell-eval-region-and-go.

* Fix typos: "indendation" -> "indentation"

* Fix typos: "the the", "a a"

Fix duplicated (or misplaced) articles.

* Fix typos: "wether" -> "whether"

* Fix typos: "intialize" -> "initialize"
2018-05-23 22:12:30 -04:00

153 lines
5.4 KiB
EmacsLisp
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

;;; funcs.el --- TypeScript Layer functions File for Spacemacs
;;
;; Copyright (c) 2012-2018 Sylvain Benner & Contributors
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; backend
(defun spacemacs//typescript-setup-backend ()
"Conditionally setup typescript backend."
(pcase typescript-backend
(`tide (spacemacs//typescript-setup-tide))
(`lsp (spacemacs//typescript-setup-lsp))))
(defun spacemacs//typescript-setup-company ()
"Conditionally setup company based on backend."
(pcase typescript-backend
(`tide (spacemacs//typescript-setup-tide-company))
(`lsp (spacemacs//typescript-setup-lsp-company))))
(defun spacemacs//typescript-setup-eldoc ()
"Conditionally setup eldoc based on backend."
(pcase typescript-backend
(`tide (spacemacs//typescript-setup-tide-eldoc))
(`lsp (spacemacs//typescript-setup-lsp-eldoc))))
;; tide
(defun spacemacs//typescript-setup-tide ()
"Setup tide backend."
(progn
(evilified-state-evilify tide-references-mode tide-references-mode-map
(kbd "C-k") 'tide-find-previous-reference
(kbd "C-j") 'tide-find-next-reference
(kbd "C-l") 'tide-goto-reference)
(add-to-list 'spacemacs-jump-handlers-typescript-tsx-mode
'(tide-jump-to-definition :async t))
(add-to-list 'spacemacs-jump-handlers-typescript-mode
'(tide-jump-to-definition :async t))
(tide-setup)))
(defun spacemacs//typescript-setup-tide-company ()
"Setup tide auto-completion."
(spacemacs|add-company-backends
:backends company-tide
:modes typescript-mode typescript-tsx-mode
:variables
company-minimum-prefix-length 2)
(company-mode))
(defun spacemacs//typescript-setup-tide-eldoc ()
"Setup eldoc for tide."
(eldoc-mode))
;; lsp
(defun spacemacs//typescript-setup-lsp ()
"Setup lsp backend."
(if (configuration-layer/layer-used-p 'lsp)
(progn
(spacemacs//setup-lsp-jump-handler 'typescript-mode
'typescript-tsx-mode)
(lsp-javascript-typescript-enable))
(message (concat "`lsp' layer is not installed, "
"please add `lsp' layer to your dotfile."))))
(defun spacemacs//typescript-setup-lsp-company ()
"Setup lsp auto-completion."
(if (configuration-layer/layer-used-p 'lsp)
(progn
(fix-lsp-company-prefix)
(spacemacs|add-company-backends
:backends company-lsp
:modes typescript-mode typescript-tsx-mode
:variables company-minimum-prefix-length 2
:append-hooks nil
:call-hooks t)
(company-mode))
(message (concat "`lsp' layer is not installed, "
"please add `lsp' layer to your dotfile."))))
(defun spacemacs//typescript-setup-lsp-eldoc ()
"Setup eldoc for LSP."
(eldoc-mode))
;; Others
(defun spacemacs/typescript-tsfmt-format-buffer ()
"Format buffer with tsfmt."
(interactive)
(if (executable-find "tsfmt")
(let* ((extension (file-name-extension (or buffer-file-name "tmp.ts") 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.ts*")))
(unwind-protect
(progn
(with-current-buffer outputbuf (erase-buffer))
(write-region nil nil tmpfile)
(if (zerop (apply 'call-process "tsfmt" nil outputbuf nil
(list (format
"--baseDir='%s' --"
default-directory)
tmpfile)))
(let ((p (point)))
(save-excursion
(with-current-buffer (current-buffer)
(erase-buffer)
(insert-buffer-substring outputbuf)))
(goto-char p)
(message "formatted.")
(kill-buffer outputbuf))
(progn
(message "Formatting failed!")
(display-buffer outputbuf)))
(progn
(delete-file tmpfile)))))
(error "tsfmt not found. Run \"npm install -g typescript-formatter\"")))
(defun spacemacs/typescript-format ()
"Call formatting tool specified in `typescript-fmt-tool'."
(interactive)
(cond
((eq typescript-fmt-tool 'typescript-formatter)
(call-interactively 'spacemacs/typescript-tsfmt-format-buffer))
((eq typescript-fmt-tool 'tide)
(call-interactively 'tide-format))
(t (error (concat "%s isn't valid typescript-fmt-tool value."
" It should be 'tide or 'typescript-formatter."
(symbol-name typescript-fmt-tool))))))
(defun spacemacs/typescript-fmt-before-save-hook ()
(add-hook 'before-save-hook 'spacemacs/typescript-format t t))
(defun spacemacs/typescript-open-region-in-playground (start end)
"Open selected region in http://www.typescriptlang.org/Playground
If nothing is selected - open the whole current buffer."
(interactive (if (use-region-p)
(list (region-beginning) (region-end))
(list (point-min) (point-max))))
(browse-url (concat "http://www.typescriptlang.org/Playground#src="
(url-hexify-string (buffer-substring-no-properties start end)))))