X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=emacs.d_2%2Fconfig.org;h=8a07bec2de023c8e4b2032c478ccd5925a308559;hb=64efe2b4c6715ad8c5660df5c1a5baf1c0f9c00c;hp=a128b4abe3c224782a0f0c74b95ff5a9269624f1;hpb=47cda1910204303533831b488c1bddc527e0c801;p=dotfiles.git diff --git a/emacs.d_2/config.org b/emacs.d_2/config.org index a128b4a..8a07bec 100644 --- a/emacs.d_2/config.org +++ b/emacs.d_2/config.org @@ -4,12 +4,21 @@ * Introduction -Most config are just copied from [[https://github.com/howardabrams/dot-files][howardabrams]]'s dotfiles +Most config are just copied from [[https://github.com/howardabrams/dot-files][howardabrams]]'s and [[https://github.com/abo-abo/oremacs][abo-abo's]] dotfiles * Basic Settings ** Setting loading Path +Set system PATH and emacs exec path + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (setenv "PATH" (concat (getenv "PATH") ":/usr/local/bin")) + (setq exec-path (append exec-path '("/usr/local/bin"))) + +#+END_SRC + Set the emacs load path #+BEGIN_SRC emacs-lisp :tangle yes :results silent @@ -20,18 +29,19 @@ Set the emacs load path ** Package Initialization -#+BEGIN_SRC emacs-lisp :tangle yes +#+BEGIN_SRC emacs-lisp :tangle yes :results silent (require 'package) (setq package-archives '(("mepla" . "http://melpa.milkbox.net/packages/") + ("gnu" . "http://elpa.gnu.org/packages/") ("org" . "http://orgmode.org/elpa/"))) (package-initialize) -#+END_SRC +#+END_SRC -** Windows Setting +** General Setting Disable scroll bar, tool-bar and menu-bar @@ -39,7 +49,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) @@ -47,9 +57,21 @@ Disable scroll bar, tool-bar and menu-bar (defalias 'yes-or-no-p 'y-or-n-p) (show-paren-mode 1) + + #+END_SRC -* Use-package +Switch the focus to help window when it appears + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (setq help-window-select t) + +#+END_SRC + +* Package Management Tools + +** Use-package Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs packages @@ -63,6 +85,20 @@ Using [[https://github.com/jwiegley/use-package][use-package]] to manage emacs p #+END_SRC +** El-get + +[[https://github.com/dimitri/el-get][El-get]] is package management tool, whicl allows to install external elisp package from any git repository not in mepla. +Check out [[http://tapoueh.org/emacs/el-get.html][el-get]]. + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package el-get + :ensure t + :init + (add-to-list 'load-path "~/.emacs.d/el-get")) + +#+END_SRC + * Color and Fonts Settings ** highlight current line @@ -116,7 +152,7 @@ Setting the fonts (if window-system (when sd/fixed-font-family (set-frame-font sd/fixed-font-family) - (set-face-attribute 'default nil :font sd/fixed-font-family :height 140) + (set-face-attribute 'default nil :font sd/fixed-font-family :height 120) (set-face-font 'default sd/fixed-font-family))) #+END_SRC @@ -263,6 +299,9 @@ Always indents header, and hide header leading starts so that no need type =#+ST (sqlite . t) (js . t))) + ;; use current window for org source buffer editting + (setq org-src-window-setup 'current-window ) + #+END_SRC ** Org-bullets @@ -285,7 +324,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 @@ -293,11 +332,12 @@ cause we cannot input =[= and =]=, so here I unset this mappings. And redifined :ensure t :commands worf-mode :init (add-hook 'org-mode-hook 'worf-mode) - :config - (define-key worf-mode-map "[" nil) - (define-key worf-mode-map "]" nil) - (define-key worf-mode-map (kbd "M-[") 'worf-backward) - (define-key worf-mode-map (kbd "M-]") 'worf-forward)) + ;; :config + ;; (define-key worf-mode-map "[" nil) + ;; (define-key worf-mode-map "]" nil) + ;; (define-key worf-mode-map (kbd "M-[") 'worf-backward) + ;; (define-key worf-mode-map (kbd "M-]") 'worf-forward) + ) #+END_SRC @@ -335,6 +375,8 @@ cause we cannot input =[= and =]=, so here I unset this mappings. And redifined (ido-everywhere 1) (add-to-list 'completion-ignored-extensions ".pyc")) + (icomplete-mode t) + #+END_SRC ** FLX @@ -351,7 +393,7 @@ cause we cannot input =[= and =]=, so here I unset this mappings. And redifined ** IDO-vertically -#+BEGIN_SRC emacs-lisp :tangle yes :result silent +#+BEGIN_SRC emacs-lisp :tangle yes :results silent (use-package ido-vertical-mode :ensure t @@ -364,7 +406,7 @@ cause we cannot input =[= and =]=, so here I unset this mappings. And redifined ** SMEX -#+BEGIN_SRC emacs-lisp :tangle yes :result silent +#+BEGIN_SRC emacs-lisp :tangle yes :results silent (use-package smex :ensure t @@ -375,8 +417,264 @@ cause we cannot input =[= and =]=, so here I unset this mappings. And redifined #+END_SRC +** Ido-ubiquitous + +Use [[https://github.com/DarwinAwardWinner/ido-ubiquitous][ido-ubiquitous]] for ido everywhere. It makes =describe-function= can also use ido + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package ido-ubiquitous + :ensure t + :init + (setq magit-completing-read-function 'magit-ido-completing-read) + (setq gnus-completing-read-function 'gnus-ido-completing-read) + :config + (ido-ubiquitous-mode 1)) + +#+END_SRC + +* File and Buffer Operation + +Remove prefix =ESC=, refer [[http://emacs.stackexchange.com/questions/14755/how-to-remove-bindings-to-the-esc-prefix-key][here]] + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (define-key key-translation-map (kbd "ESC") (kbd "C-g")) + +#+END_SRC + +** Esc on Minibuffer + +Use =ESC= to exit minibuffer. Also I map =Super-h= the same as =C-g= + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (define-key minibuffer-local-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-ns-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-isearch-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-completion-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-must-match-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-must-match-filename-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-filename-completion-map [escape] 'keyboard-escape-quit) + (define-key minibuffer-local-filename-must-match-map [escape] 'keyboard-escape-quit) + + ;; Also map s-h same as C-g + (define-key minibuffer-local-map (kbd "s-h") 'keyboard-escape-quit) + +#+END_SRC + +** =Super= bindings for file, buffer and windows + +Some global bindings on =Super=, on Mac, it is =Command= + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (global-set-key (kbd "s-h") 'keyboard-quit) + (global-set-key (kbd "s-j") 'ido-switch-buffer) + ;; s-k --> kill-this-buffer + ;; s-l --> goto-line + ;; s-; --> + ;; s-' --> 'next-multiframe-window + (global-set-key (kbd "") 'toggle-frame-fullscreen) + + ;; (global-set-key (kbd "s-y") 'projectile-find-file) + (global-set-key (kbd "s-f") 'projectile-find-file) + (global-set-key (kbd "s-[") 'next-buffer) + (global-set-key (kbd "s-]") 'previous-buffer) + + (global-set-key (kbd "s-`") 'mode-line-other-buffer) + + + + ;; someothers default mapping on super (command) key + ;; s-s save-buffer + ;; s-k kill-this-buffer + + + ;; s-h --> ns-do-hide-emacs + ;; s-j --> ido-switch-buffer + + ;; s-k --> kill-this-buffer + ;; s-l --> goto-line + ;; s-; --> undefined + ;; s-' --> next-multiframe-window + ;; s-ret --> toggle-frame-fullscreen + + + ;; s-y --> ns-paste-secondary + ;; s-u --> revert-buffer + ;; s-i --> undefined - but used for iterm globally + ;; s-o --> used for emacs globally + ;; s-p --> projectile-persp-switch-project + + ;; s-[ --> next-buffer + + ;; s-] --> previous-buffer + + + ;; s-0 --> undefined + ;; s-9 --> undefined + ;; s-8 --> undefined + ;; s-7 --> undefined + ;; s-6 --> undefined + ;; s-- --> center-line + ;; s-= --> undefined + + ;; s-n --> make-frame + ;; s-m --> iconify-frame + ;; s-b --> undefined + ;; s-, --> customize + ;; s-. --> undefined + ;; s-/ --> undefined + + ;; s-g --> isearch-repeat-forward + ;; s-f --> projectile-find-file + + ;; s-d --> isearch-repeat-background + ;; s-s --> save-buffer + ;; s-a --> make-whole-buffer + + ;; s-b --> undefined + ;; s-v --> yank + ;; s-c --> ns-copy-including-secondary + + ;; s-t --> ns-popup-font-panel + ;; s-r --> undefined + ;; s-e --> isearch-yanqk-kill + ;; s-w --> delete-frame + ;; s-q --> same-buffers-kill-emacs + + ;; s-` --> other-frame +#+END_SRC + +** =M-s= bindings for searching + +I use the prefix =M-s= for searching in buffers + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (defun pl-make-keymap (key bindings) + (setq keymap (make-sparse-keymap)) + (dolist (binding bindings) + (define-key keymap (car binding) (cdr binding))) + (global-set-key key keymap)) + + (global-set-key (kbd "M-s M-s") 'isearch-forward-regexp) + (global-set-key (kbd "M-s M-r") 'isearch-forward-regexp) + + (define-key isearch-mode-map (kbd "M-s") 'isearch-forward-regexp) + +#+END_SRC + * Misc Settings + +** [[https://github.com/abo-abo/hydra][Hydra]] + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package hydra + :ensure t) + +#+END_SRC + +*** Font Zoom + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (defhydra sd/font-zoom (global-map "") + "zoom" + ("g" text-scale-increase "in") + ("l" text-scale-decrease "out")) + +#+END_SRC + +*** Windmove Splitter + +Refer [[https://github.com/abo-abo/hydra/blob/master/hydra-examples.el][hydra-example]], to enlarge or shrink the windows splitter + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (defun hydra-move-splitter-left (arg) + "Move window splitter left." + (interactive "p") + (if (let ((windmove-wrap-around)) + (windmove-find-other-window 'right)) + (shrink-window-horizontally arg) + (enlarge-window-horizontally arg))) + + (defun hydra-move-splitter-right (arg) + "Move window splitter right." + (interactive "p") + (if (let ((windmove-wrap-around)) + (windmove-find-other-window 'right)) + (enlarge-window-horizontally arg) + (shrink-window-horizontally arg))) + + (defun hydra-move-splitter-up (arg) + "Move window splitter up." + (interactive "p") + (if (let ((windmove-wrap-around)) + (windmove-find-other-window 'up)) + (enlarge-window arg) + (shrink-window arg))) + + (defun hydra-move-splitter-down (arg) + "Move window splitter down." + (interactive "p") + (if (let ((windmove-wrap-around)) + (windmove-find-other-window 'up)) + (shrink-window arg) + (enlarge-window arg))) + +#+END_SRC + +*** hydra-window + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (winner-mode 1) + + (defhydra sd/hydra-window (:color red :columns nil) + "window" + ("h" windmove-left nil) + ("j" windmove-down nil) + ("k" windmove-up nil) + ("l" windmove-right nil) + ("H" hydra-move-splitter-left nil) + ("J" hydra-move-splitter-down nil) + ("K" hydra-move-splitter-up nil) + ("L" hydra-move-splitter-right nil) + ("v" (lambda () + (interactive) + (split-window-right) + (windmove-right)) + "vert") + ("x" (lambda () + (interactive) + (split-window-below) + (windmove-down)) + "horz") + ;; ("o" delete-other-windows "one" :exit t) + ;; Todo define o to triggle delete others windows and restore windows layout + ("o" triggle-windows-max-size "maximize" :exit t) + ("a" ace-window "ace") + ("s" ace-swap-window "swap") + ("d" ace-delete-window "ace-one" :exit t) + ("i" ace-maximize-window "ace-one" :exit t) + ("b" ido-switch-buffer "buf") + ("m" headlong-bookmark-jump "bmk") + ("q" nil "cancel") + ("u" (progn (winner-undo) (setq this-command 'winner-undo)) "undo") + ("r" (progn (winner-redo) (setq this-command 'winner-redo)) "redo") + ("f" nil)) + + (global-unset-key (kbd "M-o")) + (global-set-key (kbd "M-o") 'sd/hydra-window/body) + + (defun triggle-windows-max-size () + (interactive) + (if (> (length (window-list)) 1) + (delete-other-windows) + (winner-undo))) + +#+END_SRC + ** Line Number Enable linum mode on programming modes @@ -456,9 +754,131 @@ Type =o= to go to the link #+END_SRC -* Programming Languages +** Emux + +[[https://github.com/re5et/emux][emux]] is + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (el-get-bundle re5et/emux) + +#+END_SRC + +** Smart Parens + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package smartparens + :ensure t + :config + (progn + (require 'smartparens-config) + (add-hook 'prog-mode-hook 'smartparens-mode))) + +#+END_SRC + +** Ace-Windows -** Emacs Lisp +[[https://github.com/abo-abo/ace-window][ace-window]] + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package ace-window + :ensure t + :defer t + ; :init + ; (global-set-key (kbd "M-o") 'ace-window) + :config + (setq aw-keys '(?a ?s ?d ?f ?j ?k ?l))) + +#+END_SRC + +** Projectile + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package projectile + :ensure t + :init + (setq projectile-enable-caching t) + :config + (projectile-global-mode t)) + + (use-package persp-projectile + :ensure t + :config + (persp-mode) + :bind + (:map projectile-mode-map + ("s-p" . projectile-persp-switch-project))) + + ;; projectile-find-file + ;; projectile-switch-buffer + ;; projectile-find-file-other-window +#+END_SRC + +** Which key + +[[https://github.com/justbur/emacs-which-key][which-key]] show the key bindings + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package which-key + :ensure t + :config + (which-key-mode)) + +#+END_SRC + +** Emms + +We can use [[https://www.gnu.org/software/emms/quickstart.html][Emms]] for multimedia in Emacs + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package emms + :ensure t + :init + (setq emms-source-file-default-directory "~/Music/emms/") + :config + (emms-standard) + (emms-default-players) + (define-emms-simple-player mplayer '(file url) + (regexp-opt '(".ogg" ".mp3" ".mgp" ".wav" ".wmv" ".wma" ".ape" + ".mov" ".avi" ".ogm" ".asf" ".mkv" ".divx" ".mpeg" + "http://" "mms://" ".rm" ".rmvb" ".mp4" ".flac" ".vob" + ".m4a" ".flv" ".ogv" ".pls")) + "mplayer" "-slave" "-quiet" "-really-quiet" "-fullscreen") + (emms-history-load)) + +#+END_SRC + +** GnoGo + +Play Go in Emacs + +gnugo xpm refert [[https://github.com/okanotor/dotemacs/blob/f95b774cb292d1169748bc0a62ba647bbd8c0652/etc/my-inits/my-inits-gnugo.el][to here]] + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package gnugo + :ensure t + :defer t + :init + (require 'gnugo-imgen) + (setq gnugo-xpms 'gnugo-imgen-create-xpms) + (add-hook 'gnugo-start-game-hook '(lambda () + (gnugo-image-display-mode) + (gnugo-grid-mode))) + :config + (add-to-list 'gnugo-option-history (format "--boardsize 19 --color black --level 1"))) + +#+END_SRC +* Programming + +** Languages + +*** Emacs Lisp #+BEGIN_SRC emacs-lisp :tangle yes :results silent @@ -471,7 +891,25 @@ Type =o= to go to the link #+END_SRC -** Perl +**** Lispy Mode + +In Lisp Mode, =M-o= is defined, but I use this for global hydra window. So here disable this key +bindings in =lispy-mode-map= after loaded. see [[http://stackoverflow.com/questions/298048/how-to-handle-conflicting-keybindings][here]] + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package lispy + :ensure t + :init + (eval-after-load 'lispy + '(progn + (define-key lispy-mode-map (kbd "M-o") nil))) + :config + (add-hook 'emacs-lisp-mode-hook (lambda () (lispy-mode 1)))) + +#+END_SRC + +*** Perl [[https://www.emacswiki.org/emacs/CPerlMode][CPerl mode]] has more features than =PerlMode= for perl programming. Alias this to =CPerlMode= @@ -479,12 +917,164 @@ 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 silent + + (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 " \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 " \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 -* Others +*** Perl Auto Insert -** Shell pop mode +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 + +** Completion + +company mode + +#+BEGIN_SRC emacs-lisp :tangle yes :results silent + + (use-package company + :ensure t + :diminish company-mode + :init (setq company-idle-delay 0.1) + :config + (global-company-mode)) + +#+END_SRC -** Smartparens mode +* Todo -*** +- change M-o to trigger to delete other windows and restore previous config +-