From efdf06bf08e700de04a908c3a4629703ae69d02c Mon Sep 17 00:00:00 2001 From: Peng Li Date: Tue, 5 Sep 2017 16:36:39 +0800 Subject: [PATCH] Emacs - Add compile for cpp mode --- emacs.d/config.org | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/emacs.d/config.org b/emacs.d/config.org index 64b493f..2993e1a 100644 --- a/emacs.d/config.org +++ b/emacs.d/config.org @@ -2336,6 +2336,26 @@ irony-company (add-hook 'c++-mode-hook 'google-set-c-style)) #+END_SRC +*** Compile and Run the C file +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + (defun my-cpp-hook () + (let* ((current-file-name) + (a-dot-out-file)) + (when buffer-file-name + (setq current-file-name (shell-quote-argument buffer-file-name)) + (setq a-dot-out-file (concat (file-name-directory buffer-file-name) "a.out"))) + (setq-local compilation-read-command t) + (set (make-local-variable 'compile-command) + (concat "g++ -Wall " + current-file-name + " && " + a-dot-out-file)) + (local-set-key (kbd "s-r") 'compile))) + + (add-hook 'c-mode-hook 'my-cpp-hook) + (add-hook 'c++-mode-hook 'my-cpp-hook) +#+END_SRC + ** Lua #+BEGIN_SRC emacs-lisp :tangle yes :results silent (use-package lua-mode -- 2.11.0