Created
January 23, 2012 01:35
-
-
Save ageekymonk/1659869 to your computer and use it in GitHub Desktop.
Emacs snippet for compiling code in c and cpp
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
;; Compilation for gcc / g++ | |
(defun ramz/code-compile () | |
(interactive) | |
(unless (file-exists-p "Makefile") | |
(set (make-local-variable 'compile-command) | |
(let ((file (file-name-nondirectory buffer-file-name))) | |
(format "%s -o %s %s" | |
(if (equal (file-name-extension file) "cpp") "g++" "gcc" ) | |
(file-name-sans-extension file) | |
file))) | |
(compile compile-command))) | |
(global-set-key [f9] 'ramz/code-compile) | |
;; Run the compiled file | |
(defun ramz/run-code () | |
(interactive) | |
(set 'run-command | |
(if (equal (file-name-extension (file-name-nondirectory buffer-file-name)) "rb") | |
(format "ruby %s" (file-name-nondirectory buffer-file-name)) | |
(format "./%s" (file-name-sans-extension (file-name-nondirectory buffer-file-name))))) | |
(shell-command run-command)) | |
(global-set-key [f8] 'ramz/run-code) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment