emacs - add auto-insert for c/c++ and perl mode
[dotfiles.git] / emacs.d_2 / config.org
index 4c5d556..e7e8571 100644 (file)
@@ -39,7 +39,7 @@ Disable scroll bar, tool-bar and menu-bar
 
   (scroll-bar-mode 0)
   (tool-bar-mode 0)
-  (menu-bar-mode 0)
+  (menu-bar-mode 1)
 
   (setq debug-on-error t)
   (setq inhibit-startup-message t)
@@ -301,7 +301,7 @@ use [[https://github.com/sabof/org-bullets][org-bullets]] package to show utf-8
 [[https://github.com/abo-abo/worf][worf]] mode is an extension of vi-like binding for org-mode. 
 In =worf-mode=, it is mapping =[=, =]= as =worf-backward= and =worf-forward= in global, wich
 cause we cannot input =[= and =]=, so here I unset this mappings. And redifined this two to
-=M-[= and =M-]=
+=M-[= and =M-]=. see this [[https://github.com/abo-abo/worf/issues/19#issuecomment-223756599][issue]]
 
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
 
@@ -472,9 +472,11 @@ Type =o= to go to the link
 
 #+END_SRC
 
-* Programming Languages
+* Programming
 
-** Emacs Lisp
+** Languages
+
+*** Emacs Lisp
 
 #+BEGIN_SRC emacs-lisp :tangle yes :results silent
 
@@ -487,7 +489,7 @@ Type =o= to go to the link
 
 #+END_SRC
 
-** Perl
+*** Perl
 
 [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode=
 
@@ -495,8 +497,149 @@ Type =o= to go to the link
 
   (defalias 'perl-mode 'cperl-mode)
 
+  ;(setq cperl-hairy t) ;; Turns on most of the CPerlMode options
+  (setq cperl-auto-newline t)
+  (setq cperl-highlight-variables-indiscriminately t)
+  ;(setq cperl-indent-level 4)
+  ;(setq cperl-continued-statement-offset 4)
+  (setq cperl-close-paren-offset -4)
+  (setq cperl-indent-parents-as-block t)
+  (setq cperl-tab-always-indent t)
+  ;(setq cperl-brace-offset  0)
+
+  (add-hook 'cperl-mode-hook
+            '(lambda ()
+               (cperl-set-style "C++")))
+
+  ;(require 'template)
+  ;(template-initialize)
+  ;(require 'perlnow)
+
+#+END_SRC
+
+- auto insert
+- run script 
+
+Change the compile-command to set the default command run when call =compile=
+Mapping =s-r= (on Mac, it's =Command + R= to run the script. Here =current-prefix-arg= is set
+to call =compilation=  interactively.
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+  (defun my-perl-hook ()
+    (progn
+      (setq-local compilation-read-command nil)
+      (set (make-local-variable 'compile-command)
+           (concat "/usr/bin/perl "
+                   (if buffer-file-name
+                       (shell-quote-argument buffer-file-name))))
+      (local-set-key (kbd "s-r")
+                       (lambda ()
+                         (interactive)
+  ;                       (setq current-prefix-arg '(4)) ; C-u
+                         (call-interactively 'compile)))))
+
+  (add-hook 'cperl-mode-hook 'my-perl-hook)
+
+
+#+END_SRC
+
+*** C & C++
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+  (setq c-default-style "stroustrup"
+        c-basic-offset 4)
+
+#+END_SRC
+
+** Compile
+
+Set the environments vairables in compilation mode
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+  (use-package compile
+    :commands compile
+    :config
+    (setq compilation-environment (cons "LC_ALL=C" compilation-environment)))
+
+#+END_SRC
+
+** Auto-Insert
+
+Enable auto-insert mode
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silenc
+
+  (auto-insert-mode t)
+  (setq auto-insert-query nil)
+
 #+END_SRC
 
+*** C++ Auto Insert
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+  (eval-after-load 'autoinsert
+    '(define-auto-insert '("\\.cpp\\'" . "C++ skeleton")
+       '(
+         "Short description:"
+         "/*"
+         "\n * " (file-name-nondirectory (buffer-file-name))
+         "\n */" > \n \n
+         "#include <iostream>" \n
+         "#include \""
+         (file-name-sans-extension
+          (file-name-nondirectory (buffer-file-name)))
+         ".hpp\"" \n \n
+         "using namespace std;" \n \n
+         "int main ()"
+         "\n{" \n 
+         > _ \n
+         "return 1;"
+         "\n}" > \n
+         )))
+
+  (eval-after-load 'autoinsert
+    '(define-auto-insert '("\\.c\\'" . "C skeleton")
+       '(
+         "Short description:"
+         "/*\n"
+         " * " (file-name-nondirectory (buffer-file-name)) "\n"
+         " */" > \n \n
+         "#include <stdio.h>" \n
+         "#include \""
+         (file-name-sans-extension
+          (file-name-nondirectory (buffer-file-name)))
+         ".h\"" \n \n
+         "int main ()\n"
+         "{" \n
+         > _ \n
+         "return 1;\n"
+         "}" > \n
+         )))
+       
+#+END_SRC
+
+*** Perl Auto Insert
+
+Refer [[https://www.emacswiki.org/emacs/AutoInsertMode][AutoInsertMode]] Wiki
+
+#+BEGIN_SRC emacs-lisp :tangle yes :results silent
+
+  (eval-after-load 'autoinsert
+    '(define-auto-insert '("\\.pl\\'" . "Perl skeleton")
+       '(
+         "Description: "
+         "#!/usr/bin/perl -w" \n
+         \n
+         "use strict;" \n \n
+         )))
+
+#+END_SRC
+
+
 * Others
 
 ** Shell pop mode