Emacs - Add compile for cpp mode
[dotfiles.git] / emacs.d / config.org
index bf8028e..2993e1a 100644 (file)
@@ -150,6 +150,9 @@ Check out [[http://tapoueh.org/emacs/el-get.html][el-get]].
 
   ;; only highlight selected window
   (setq hl-line-sticky-flag nil)
+
+  (setq-default fill-column 120)
+  (add-hook 'text-mode-hook 'turn-on-auto-fill)
 #+END_SRC
 
 ** Smart Comments
@@ -1155,6 +1158,7 @@ extend org-mode's easy templates, refer to [[http://coldnew.github.io/coldnew-em
             (set-face-attribute face nil :inherit 'fixed-pitch))
           (list 'org-code 'org-block 'org-block-background 'org-block-begin-line 'org-block-end-line))
     (set-face-attribute 'org-table nil :family "Ubuntu Mono" :height 140)
+    (set-face-attribute 'org-formula nil :family "Ubuntu Mono" :height 140)
     ;; org-special-keyword inherited from font-lock-keywork originally; as org is changed to variable-pitch, it cause
     ;; the font in special-keywords are not monospace
     (set-face-attribute 'org-special-keyword nil :inherit '(font-lock-keyword-face fixed-pitch))
@@ -2332,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
@@ -2911,15 +2935,6 @@ Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g=
     (add-to-list 'projectile-globally-ignored-files "GTAGS")
     (projectile-global-mode t))
 
-  ;; (use-package persp-projectile
-  ;;   :ensure t
-  ;;   :config
-  ;;   (persp-mode)
-  ;;   :bind
-  ;;   ;; (:map projectile-mode-map
-  ;;   ;;       ("s-t" . projectile-persp-switch-project))
-  ;;   )
-
   ;; change default-directory of scratch buffer to projectile-project-root 
   (defun sd/project-switch-action ()
     "Change default-directory of scratch buffer to current projectile-project-root directory"