Last active
November 8, 2017 14:38
-
-
Save goromlagche/062ab3f8abb32cd21ef7dc1f98d3a4ca to your computer and use it in GitHub Desktop.
a small function to compile cpp/java code on eshell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun compile-current-cpp-file () | |
"Compile and run current file on eshell" | |
(interactive) | |
(let ((filename (buffer-file-name))) | |
(with-selected-window (get-buffer-window "*eshell*") | |
(recenter) | |
(insert "g++ -std=c++11 " filename " -o a.out && ./a.out") | |
(eshell-send-input) | |
(erase-buffer)) | |
(message "File '%s' is compiled and ran" filename))) | |
(defun compile-current-java-file () | |
"Compile and run current file on eshell" | |
(interactive) | |
(let ((filename (buffer-file-name)) | |
(filename-wo-extension (file-name-nondirectory (file-name-sans-extension buffer-file-name)))) | |
(with-selected-window (get-buffer-window "*eshell*") | |
(recenter) | |
(insert "javac " filename " && java " filename-wo-extension) | |
(eshell-send-input) | |
(erase-buffer)) | |
(message "File '%s' is compiled and ran" filename))) | |
(add-hook 'c++-mode-hook | |
'(lambda () | |
(local-set-key (kbd "C-c C-c") 'compile-current-cpp-file))) | |
(add-hook 'java-mode-hook | |
'(lambda () | |
(local-set-key (kbd "C-c C-c") 'compile-current-java-file))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I personally use a 3 window setup.
now as soon as I am done with coding, I can just press
C-c C-c
and I can view the result in the eshell prompt