forked from brotzeit/rustic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rustic-expand.el
61 lines (48 loc) · 2.03 KB
/
rustic-expand.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
;;; rustic-expand.el --- Expand support -*-lexical-binding: t-*-
;;; Commentary:
;; This implements various functionalities related to cargo expand to
;; show result of expansion
;;; Code:
(require 'rustic-cargo)
(require 'rustic-compile)
(defvar rustic-expand-process-name "rustic-cargo-expand-process"
"Process name for expand processes.")
(defvar rustic-expand-buffer-name "*cargo-expand*"
"Buffer name for expand buffers.")
(defvar rustic-expand-arguments ""
"Holds arguments for 'cargo expand', similar to `compilation-arguments`.")
(defvar rustic-cargo-expand-mode-map
(let ((map (make-sparse-keymap)))
(define-key map [remap recompile] 'rustic-cargo-expand-rerun)
map)
"Local keymap for `rustic-cargo-expand-mode' buffers.")
(define-derived-mode rustic-cargo-expand-mode rustic-compilation-mode "cargo-expand"
:group 'rustic)
;;;###autoload
(defun rustic-cargo-expand (&optional arg)
"Run 'cargo expand'.
If ARG is not nil, use value as argument and store it in
`rustic-expand-arguments'. When calling this function from
`rustic-popup-mode', always use the value of
`rustic-expand-arguments'."
(interactive "P")
(rustic-cargo-expand-command
(cond (arg
(setq rustic-expand-arguments (read-from-minibuffer "Cargo expand arguments: " rustic-expand-arguments)))
(t ""))))
(defun rustic-cargo-expand-command (&optional expand-args)
"Start compilation process for 'cargo expand' with optional EXPAND-ARGS."
(rustic-compilation-process-live)
(let* ((command (list (rustic-cargo-bin) "expand"))
(c (append command (split-string (if expand-args expand-args ""))))
(buf rustic-expand-buffer-name)
(proc rustic-expand-process-name)
(mode 'rustic-cargo-expand-mode))
(rustic-compilation c (list :buffer buf :process proc :mode mode))))
;;;###autoload
(defun rustic-cargo-expand-rerun ()
"Run 'cargo expand' with `rustic-expand-arguments'."
(interactive)
(rustic-cargo-expand-command rustic-expand-arguments))
(provide 'rustic-expand)
;;; rustic-expand.el ends here