dotfiles/emacs/.emacs.d/config.org

308 lines
8.5 KiB
Org Mode
Raw Normal View History

#+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
* Packages
A list of installed packages and details about them.
** Package Archives
Adding the melpa package repository to Emacs.
#+BEGIN_SRC emacs-lisp
2018-01-10 06:33:52 +01:00
(require 'package)
(add-to-list 'package-archives
'("melpa" . "http://melpa.org/packages/"))
(package-initialize)
#+END_SRC
** Installed packages:
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
#+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 aggressive-indent) is a dep
(use-package anaconda-mode)
(use-package auctex
:defer t
:ensure t)
(use-package auto-complete)
(use-package auto-complete-auctex
:defer t
:ensure t)
(use-package counsel)
(use-package eclim)
(use-package flycheck)
(use-package google-this)
(use-package ledger-mode)
(use-package ivy)
(use-package material-theme)
(use-package ox-twbs)
(use-package rainbow-delimiters)
(use-package rainbow-mode)
(use-package smartparens)
(use-package swiper)
;; (use-package yasnippet) is a dep
#+END_SRC
* Themes
Using the [[https://github.com/cpaulik/emacs-material-theme][Material]]-Theme.
2018-01-10 06:33:52 +01:00
#+BEGIN_SRC emacs-lisp
(load-theme 'material t)
2018-01-10 06:33:52 +01:00
#+END_SRC
Changes the Emacs background to the terminals defaults. (Generally)
#+BEGIN_SRC emacs-lisp
(add-hook 'window-setup-hook
'(lambda ()
(set-face-background 'default "unspecified-bg")))
#+END_SRC
* Emacs behavior
Save auto-save files in ~/.emacs-save
#+BEGIN_SRC emacs-lisp
(f-mkdir "~/.emacs-saves")
(setq auto-save-file-name-transforms
'((".*" "~/.emacs-saves/" t)))
#+END_SRC
* Functions
All the functions I use.
** Cut/Copy and Paste by Boruch Baum
A nice way to copy and paste contents comfortably inside and out of emacs.
*** Copy
Copy the marked area to the clipboard.
2018-01-10 06:33:52 +01:00
#+BEGIN_SRC emacs-lisp
(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
*** Cut
Cut the marked area to the clipboard.
2018-01-10 06:33:52 +01:00
#+BEGIN_SRC emacs-lisp
(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
*** 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
** Personal functions
Go back to indentation, if you are at the indentation, go to beginning of the line instead.
#+BEGIN_SRC emacs-lisp
(defun back-to-indentation-or-beginning ()
"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
Sets the background of Emacs in terminal-mode to the terminals. Doesn't change it in window
mode though.
Function is not currently used since I still have to figure out how to make it work with emacs in daemon mode
#+BEGIN_SRC emacs-lisp
(defun transparent-terminal ()
(unless (display-graphic-p (selected-frame))
(set-face-background 'default "unspecified-bg" (selected-frame))))
#+END_SRC
* Modes
** Window Modes
2018-01-10 06:33:52 +01:00
#+BEGIN_SRC emacs-lisp
(menu-bar-mode -1)
2018-01-10 06:33:52 +01:00
#+END_SRC
** Autocomplete
#+BEGIN_SRC emacs-lisp
(ac-config-default)
2018-01-10 06:33:52 +01:00
#+END_SRC
** Python
Using Anaconda-mode as default python development mode
#+BEGIN_SRC emacs-lisp
(add-hook 'python-mode-hook 'anaconda-mode)
(add-hook 'python-mode-hook 'anaconda-eldoc-mode)
#+END_SRC
** LaTeX
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)
(setq-default TeX-master nil)
#+END_SRC
** Org
Enable a Twitter Bootstrap mode as an export mode for Org-mode.
#+BEGIN_SRC emacs-lisp
;; (require 'ox-twbs)
#+END_SRC
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
Enable syntax highlighting in Org-mode.
2018-01-10 06:33:52 +01:00
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook
'(lambda ()
(setq org-src-fontify-natively t)))
#+END_SRC
Enable automatic translation of special characters
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook
'(lambda ()
(setq org-pretty-entities t)))
#+END_SRC
Add rainbow-delimiters in org-mode
#+BEGIN_SRC emacs-lisp
(add-hook 'org-mode-hook 'rainbow-delimiters-mode)
#+END_SRC
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
Enabled languages:
#+BEGIN_SRC emacs-lisp
(org-babel-do-load-languages
'org-babel-load-languages
'( (python . t)
(sh . t)
(emacs-lisp . t)
(C . t)
))
#+END_SRC
** Ivy/Counsel/Swiper
#+BEGIN_SRC emacs-lisp
(counsel-mode 1)
(global-set-key "\C-s" 'swiper)
#+END_SRC
** Parenthesis
#+BEGIN_SRC emacs-lisp
;; (require 'paren)
(setq show-paren-style 'parenthesis)
(show-paren-mode 1)
#+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)
(set-face-background 'hl-line "#141b1e")
(set-face-foreground 'highlight nil)
#+END_SRC
** Yasnippet
#+BEGIN_SRC emacs-lisp
;; (require 'yasnippet)
(setq yas-snippet-dirs
'("~/.emacs.d/snippets/"))
(yas-global-mode 1)
#+END_SRC
** Ledger
#+BEGIN_SRC emacs-lisp
2018-03-08 01:13:52 +01:00
(custom-set-variables
;; custom-set-variables was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
'(ledger-reports
(quote
(("budget" "ledger -f MyBudget.ledger bal Brieftasche$ Girokonto$")
("bal" "%(binary) -f %(ledger-file) bal")
("reg" "%(binary) -f %(ledger-file) reg")
("payee" "%(binary) -f %(ledger-file) reg @%(payee)")
("account" "%(binary) -f %(ledger-file) reg %(account)"))))
'(package-selected-packages
(quote
(ledger-mode smartparens rainbow-mode rainbow-delimiters ox-twbs material-theme google-this flycheck eclim counsel auto-complete-auctex auto-complete auctex anaconda-mode use-package))))
(custom-set-faces
;; custom-set-faces was added by Custom.
;; If you edit it by hand, you could mess it up, so be careful.
;; Your init file should contain only one such instance.
;; If there is more than one, they won't work right.
)
#+END_SRC
** Personal
#+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)
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
** Conf
#+BEGIN_SRC emacs-lisp
(add-hook 'conf-mode 'rainbow-mode)
#+END_SRC