2015-01-14 04:12:56 +00:00
|
|
|
;;; funcs.el --- Scala Layer functions File for Spacemacs
|
|
|
|
;;
|
2016-01-12 02:40:54 +00:00
|
|
|
;; Copyright (c) 2012-2016 Sylvain Benner & Contributors
|
2015-01-14 04:12:56 +00:00
|
|
|
;;
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
|
|
|
|
;; URL: https://github.com/syl20bnr/spacemacs
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
2015-01-03 02:30:17 +00:00
|
|
|
;;; Ensime
|
|
|
|
|
2015-02-20 07:41:28 +00:00
|
|
|
(autoload 'ensime-config-find-file "ensime-config")
|
|
|
|
(autoload 'ensime-config-find "ensime-config")
|
|
|
|
(autoload 'projectile-project-p "projectile")
|
|
|
|
|
2015-01-03 04:18:31 +00:00
|
|
|
(defun scala/configure-ensime ()
|
|
|
|
"Ensure the file exists before starting `ensime-mode'."
|
2015-04-02 20:36:40 +00:00
|
|
|
(cond
|
|
|
|
((and (buffer-file-name) (file-exists-p (buffer-file-name)))
|
|
|
|
(ensime-mode +1))
|
|
|
|
((buffer-file-name)
|
|
|
|
(add-hook 'after-save-hook (lambda () (ensime-mode +1)) nil t))))
|
2015-01-03 04:18:31 +00:00
|
|
|
|
2015-02-20 07:41:28 +00:00
|
|
|
(defun scala/maybe-start-ensime ()
|
|
|
|
(when (buffer-file-name)
|
|
|
|
(let ((ensime-buffer (scala/ensime-buffer-for-file (buffer-file-name)))
|
|
|
|
(file (ensime-config-find-file (buffer-file-name)))
|
|
|
|
(is-source-file (s-matches? (rx (or "/src/" "/test/")) (buffer-file-name))))
|
|
|
|
|
|
|
|
(when (and is-source-file (null ensime-buffer))
|
|
|
|
(noflet ((ensime-config-find (&rest _) file))
|
|
|
|
(save-window-excursion
|
|
|
|
(ensime)))))))
|
|
|
|
|
|
|
|
(defun scala/ensime-buffer-for-file (file)
|
|
|
|
"Find the Ensime server buffer corresponding to FILE."
|
|
|
|
(let ((default-directory (file-name-directory file)))
|
|
|
|
(-when-let (project-name (projectile-project-p))
|
|
|
|
(--first (-when-let (bufname (buffer-name it))
|
|
|
|
(and (s-contains? "inferior-ensime-server" bufname)
|
|
|
|
(s-contains? (file-name-nondirectory project-name) bufname)))
|
|
|
|
(buffer-list)))))
|
|
|
|
|
2015-02-20 09:26:13 +00:00
|
|
|
(defun scala/enable-eldoc ()
|
|
|
|
(setq-local eldoc-documentation-function
|
|
|
|
(lambda ()
|
|
|
|
(when (ensime-connected-p)
|
|
|
|
(ensime-print-type-at-point))))
|
2015-11-23 19:09:57 +00:00
|
|
|
(eldoc-mode +1))
|
2015-02-20 09:26:13 +00:00
|
|
|
|
2014-12-29 20:40:56 +00:00
|
|
|
(defun spacemacs/ensime-refactor-accept ()
|
|
|
|
(interactive)
|
|
|
|
(funcall continue-refactor)
|
|
|
|
(ensime-popup-buffer-quit-function))
|
|
|
|
|
|
|
|
(defun spacemacs/ensime-refactor-cancel ()
|
|
|
|
(interactive)
|
|
|
|
(funcall cancel-refactor)
|
|
|
|
(ensime-popup-buffer-quit-function))
|
|
|
|
|
2015-01-03 02:30:17 +00:00
|
|
|
;;; Interactive commands
|
|
|
|
|
2014-12-29 20:40:56 +00:00
|
|
|
(defun spacemacs/scala-join-line ()
|
|
|
|
"Adapt `scala-indent:join-line' to behave more like evil's line join.
|
|
|
|
|
|
|
|
`scala-indent:join-line' acts like the vanilla `join-line',
|
|
|
|
joining the current line with the previous one. The vimmy way is
|
|
|
|
to join the current line with the next.
|
|
|
|
|
|
|
|
Try to move to the subsequent line and then join. Then manually move
|
|
|
|
point to the position of the join."
|
|
|
|
(interactive)
|
|
|
|
(let (join-pos)
|
|
|
|
(save-excursion
|
|
|
|
(goto-char (line-end-position))
|
|
|
|
(unless (eobp)
|
|
|
|
(forward-line)
|
|
|
|
(call-interactively 'scala-indent:join-line)
|
|
|
|
(setq join-pos (point))))
|
|
|
|
|
|
|
|
(when join-pos
|
|
|
|
(goto-char join-pos))))
|
2015-01-03 02:30:17 +00:00
|
|
|
|
|
|
|
(defun scala/completing-dot ()
|
|
|
|
"Insert a period and show company completions."
|
|
|
|
(interactive "*")
|
|
|
|
(when (s-matches? (rx (+ (not space)))
|
|
|
|
(buffer-substring (line-beginning-position) (point)))
|
|
|
|
(delete-horizontal-space t))
|
2016-07-10 21:04:22 +00:00
|
|
|
(company-abort)
|
2015-11-25 04:57:47 +00:00
|
|
|
(insert ".")
|
|
|
|
(company-complete))
|
2015-01-03 02:30:17 +00:00
|
|
|
|
2015-01-03 02:29:02 +00:00
|
|
|
;;; Flyspell
|
|
|
|
|
|
|
|
(defun scala/flyspell-verify ()
|
|
|
|
"Prevent common flyspell false positives in scala-mode."
|
|
|
|
(and (flyspell-generic-progmode-verify)
|
|
|
|
(not (s-matches? (rx bol (* space) "package") (current-line)))))
|
|
|
|
|
|
|
|
(defun scala/configure-flyspell ()
|
|
|
|
(setq-local flyspell-generic-check-word-predicate 'scala/flyspell-verify))
|
2016-03-09 04:09:40 +00:00
|
|
|
|
|
|
|
(defun scala/yank-type-at-point ()
|
2016-06-03 06:40:14 +00:00
|
|
|
"Yank to kill ring and print short type name at point to the minibuffer."
|
2016-03-09 04:09:40 +00:00
|
|
|
(interactive)
|
2016-06-03 06:40:14 +00:00
|
|
|
(ensime-type-at-point t nil))
|
|
|
|
|
|
|
|
(defun scala/yank-type-at-point-full-name ()
|
|
|
|
"Yank to kill ring and print full type name at point to the minibuffer."
|
|
|
|
(interactive)
|
|
|
|
(ensime-type-at-point t t))
|