2016-05-27 04:22:47 +00:00
|
|
|
|
;;; funcs.el --- Elixir Layer functions File for Spacemacs
|
2016-02-15 04:15:39 +00:00
|
|
|
|
;;
|
2021-03-22 20:11:29 +00:00
|
|
|
|
;; Copyright (c) 2012-2021 Sylvain Benner & Contributors
|
2016-02-15 04:15:39 +00:00
|
|
|
|
;;
|
|
|
|
|
;; Author: Sylvain Benner <sylvain.benner@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/>.
|
|
|
|
|
|
2016-02-15 04:15:39 +00:00
|
|
|
|
|
2019-08-27 10:21:24 +00:00
|
|
|
|
(defun spacemacs//elixir-setup-backend ()
|
|
|
|
|
"Conditionally setup elixir backend."
|
2021-03-18 04:00:12 +00:00
|
|
|
|
(pcase elixir-backend
|
|
|
|
|
('alchemist (spacemacs//elixir-setup-alchemist))
|
|
|
|
|
('lsp (spacemacs//elixir-setup-lsp))))
|
2019-08-27 10:21:24 +00:00
|
|
|
|
|
|
|
|
|
(defun spacemacs//elixir-setup-company ()
|
|
|
|
|
"Conditionally setup company based on backend."
|
2021-03-18 04:00:12 +00:00
|
|
|
|
(when (eq elixir-backend 'alchemist) (spacemacs//elixir-setup-alchemist-company)))
|
2019-08-27 10:21:24 +00:00
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(defun spacemacs//elixir-setup-dap ()
|
|
|
|
|
"Conditionally setup elixir DAP integration."
|
|
|
|
|
;; currently DAP is only available using LSP
|
2021-03-18 04:00:12 +00:00
|
|
|
|
(when (eq elixir-backend 'lsp) (spacemacs//elixir-setup-lsp-dap)))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
|
2019-08-27 10:21:24 +00:00
|
|
|
|
|
|
|
|
|
;;alchemist
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//elixir-setup-alchemist ()
|
|
|
|
|
(alchemist-mode))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//elixir-setup-alchemist-company ()
|
|
|
|
|
(when (configuration-layer/package-used-p 'alchemist)
|
2021-03-18 04:00:12 +00:00
|
|
|
|
(spacemacs|add-company-backends
|
|
|
|
|
:backends alchemist-company
|
|
|
|
|
:modes elixir-mode alchemist-iex-mode)
|
|
|
|
|
(company-mode)))
|
2019-08-27 10:21:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;;lsp
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//elixir-setup-lsp ()
|
|
|
|
|
"Setup lsp backend."
|
|
|
|
|
(if (configuration-layer/layer-used-p 'lsp)
|
2021-06-06 20:25:00 +00:00
|
|
|
|
(progn (add-to-list 'exec-path elixir-ls-path) (lsp-deferred))
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(message "`lsp' layer is not installed, please add `lsp' layer to your dotfile.")))
|
2019-08-27 10:21:24 +00:00
|
|
|
|
|
2019-09-30 01:30:53 +00:00
|
|
|
|
(defun spacemacs//elixir-setup-lsp-dap ()
|
|
|
|
|
"Setup DAP integration."
|
|
|
|
|
(require 'dap-elixir))
|
|
|
|
|
|
2019-08-27 10:21:24 +00:00
|
|
|
|
|
|
|
|
|
;; others
|
|
|
|
|
|
2019-09-06 08:00:51 +00:00
|
|
|
|
(defun spacemacs//elixir-default ()
|
|
|
|
|
"Default settings for elixir buffers"
|
|
|
|
|
|
|
|
|
|
;; highlight all breakpoints
|
|
|
|
|
(spacemacs/elixir-annotate-pry)
|
|
|
|
|
;; make C-j work the same way as RET
|
|
|
|
|
(local-set-key (kbd "C-j") 'newline-and-indent))
|
|
|
|
|
|
2017-04-14 18:59:47 +00:00
|
|
|
|
(defun spacemacs//elixir-looking-back-special-p (expr)
|
2016-12-22 08:31:05 +00:00
|
|
|
|
(save-excursion
|
|
|
|
|
(when (or (looking-back " ")
|
|
|
|
|
(looking-back "-")) (backward-char))
|
|
|
|
|
(looking-back expr)))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs//elixir-point-after-fn-p (id action context)
|
|
|
|
|
(save-excursion
|
|
|
|
|
(when (looking-back id) (backward-char))
|
|
|
|
|
(looking-back "fn")))
|
|
|
|
|
|
2016-02-15 04:15:39 +00:00
|
|
|
|
(defun spacemacs//elixir-do-end-close-action (id action context)
|
|
|
|
|
(when (eq action 'insert)
|
2017-04-14 18:59:47 +00:00
|
|
|
|
(cond ((spacemacs//elixir-looking-back-special-p id)
|
2016-12-22 08:31:05 +00:00
|
|
|
|
(insert " ") (backward-char))
|
|
|
|
|
((looking-back "(")
|
|
|
|
|
(insert ") ") (backward-char) (backward-char))
|
|
|
|
|
(t
|
|
|
|
|
(newline-and-indent)
|
|
|
|
|
(forward-line -1)
|
|
|
|
|
(indent-according-to-mode)))))
|
2016-06-01 01:34:51 +00:00
|
|
|
|
|
2019-09-06 08:00:51 +00:00
|
|
|
|
(defun spacemacs/elixir-annotate-pry ()
|
|
|
|
|
"Highlight breakpoint lines."
|
|
|
|
|
(interactive)
|
|
|
|
|
(highlight-lines-matching-regexp "require IEx; IEx.pry"))
|
|
|
|
|
|
|
|
|
|
(defun spacemacs/elixir-toggle-breakpoint ()
|
|
|
|
|
"Add a breakpoint line or clear it if line is already a breakpoint."
|
|
|
|
|
(interactive)
|
|
|
|
|
(let ((trace "require IEx; IEx.pry")
|
|
|
|
|
(line (thing-at-point 'line)))
|
|
|
|
|
(if (and line (string-match trace line))
|
|
|
|
|
(kill-whole-line)
|
|
|
|
|
(progn
|
|
|
|
|
(back-to-indentation)
|
|
|
|
|
(insert trace)
|
|
|
|
|
(newline-and-indent)))))
|