2018-01-13 15:29:33 +01:00
|
|
|
#+TITLE: Emacs configure
|
|
|
|
#+AUTHOR: Tuan-Dat Tran
|
|
|
|
#+DATE: <2018-01-11 Do>
|
|
|
|
#+EMAIL: tran.tuan-dat@mailbox.org
|
|
|
|
#+OPTIONS: ':nil *:t -:t ::t <:t H:3 \n:nil ^:t arch:headline
|
|
|
|
#+OPTIONS: author:t c:nil creator:comment d:(not "LOGBOOK") date:t
|
|
|
|
#+OPTIONS: e:t email:nil f:t inline:t num:t p:nil pri:nil stat:t
|
|
|
|
#+OPTIONS: tags:t tasks:t tex:t timestamp:t toc:t todo:t |:t
|
|
|
|
#+KEYWORDS:
|
|
|
|
#+LANGUAGE: en
|
|
|
|
#+SELECT_TAGS: export
|
2018-01-10 03:56:51 +01:00
|
|
|
|
2018-01-13 15:29:33 +01:00
|
|
|
* Packages
|
2018-01-19 06:50:57 +01:00
|
|
|
A list of installed packages and details about them.
|
2018-01-13 15:29:33 +01:00
|
|
|
** Package Archives
|
2018-01-22 16:34:03 +01:00
|
|
|
Adding the melpa package repository to Emacs.
|
2018-01-10 03:56:51 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-10 06:33:52 +01:00
|
|
|
(require 'package)
|
2018-04-29 23:13:10 +02:00
|
|
|
(add-to-list 'package-archives
|
2018-01-13 15:29:33 +01:00
|
|
|
'("melpa" . "http://melpa.org/packages/"))
|
2018-01-14 12:25:14 +01:00
|
|
|
(package-initialize)
|
|
|
|
#+END_SRC
|
|
|
|
** Installed packages:
|
2018-01-22 16:34:03 +01:00
|
|
|
A require for all my installed packages, so that they are automatically installed
|
|
|
|
in case I want to setup my emacs on another pc he same way as always
|
2018-01-14 12:25:14 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(unless (package-installed-p 'use-package)
|
|
|
|
(package-refresh-contents)
|
|
|
|
(package-install 'use-package))
|
|
|
|
|
|
|
|
(require 'use-package)
|
|
|
|
(setq use-package-always-ensure t)
|
|
|
|
|
|
|
|
(use-package anaconda-mode)
|
2018-01-22 16:34:03 +01:00
|
|
|
(use-package auctex
|
|
|
|
:defer t
|
|
|
|
:ensure t)
|
|
|
|
(use-package auto-complete)
|
|
|
|
(use-package auto-complete-auctex
|
|
|
|
:defer t
|
|
|
|
:ensure t)
|
2018-01-14 12:25:14 +01:00
|
|
|
(use-package counsel)
|
|
|
|
(use-package flycheck)
|
|
|
|
(use-package ivy)
|
2018-05-27 18:52:35 +02:00
|
|
|
(use-package ledger-mode)
|
2018-06-24 13:25:59 +02:00
|
|
|
(use-package molokai-theme)
|
2018-05-27 18:52:35 +02:00
|
|
|
(use-package ox-gfm)
|
2018-01-14 12:25:14 +01:00
|
|
|
(use-package ox-twbs)
|
2018-05-27 18:52:35 +02:00
|
|
|
(use-package php-mode)
|
|
|
|
(use-package powerline)
|
2018-01-14 12:25:14 +01:00
|
|
|
(use-package rainbow-delimiters)
|
|
|
|
(use-package rainbow-mode)
|
2018-04-05 09:46:48 +02:00
|
|
|
(use-package smart-compile)
|
2018-01-14 12:25:14 +01:00
|
|
|
(use-package smartparens)
|
|
|
|
(use-package swiper)
|
2018-04-05 09:46:48 +02:00
|
|
|
(use-package visual-regexp)
|
2018-01-10 03:56:51 +01:00
|
|
|
#+END_SRC
|
2018-03-15 12:24:46 +01:00
|
|
|
* Appearance
|
2018-06-24 13:25:59 +02:00
|
|
|
Using the Molokai-Theme.
|
2018-01-10 06:33:52 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-06-24 13:25:59 +02:00
|
|
|
(load-theme 'molokai t)
|
2018-01-10 06:33:52 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-14 12:25:14 +01:00
|
|
|
Changes the Emacs background to the terminals defaults. (Generally)
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-04-29 23:13:10 +02:00
|
|
|
(add-hook 'window-setup-hook
|
|
|
|
'(lambda ()
|
2018-01-14 12:25:14 +01:00
|
|
|
(set-face-background 'default "unspecified-bg")))
|
|
|
|
#+END_SRC
|
2018-03-15 12:24:46 +01:00
|
|
|
|
|
|
|
Remove menubar
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(menu-bar-mode -1)
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
Powerline for Emacs
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(powerline-center-theme)
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-19 06:50:57 +01:00
|
|
|
* Emacs behavior
|
2018-01-22 16:34:03 +01:00
|
|
|
Save auto-save files in ~/.emacs-save
|
2018-01-19 06:50:57 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(f-mkdir "~/.emacs-saves")
|
2018-04-29 23:13:10 +02:00
|
|
|
(setq backup-directory-alist
|
|
|
|
'((".*" . "~/.emacs-saves/")))
|
2018-01-19 06:50:57 +01:00
|
|
|
(setq auto-save-file-name-transforms
|
|
|
|
'((".*" "~/.emacs-saves/" t)))
|
2018-05-20 19:38:00 +02:00
|
|
|
(setq custom-file "~/.emacs.d/config.el")
|
2018-06-24 13:25:59 +02:00
|
|
|
(setq auto-mode-alist (append '(("/tmp/mutt.*" . mail-mode)) auto-mode-alist))
|
2018-01-19 06:50:57 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2018-05-27 18:52:35 +02:00
|
|
|
Delete trailing spaces before saving
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(add-hook 'before-save-hook 'delete-trailing-whitespace)
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-13 15:29:33 +01:00
|
|
|
* Functions
|
2018-01-22 16:34:03 +01:00
|
|
|
All the functions I use.
|
2018-01-13 15:29:33 +01:00
|
|
|
** Cut/Copy and Paste by Boruch Baum
|
2018-01-19 06:50:57 +01:00
|
|
|
A nice way to copy and paste contents comfortably inside and out of emacs.
|
2018-01-13 15:29:33 +01:00
|
|
|
*** Copy
|
|
|
|
Copy the marked area to the clipboard.
|
2018-01-10 06:33:52 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-13 15:29:33 +01:00
|
|
|
(defun copy-to-xclipboard(arg)
|
|
|
|
(interactive "P")
|
|
|
|
(cond
|
|
|
|
((not (use-region-p))
|
|
|
|
(message "Nothing to yank to X-clipboard"))
|
|
|
|
((and (not (display-graphic-p))
|
|
|
|
(/= 0 (shell-command-on-region
|
|
|
|
(region-beginning) (region-end) "xsel -i -b")))
|
|
|
|
(error "Is program `xsel' installed?"))
|
|
|
|
(t
|
|
|
|
(when (display-graphic-p)
|
|
|
|
(call-interactively 'clipboard-kill-ring-save))
|
|
|
|
(message "Yanked region to X-clipboard")
|
|
|
|
(deactivate-mark))))
|
2018-01-10 06:33:52 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-13 15:29:33 +01:00
|
|
|
*** Cut
|
|
|
|
Cut the marked area to the clipboard.
|
2018-01-10 06:33:52 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-13 15:29:33 +01:00
|
|
|
(defun cut-to-xclipboard(arg)
|
|
|
|
(interactive "P")
|
|
|
|
(cond
|
|
|
|
((not (use-region-p))
|
|
|
|
(message "Nothing to yank to X-clipboard"))
|
|
|
|
((and (not (display-graphic-p))
|
|
|
|
(/= 0 (shell-command-on-region
|
|
|
|
(region-beginning) (region-end) "xsel -i -b")))
|
|
|
|
(error "Is program `xsel' installed?"))
|
|
|
|
(t
|
|
|
|
(when (display-graphic-p)
|
|
|
|
(call-interactively 'clipboard-kill-ring-save))
|
|
|
|
(message "Yanked region to X-clipboard")
|
|
|
|
(kill-region (region-beginning) (region-end))
|
|
|
|
(deactivate-mark))))
|
2018-01-10 06:33:52 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-13 15:29:33 +01:00
|
|
|
*** Paste
|
|
|
|
Paste from the clipboard.
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun paste-from-xclipboard()
|
|
|
|
"Uses shell command `xsel -o' to paste from x-clipboard. With
|
|
|
|
one prefix arg, pastes from X-PRIMARY, and with two prefix args,
|
|
|
|
pastes from X-SECONDARY."
|
|
|
|
(interactive)
|
|
|
|
(if (display-graphic-p)
|
|
|
|
(clipboard-yank)
|
|
|
|
(let*
|
|
|
|
((opt (prefix-numeric-value current-prefix-arg))
|
|
|
|
(opt (cond
|
|
|
|
((= 1 opt) "b")
|
|
|
|
((= 4 opt) "p")
|
|
|
|
((= 16 opt) "s"))))
|
|
|
|
(insert (shell-command-to-string (concat "xsel -o -" opt))))))
|
|
|
|
#+END_SRC
|
2018-01-10 06:33:52 +01:00
|
|
|
|
2018-01-13 15:29:33 +01:00
|
|
|
** Personal functions
|
|
|
|
Go back to indentation, if you are at the indentation, go to beginning of the line instead.
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-04-29 23:13:10 +02:00
|
|
|
(defun back-to-indentation-or-beginning ()
|
2018-01-13 15:29:33 +01:00
|
|
|
"Go back to indentation, if at indentation go to beginning of line"
|
|
|
|
(interactive)
|
|
|
|
(if (= (point) (progn (back-to-indentation) (point)))
|
|
|
|
(beginning-of-line)))
|
|
|
|
#+END_SRC
|
2018-01-14 12:25:14 +01:00
|
|
|
|
2018-04-29 23:13:10 +02:00
|
|
|
Sets the background of Emacs in terminal-mode to the terminals. Doesn't change it in window
|
2018-01-19 06:50:57 +01:00
|
|
|
mode though.
|
|
|
|
Function is not currently used since I still have to figure out how to make it work with emacs in daemon mode
|
2018-01-14 12:25:14 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun transparent-terminal ()
|
|
|
|
(unless (display-graphic-p (selected-frame))
|
|
|
|
(set-face-background 'default "unspecified-bg" (selected-frame))))
|
|
|
|
#+END_SRC
|
2018-03-15 11:32:26 +01:00
|
|
|
|
|
|
|
Copy word
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun copy-word (&optinal arg)
|
|
|
|
"Copy words at point into kill-ring"
|
|
|
|
(interactive "P")
|
|
|
|
(copy-thing 'backward-word 'forward-word arg)
|
|
|
|
)
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-06-24 13:25:59 +02:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun insert-current-date () (interactive)
|
|
|
|
(insert (shell-command-to-string "echo -n $(date +%d.%m.%Y)")))
|
|
|
|
#+END_SRC
|
|
|
|
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defun insert-current-time () (interactive)
|
|
|
|
(insert (shell-command-to-string "echo -n $(date +%H:%M)")))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-14 12:25:14 +01:00
|
|
|
* Modes
|
2018-01-13 15:29:33 +01:00
|
|
|
** Window Modes
|
2018-01-19 06:50:57 +01:00
|
|
|
** Autocomplete
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(ac-config-default)
|
2018-01-10 06:33:52 +01:00
|
|
|
|
2018-01-19 06:50:57 +01:00
|
|
|
#+END_SRC
|
2018-01-13 15:29:33 +01:00
|
|
|
** Python
|
2018-01-14 12:25:14 +01:00
|
|
|
Using Anaconda-mode as default python development mode
|
2018-01-13 15:29:33 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(add-hook 'python-mode-hook 'anaconda-mode)
|
|
|
|
(add-hook 'python-mode-hook 'anaconda-eldoc-mode)
|
|
|
|
#+END_SRC
|
2018-04-29 23:13:10 +02:00
|
|
|
** Java
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(add-hook
|
|
|
|
'java-mode-hook
|
|
|
|
(lambda()
|
|
|
|
(local-set-key (kbd "C-c C-c") #'smart-compile)
|
|
|
|
(local-set-key (kbd "C-c /") #'comment-region)))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-04-05 09:46:48 +02:00
|
|
|
** C++
|
|
|
|
My exec doesnt quite work yet.
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
;;(defun my-exec ()
|
|
|
|
;; (interactive)
|
|
|
|
;; (let ((exe (smart-compile-string "%n")))
|
|
|
|
;; (with-current-buffer "*eshell*"
|
|
|
|
;; (goto-char (point-max))
|
|
|
|
;; (insert "./")
|
|
|
|
;; (insert exe)
|
|
|
|
;; (eshell-send-input))
|
|
|
|
;; (switch-to-buffer-other-window "*eshell*")))
|
|
|
|
(add-hook
|
|
|
|
'c++-mode-hook
|
|
|
|
(lambda()
|
|
|
|
(local-set-key (kbd "C-c C-c") #'smart-compile)
|
|
|
|
(local-set-key (kbd "C-c /") #'comment-region)))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-04-29 23:13:10 +02:00
|
|
|
** NASM
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(add-to-list 'auto-mode-alist '("\\.\\(asm\\|s\\)$" . nasm-mode))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-13 15:29:33 +01:00
|
|
|
** LaTeX
|
2018-01-14 12:25:14 +01:00
|
|
|
Some default settings for LaTeX-Mode.
|
|
|
|
AucTeX is needed.
|
2018-01-10 06:33:52 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(setq TeX-auto-save t)
|
|
|
|
(setq TeX-parse-self t)
|
2018-01-13 15:29:33 +01:00
|
|
|
(setq-default TeX-master nil)
|
|
|
|
#+END_SRC
|
|
|
|
** Org
|
|
|
|
Use Evince as default pdf viewer.
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(add-hook 'org-mode-hook
|
|
|
|
'(lambda ()
|
|
|
|
(delete '("\\.pdf\\'" . default) org-file-apps)
|
|
|
|
(add-to-list 'org-file-apps '("\\.pdf\\'" . "evince %s"))))
|
2018-01-10 06:33:52 +01:00
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-22 16:34:03 +01:00
|
|
|
Enable syntax highlighting in Org-mode.
|
2018-01-10 06:33:52 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-04-29 23:13:10 +02:00
|
|
|
(add-hook 'org-mode-hook
|
|
|
|
'(lambda ()
|
2018-01-13 15:29:33 +01:00
|
|
|
(setq org-src-fontify-natively t)))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-04-29 23:13:10 +02:00
|
|
|
Enable
|
2018-01-22 16:34:03 +01:00
|
|
|
Enable automatic translation of special characters
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-04-29 23:13:10 +02:00
|
|
|
(add-hook 'org-mode-hook
|
2018-01-22 16:34:03 +01:00
|
|
|
'(lambda ()
|
|
|
|
(setq org-pretty-entities t)))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-13 15:29:33 +01:00
|
|
|
Add rainbow-delimiters in org-mode
|
2018-01-14 12:25:14 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-13 15:29:33 +01:00
|
|
|
(add-hook 'org-mode-hook 'rainbow-delimiters-mode)
|
2018-01-14 12:25:14 +01:00
|
|
|
#+END_SRC
|
2018-01-22 16:34:03 +01:00
|
|
|
|
2018-01-31 04:23:36 +01:00
|
|
|
Handy shortcuts
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(define-key global-map "\C-ca" 'org-agenda)
|
|
|
|
(define-key global-map "\C-cl" 'org-store-link)
|
|
|
|
(setq org-log-done t)
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-04-05 09:46:48 +02:00
|
|
|
GNU Plot
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-04-29 23:13:10 +02:00
|
|
|
(add-hook 'org-mode-hook
|
|
|
|
'(lambda ()
|
2018-04-05 09:46:48 +02:00
|
|
|
(local-set-key (kbd "C-c c") #'org-plot/gnuplot)))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-31 04:23:36 +01:00
|
|
|
Enabled languages:
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(org-babel-do-load-languages
|
|
|
|
'org-babel-load-languages
|
|
|
|
'( (python . t)
|
|
|
|
(emacs-lisp . t)
|
|
|
|
(C . t)
|
2018-04-05 09:46:48 +02:00
|
|
|
(gnuplot . t)
|
2018-04-29 23:13:10 +02:00
|
|
|
(latex . t)
|
2018-06-24 13:25:59 +02:00
|
|
|
(shell . t)
|
2018-01-31 04:23:36 +01:00
|
|
|
))
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-01-14 12:25:14 +01:00
|
|
|
** Ivy/Counsel/Swiper
|
2018-01-13 15:29:33 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-14 12:25:14 +01:00
|
|
|
(counsel-mode 1)
|
2018-01-19 06:50:57 +01:00
|
|
|
(global-set-key "\C-s" 'swiper)
|
2018-01-13 15:29:33 +01:00
|
|
|
#+END_SRC
|
|
|
|
** Parenthesis
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-31 04:23:36 +01:00
|
|
|
;; (require 'paren)
|
2018-01-13 15:29:33 +01:00
|
|
|
(setq show-paren-style 'parenthesis)
|
2018-01-19 06:50:57 +01:00
|
|
|
(show-paren-mode 1)
|
2018-01-13 15:29:33 +01:00
|
|
|
#+END_SRC
|
|
|
|
** Highlight line
|
|
|
|
Globaly highlight the current line in a slightly darker shade of grey.
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(global-hl-line-mode 1)
|
2018-01-14 12:25:14 +01:00
|
|
|
(set-face-background 'hl-line "#141b1e")
|
2018-01-13 15:29:33 +01:00
|
|
|
(set-face-foreground 'highlight nil)
|
|
|
|
#+END_SRC
|
|
|
|
** Yasnippet
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
2018-01-31 04:23:36 +01:00
|
|
|
;; (require 'yasnippet)
|
2018-01-13 15:29:33 +01:00
|
|
|
(setq yas-snippet-dirs
|
|
|
|
'("~/.emacs.d/snippets/"))
|
|
|
|
(yas-global-mode 1)
|
|
|
|
#+END_SRC
|
|
|
|
|
2018-04-29 23:13:10 +02:00
|
|
|
** Ledger
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(org-babel-load-file "~/.emacs.d/ledger.org")
|
|
|
|
#+END_SRC
|
2018-04-05 09:46:48 +02:00
|
|
|
** Personal Global
|
2018-01-13 15:29:33 +01:00
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(defvar my-keys-minor-mode-map
|
|
|
|
(let ((map (make-sparse-keymap)))
|
|
|
|
(define-key map (kbd "C-a") 'back-to-indentation-or-beginning)
|
|
|
|
(define-key map (kbd "C-c M-w") 'copy-to-xclipboard)
|
|
|
|
(define-key map (kbd "C-c C-w") 'cut-to-xclipboard)
|
|
|
|
(define-key map (kbd "C-c M-y") 'paste-from-xclipboard)
|
2018-03-15 11:32:26 +01:00
|
|
|
(define-key map (kbd "C-c w") 'copy-word)
|
2018-04-05 09:46:48 +02:00
|
|
|
(define-key map (kbd "C-c r") 'vr/query-replace)
|
2018-04-29 23:13:10 +02:00
|
|
|
(define-key map (kbd "M-/") 'comment-region)
|
2018-06-24 13:25:59 +02:00
|
|
|
(define-key map (kbd "C-c d") 'insert-current-date)
|
|
|
|
(define-key map (kbd "C-c t") 'insert-current-time)
|
2018-01-13 15:29:33 +01:00
|
|
|
map)
|
|
|
|
"my-keys-minor-mode keymap.")
|
|
|
|
|
|
|
|
(define-minor-mode my-keys-minor-mode
|
|
|
|
"A minor mode so that my key settings override annoying major modes."
|
|
|
|
:init-value t
|
|
|
|
:lighter " my-keys")
|
|
|
|
|
|
|
|
(my-keys-minor-mode 1)
|
2018-01-10 06:33:52 +01:00
|
|
|
#+END_SRC
|
2018-01-19 06:50:57 +01:00
|
|
|
|
|
|
|
** Conf
|
|
|
|
#+BEGIN_SRC emacs-lisp
|
|
|
|
(add-hook 'conf-mode 'rainbow-mode)
|
|
|
|
#+END_SRC
|