config
Table of Contents
- 1. org
- 2. emacs gui
- 3. functions
- 4. use-package
- 5. ido
- 6. misc
- 7. auto-minor-mode
- 8. sensitive-minor-mode
- 9. unix line endings
1 org
1.1 edit/reload config.org
1.1.1 edit
(defun manx/config-open () (interactive) (find-file "~/.emacs.d/config.org")) (global-set-key (kbd "C-c x e") 'manx/config-open)
1.1.2 reload
(defun manx/config-reload () (interactive) ;; save buffer if it's been edited (if (get-buffer "config.org") (with-current-buffer "config.org" (save-buffer))) (org-babel-load-file (expand-file-name "~/.emacs.d/config.org"))) (global-set-key (kbd "C-c x r") 'manx/config-reload)
1.2 src edit in current window
(setq org-src-window-setup 'current-window)
1.3 disable company-mode
(add-hook 'org-mode-hook 'company-mode)
1.4 Snippets
(setq org-structure-template-alist (append '(("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC") ("js" "#+BEGIN_SRC javascript\n?\n#+END_SRC")) org-structure-template-alist))
1.5 html export
1.5.1 html5
(setq org-html-doctype "html5")
1.5.2 Save file as HTML
(defun manx/save-org-to-html() (interactive) (when (equal major-mode 'org-mode) (save-buffer) (org-html-export-to-html))) (add-hook 'org-mode-hook (lambda () (local-set-key (kbd "C-c s h") 'manx/save-org-to-html)))
1.6 Links
(defun manx/delete-org-link () (interactive) (if (org-in-regexp org-bracket-link-regexp 1) (apply 'delete-region (list (match-beginning 0) (match-end 0))))) (add-hook 'org-mode-hook (lambda () (local-set-key (kbd "C-c o l") 'manx/delete-org-link)))
1.6.1 Inline Images
(defun manx/org-insert-link() (interactive) (org-insert-link) (org-redisplay-inline-images)) (add-hook 'org-mode-hook (lambda () (local-set-key (kbd "C-c C-l") 'manx/org-insert-link))) (setq org-image-actual-width 150)
2 emacs gui
(tool-bar-mode -1) (menu-bar-mode -1) (scroll-bar-mode -1) (line-number-mode 1) (column-number-mode 1) (display-battery-mode 1) (global-unset-key (kbd "C-z"))
3 functions
3.1 text
3.1.1 copy whole line
(defun copy-whole-line () (interactive) (save-excursion (kill-new (buffer-substring (point-at-bol) (point-at-eol))))) (global-set-key (kbd "C-c k l") 'copy-whole-line)
3.1.2 kill whole word
(defun kill-whole-word () (interactive) (backward-word) (kill-word 1)) (global-set-key (kbd "C-c k w") 'kill-whole-word)
3.1.3 kill whole line
(defun manx/kill-whole-line() (interactive) (move-beginning-of-line nil) (kill-whole-line)) (global-set-key (kbd "C-c k l") 'manx/kill-whole-line)
3.1.4 comment region
(defun manx/revert-buffer () (interactive) (revert-buffer)) (global-set-key (kbd "C-c r b") 'manx/revert-buffer)
3.1.5 yas-expand for when company decides to be shit
(global-set-key (kbd "C-c /") 'yas-expand)
3.1.6 Format whole file
(defun manx/format-whole-buffer() (interactive) (save-excursion (indent-region (point-min) (point-max) nil))) (global-set-key (kbd "s-i") 'manx/format-whole-buffer)
3.2 buffers
3.2.1 kill current buffer
(defun kill-current-buffer() (interactive) (kill-buffer (current-buffer))) (global-set-key (kbd "C-x k") 'kill-current-buffer)
3.2.2 kill all buffers
(defun kill-all-buffers() (interactive) (mapc 'kill-buffer (buffer-list))) (global-set-key (kbd "C-M-s-k") 'kill-all-buffers)
3.3 frames
3.3.1 transpose frame
(global-set-key (kbd "C-c f t") 'transpose-frame)
3.3.2 flip frame
;; _f_rame fl_i_p (global-set-key (kbd "C-c f i") 'flip-frame)
3.3.3 flop frame
;; _f_rame fl_o_p (global-set-key (kbd "C-c f o") 'flop-frame)
3.3.4 split and follow vertically
(defun split-and-follow-vertical () (interactive) (split-window-right) (balance-windows) (other-window 1)) (global-set-key (kbd "C-x 3") 'split-and-follow-vertical)
3.3.5 split and follow hoizontally
(defun split-and-follow-horizontal () (interactive) (split-window-below) (balance-windows) (other-window 1)) (global-set-key (kbd "C-x 2") 'split-and-follow-horizontal)
3.4 EXWM workspace
(global-set-key (kbd "s-k") 'exwm-workspace-delete)
4 use-package
4.1 org-babel-http
(use-package ob-http :ensure t)
4.2 exwm
4.2.1 install
(use-package exwm :ensure t :config (require 'exwm-config) (exwm-config-default))
4.2.2 system tray
(require 'exwm-systemtray) (exwm-systemtray-enable)
4.3 diminish
Packages are diminished individually by use-package key, making everything a bit more modular
(use-package diminish :ensure t)
4.4 company
4.4.1 company
(use-package company :ensure t :diminish 'company-mode :config (setq company-idle-delay 0) (setq company-minimum-prefix-length 3) :init (add-hook 'after-init-hook 'global-company-mode))
4.4.2 slime
(use-package slime-company :ensure t :diminish 'slime-mode) (slime-setup '(slime-fancy slime-company))
4.4.3 auctex
(use-package company-auctex :ensure t) (company-auctex-init)
4.5 omnisharp
(use-package csharp-mode :ensure t) (use-package omnisharp :ensure t :init (add-hook 'csharp-mode-hook 'omnisharp-mode)) (eval-after-load 'company '(add-to-list 'company-backends 'company-omnisharp)) (add-hook 'csharp-mode #'company-mode)
4.6 auctex
4.6.1 auctex
(use-package tex :ensure auctex)
4.6.2 indent
(setq LaTeX-item-indent 0)
4.7 spaceline
(use-package spaceline :ensure t :config (require 'spaceline-config) (setq powerline-default-seperator (quote arrow)) (spaceline-spacemacs-theme)) (spaceline-toggle-buffer-size-off)
4.8 dashboard
(use-package dashboard :ensure t :config (dashboard-setup-startup-hook) (setq dashboard-center-content t dashboard-items '((recents . 5)) dashboard-banner-logo-title "Okaeri ~"))
4.9 avy
(use-package avy :ensure t :bind ("M-s" . avy-goto-char))
4.10 which key
(use-package which-key :ensure t :diminish 'which-key-mode :init (which-key-mode))
4.11 slime
(use-package slime :ensure t :init (setq inferior-lisp-program "/usr/bin/sbcl") (add-hook 'lisp-mode-hook 'slime-mode))
4.12 switch window
(use-package switch-window :ensure t :config (setq switch-window-input-style 'minibuffer) (setq switch-window-increase 4) (setq switch-window-threshold 2) :bind ([remap other-window] . switch-window))
4.13 popup kill ring
(use-package popup-kill-ring :ensure t :bind ("M-y" . popup-kill-ring))
4.14 minor modes
4.14.1 hungry delete
(use-package hungry-delete :ensure t :diminish 'hungry-delete-mode :config (global-hungry-delete-mode 1))
4.14.2 symon
(use-package symon :ensure t :bind ("s-h" . symon-mode))
4.14.3 beacon
(use-package beacon :ensure t :diminish 'beacon-mode :init (beacon-mode 1))
4.14.4 yasnippet
4.15 Javascript
(use-package js2-mode :ensure t)
5 ido
5.1 Enable IDO
(setq ido-enable-flex-matching t) (setq ido-create-new-buffer 'always) (setq ido-everywhere 1) (ido-mode 1) (global-set-key (kbd "C-l") 'ido-reread-directory)
5.2 IDO vertical
(use-package ido-vertical-mode :ensure t :init (ido-vertical-mode 1)) (setq ido-vertical-define-keys 'C-n-and-C-p-only)
6 misc
6.1 UTF8
(setq locale-coding-system 'utf-8) (set-terminal-coding-system 'utf-8) (set-keyboard-coding-system 'utf-8) (set-selection-coding-system 'utf-8) (prefer-coding-system 'utf-8)
6.2 terminal
6.2.1 Make bash implicit terminal
(defvar my-term-shell "/bin/bash") (defadvice ansi-term (before force-bash) (interactive (list my-term-shell))) (ad-activate 'ansi-term)
6.2.2 open term with s-return
(global-set-key (kbd "<s-return>") 'ansi-term)
6.3 parenthesis matching
(show-paren-mode 1)
6.4 copy/paste
(setq x-select-enable-clipboard t)
6.5 y/n instead of yes/no
(defalias 'yes-or-no-p 'y-or-n-p)
6.6 electric pair mode
(electric-pair-mode t)
6.7 scroll line by line
(setq scroll-conservatively 100)
6.8 highlight line
(global-hl-line-mode t)
6.9 prettify symbols
(global-prettify-symbols-mode t)
6.10 docView auto reload
(add-hook 'doc-view-mode-hook 'auto-revert-mode)
6.11 Indentation
(setq-default tab-width 2) (setq-default indent-tabs-mode t) (defvaralias 'js-indent-level 'tab-width) (defvaralias js2-basic-offset 'tab-width) (defvaralias 'css-indent-offset 'tab-width)
7 auto-minor-mode
auto-mode-alist but for minor modes.
For example, used with sensitive-mode to not create backups (path/to/file~) when creating yasnippets
(defvar auto-minor-mode-alist () "Alist of filename patterns vs correpsonding minor mode functions, see `auto-mode-alist' All elements of this alist are checked, meaning you can enable multiple minor modes for the same regexp.") (defun enable-minor-mode-based-on-extension () "Check file name against `auto-minor-mode-alist' to enable minor modes the checking happens for all pairs in auto-minor-mode-alist" (when buffer-file-name (let ((name (file-name-sans-versions buffer-file-name)) (remote-id (file-remote-p buffer-file-name)) (case-fold-search auto-mode-case-fold) (alist auto-minor-mode-alist)) ;; Remove remote file name identification. (when (and (stringp remote-id) (string-match-p (regexp-quote remote-id) name)) (setq name (substring name (match-end 0)))) (while (and alist (caar alist) (cdar alist)) (if (string-match-p (caar alist) name) (funcall (cdar alist) 1)) (setq alist (cdr alist)))))) (add-hook 'find-file-hook #'enable-minor-mode-based-on-extension)
8 sensitive-minor-mode
(define-minor-mode sensitive-minor-mode "For sensitive files like password lists. It disables backup creation and auto saving. With no argument, this command toggles the mode. Non-null prefix argument turns on the mode. Null prefix argument turns off the mode." ;; The initial value. nil ;; The indicator for the mode line. " Sensitive" ;; The minor mode bindings. nil (if (symbol-value sensitive-minor-mode) (progn ;; disable backups (set (make-local-variable 'backup-inhibited) t) ;; disable auto-save (if auto-save-default (auto-save-mode -1))) ;resort to default value of backup-inhibited (kill-local-variable 'backup-inhibited) ;resort to default auto save setting (if auto-save-default (auto-save-mode 1)))) ;; Regexps of sensitive files. (setq auto-minor-mode-alist (append '(("stream/manifest/.*\\.json$" . sensitive-minor-mode) (".emacs.d/snippets/\*$" . sensitive-minor-mode)) auto-minor-mode-alist))
9 unix line endings
(defun unix-line-ends () (let ((coding-str (symbol-name buffer-file-coding-system))) (when (string-match "-\\(?:dos\\|mac\\)$" coding-str) (set-buffer-file-coding-system 'unix)))) (add-hook 'find-file-hooks 'unix-line-ends)
new Date().getSeconds();