-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcppext.el
More file actions
88 lines (72 loc) · 2.83 KB
/
cppext.el
File metadata and controls
88 lines (72 loc) · 2.83 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
;;; cppext.el --- Emacs Extensions for developing C++ programs
(defun cppext/compile () (interactive)
"If a variable 'cppext/proj-build-dir' is available, run make in
this directory. Otherwise, run the normal compile-function"
(if (boundp 'cppext/proj-build-dir)
(let ((cmd (concat "cd " cppext/proj-build-dir " && make -j8")))
(compile cmd))
(call-interactively 'compile)))
(defun cppext/test-bindir () (concat cppext/proj-build-dir cppext/test-dir))
(defun cppext/run-unit-tests (n) (interactive)
(interactive)
(let ((rundir (cppext/test-bindir))
(bindir (cppext/test-bindir)))
(cppext/choose-and-run-compiled-program rundir
bindir
cppext/unit-test-exec
"")))
(defun cppext/run-integration-tests ()
(interactive)
(let ((rundir (cppext/test-bindir))
(bindir (cppext/test-bindir)))
(cppext/choose-and-run-compiled-program rundir
bindir
cppext/integration-test-exec
"")))
(defun cppext/run-ctest () (interactive)
(cppext/run-compiled-program (cppext/test-bindir) "" "ctest --output-on-failure"))
(setq cppext/last-main-exec "")
(defun cppext/run-main ()
(interactive)
(let ((rundir (concat cppext/proj-root-dir cppext/work-dir))
(bindir cppext/proj-build-dir))
(setq cppext/last-main-exec
(cppext/choose-and-run-compiled-program rundir
bindir
cppext/main-exec
cppext/last-main-exec))))
(defun cppext/choose-and-run-compiled-program (workdir bindir cmds lastcmd)
(let ((cmdStr (if (listp cmds)
(completing-read "Choose executable to run: "
cmds
nil t lastcmd)
cmds)))
(message cmdStr)
(cppext/run-compiled-program workdir bindir cmdStr)
cmdStr))
(defun cppext/run-compiled-program (workdir bindir exec)
(let ((cmd (concat "cd " workdir " && " bindir exec)))
(compile cmd)))
(defun cppext/gmocktokillring ()
(interactive)
(let ((class (thing-at-point 'word))
(file (buffer-file-name)))
(with-temp-buffer
(shell-command (concat "gmock_gen.py " file " " class) (current-buffer))
(kill-region (point-min) (point-max))
)))
(defun cppext/c-mode-keys () (interactive)
(local-set-key (kbd "C-c C-r C-t") (lambda () (interactive) (cppext/run-unit-tests 0)))
(local-set-key (kbd "C-c C-r C-c") 'cppext/run-ctest)
(local-set-key (kbd "C-c C-r C-i") (lambda () (interactive) (cppext/run-integration-tests 0)))
(local-set-key (kbd "C-c C-r C-r") 'cppext/run-main)
(local-set-key (kbd "C-c C-c") 'cppext/compile)
(local-set-key (kbd "C-c C-f") 'clang-format-region)
(local-set-key (kbd "C-c r m") 'am/add-member)
(local-set-key (kbd "C-c <") 'rtags-location-stack-back)
(local-set-key (kbd "C-c >") 'rtags-location-stack-forward)
(local-set-key (kbd "C-c C-m") 'cppext/gmocktokillring)
)
(add-hook 'c-mode-common-hook 'cppext/c-mode-keys)
(provide 'cppext)
;;; cppext.el ends here