This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
spacemacs/layers/+lang/scala/funcs.el
justbur 6eab954afe Use + instead of ! for layer categories
Helm seems to treat "!" specially in pattern matching, so having a ! in
the pattern string when traversing directories is problematic. This
change fixes #2737, because as far as I can tell "+" has no special
meaning in a helm pattern.

Of course, we can choose a different character, but I'm fond of "+" as
representing "more layers here".
2015-09-11 00:13:51 -04:00

110 lines
3.5 KiB
EmacsLisp

;;; funcs.el --- Scala Layer functions File for Spacemacs
;;
;; Copyright (c) 2012-2014 Sylvain Benner
;; Copyright (c) 2014-2015 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
;;; Ensime
(autoload 'ensime-config-find-file "ensime-config")
(autoload 'ensime-config-find "ensime-config")
(autoload 'projectile-project-p "projectile")
(defun scala/configure-ensime ()
"Ensure the file exists before starting `ensime-mode'."
(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))))
(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)))))
(defun scala/enable-eldoc ()
(setq-local eldoc-documentation-function
(lambda ()
(when (ensime-connected-p)
(ensime-print-type-at-point))))
(eldoc-mode +1))
(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))
;;; Interactive commands
(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))))
(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))
(cond (company-backend
(company-complete-selection)
(scala/completing-dot))
(t
(insert ".")
(company-complete))))
;;; 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))