You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

450 lines
12 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

* macros
These are global macros used throughout my config file.
** definteractive
Wrappers around functions and lambdas so I don't have to type
(interactive) all the damn time
I have ~prettify-symbols-mode~ set ~lambdainteractive~ to Λ (capital lambda) because it's cute.
#+BEGIN_SRC emacs-lisp
(defmacro definteractive (name &rest body)
`(defun ,name ,(car body)
(interactive)
,@(cdr body)))
(defmacro lambdainteractive (&rest body)
`(lambda ,(car body) (interactive) ,@(cdr body)))
#+END_SRC
** local-keybind
Hide unecessary lambda when calling (local-set-key) for org-mode
functions
#+BEGIN_SRC emacs-lisp
(defmacro local-keybind (key value)
`(lambda () (local-set-key (kbd ,key) (quote ,value))))
#+END_SRC
* use-package
** use-package config
Always ensure packages are installed. Log to ~*Messages*~.
#+BEGIN_SRC emacs-lisp
(setq use-package-always-ensure t
use-package-verbose t)
#+END_SRC
** keychain-environment
#+BEGIN_SRC emacs-lisp
(use-package keychain-environment
:bind ("C-c r e" . 'keychain-refresh-environment)
:init (keychain-refresh-environment))
#+END_SRC
** slimhtml
#+BEGIN_SRC emacs-lisp
(use-package ox-slimhtml)
(org-export-define-derived-backend 'custom-html-exporter
'slimhtml
:translate-alist
'((code . org-html-code)
(timestamp . org-html-timestamp)))
#+END_SRC
** projectile
#+BEGIN_SRC emacs-lisp
(use-package projectile
:config (projectile-mode 1))
#+END_SRC
** diminish
#+BEGIN_SRC emacs-lisp
(use-package diminish
:init
(diminish 'eldoc-mode)
(diminish 'org-src-mode))
#+END_SRC
** auto-minor-mode
#+BEGIN_SRC emacs-lisp
(use-package auto-minor-mode)
#+END_SRC
** company
#+BEGIN_SRC emacs-lisp
(use-package company
:diminish 'company-mode
:bind (:map company-mode-map
("C-c /" . 'yas-expand))
:custom
(company-idle-delay 0)
(company-minimum-prefix-length 3)
:init (add-hook 'after-init-hook 'global-company-mode))
#+END_SRC
** prog
*** c#
#+BEGIN_SRC emacs-lisp
(use-package csharp-mode
:defer t
:config
(use-package omnisharp
:defer t
:config
(add-hook 'csharp-mode-hook 'omnisharp-mode)
(add-to-list 'company-backends 'company-omnisharp)))
#+END_SRC
*** elixir
#+BEGIN_SRC emacs-lisp
(use-package elixir-mode
:defer t
:config (use-package alchemist))
#+END_SRC
*** nginx
#+BEGIN_SRC emacs-lisp
(use-package nginx-mode
:custom
(nginx-indent-tabs-mode t)
(nginx-indent-level 2)
:config (add-to-list 'auto-mode-alist '("/nginx/sites-\\(?:available\\|enabled\\)/" . nginx-mode)))
#+END_SRC
*** slime
sbcl is in a werid place on Gentoo.
#+BEGIN_SRC emacs-lisp
(defun manx/lisp-keys ()
(local-set-key (kbd "C-c e") 'slime-eval-defun)
(define-key slime-mode-indirect-map (kbd "C-c x") nil))
(use-package slime
:defer t
:custom
(slime-lisp-implementations
'((sbcl ("sbcl" "--core" "/usr/lib64/sbcl/sbcl.core")
:env ("SBCL_HOME=/usr/lib64/sbcl/"))))
:diminish (slime-mode slime-autodoc-mode)
:init
(use-package slime-company)
(add-hook 'lisp-mode-hook 'slime-mode)
(add-hook 'slime-mode 'manx/lisp-keys)
(unbind-key "C-c x" slime-mode-map)
(unbind-key "C-c x" slime-mode-indirect-map)
(slime-setup '(slime-fancy slime-company)))
#+END_SRC
*** htmlize
#+BEGIN_SRC emacs-lisp
(use-package htmlize)
#+END_SRC
** yasnippet
#+BEGIN_SRC emacs-lisp
(use-package yasnippet
:diminish 'yas-minor-mode
:hook ((html-mode
LaTeX-mode
emacs-lisp-mode
lisp-mode)
. yas-minor-mode)
:init ;; These are computationally expensive, so init.
(use-package yasnippet-snippets)
(yas-reload-all))
#+END_SRC
** dashboard
#+BEGIN_SRC emacs-lisp
(use-package dashboard
:diminish (dashboard-mode page-break-lines-mode)
:custom
(dashboard-center-content t)
(dashboard-banner-logo-title "Komacs")
(dashboard-set-init-info t)
(dashboard-startup-banner "~/.emacs.d/Komacs.png")
(dashboard-show-shortcuts nil)
(dashboard-items '((recents . 5)))
:config (dashboard-setup-startup-hook))
#+END_SRC
** windows and frames
*** transpose-frame
#+BEGIN_SRC emacs-lisp
(use-package transpose-frame
:ensure t
:bind (("C-c f t" . transpose-frame)
("C-c f i" . flip-frame)
("C-c f o" . flop-frame)))
#+END_SRC
*** switch window
#+BEGIN_SRC emacs-lisp
(use-package switch-window
:custom
(switch-window-input-style 'minibuffer)
(switch-window-increase 4)
(switch-window-threshold 2)
:bind ([remap other-window] . switch-window))
#+END_SRC
*** ido
#+BEGIN_SRC emacs-lisp
(setq ido-enable-flex-matching t
ido-create-new-buffer 'always
ido-everywhere 1)
(use-package ido-vertical-mode
:bind ("C-l" . 'ido-reread-directory)
:custom (ido-vertical-define-keys 'C-n-and-C-p-only)
:config
(ido-vertical-mode 1)
(ido-mode 1))
#+END_SRC
*** spaceline
#+BEGIN_SRC emacs-lisp
(use-package spaceline
:init
(require 'spaceline-config)
(spaceline-spacemacs-theme)
:config
(spaceline-toggle-buffer-size-off)
;;This isn't set in :custom because it breaks the arrow.
(setq powerline-default-seperator 'arrow)
(add-hook 'after-init-hook 'spaceline-compile))
#+END_SRC
** minor modes
*** hungry-delete
#+BEGIN_SRC emacs-lisp
(use-package hungry-delete
:diminish 'hungry-delete-mode
:config (global-hungry-delete-mode 1))
#+END_SRC
*** which-key
#+BEGIN_SRC emacs-lisp
(use-package which-key
:diminish 'which-key-mode
:config (which-key-mode))
#+END_SRC
*** avy
#+BEGIN_SRC emacs-lisp
(use-package avy
:bind ("M-s" . avy-goto-char))
#+END_SRC
*** beacon
#+BEGIN_SRC emacs-lisp
(use-package beacon
:diminish 'beacon-mode
:config (beacon-mode 1))
#+END_SRC
*** popup-kill-ring
#+BEGIN_SRC emacs-lisp
(use-package popup-kill-ring
:bind ("M-y" . popup-kill-ring))
#+END_SRC
* org
** edit/reload config
Also saves config if open. manx/emacs-org is defined in [[./init.el][init.el]]
#+BEGIN_SRC emacs-lisp
(definteractive manx/config-reload ()
(when (get-buffer "config.org")
(with-current-buffer "config.org" (save-buffer)))
(org-babel-load-file manx/emacs-org))
(global-set-key (kbd "C-c x r") 'manx/config-reload)
(global-set-key (kbd "C-c x e") (lambdainteractive () (find-file manx/emacs-org)))
#+END_SRC
** misc
#+BEGIN_SRC emacs-lisp
(setq org-src-window-setup 'current-window)
(setq org-html-doctype "html5")
;; I read somewhere that Company breaks things?
(add-hook 'org-mode-hook 'company-mode)
;; Don't indent whole file with org-mode
(eval-after-load "org-mode" (local-set-key (kbd "s-i") nil))
(setq org-structure-template-alist
(append
'(("el" "#+BEGIN_SRC emacs-lisp\n?\n#+END_SRC")
("lisp" "#+BEGIN_SRC lisp\n?\n#+END_SRC")
("sh" "#+BEGIN_SRC shell\n?\n#+END_SRC"))
org-structure-template-alist))
(setq org-src-tab-acts-natively t
org-edit-src-content-indentation 0
org-src-preserve-indentation nil
org-agenda-files '("~/todo.org"))
#+END_SRC
** Links
#+BEGIN_SRC emacs-lisp
(definteractive manx/delete-org-link ()
(when (org-in-regexp org-bracket-link-regexp 1)
(apply 'delete-region (list (match-beginning 0) (match-end 0)))))
(add-hook 'org-mode-hook (local-keybind "C-c o l" manx/delete-org-link))
#+END_SRC
*** Inline Images
#+BEGIN_SRC emacs-lisp
(setq org-image-actual-width 150)
(definteractive manx/org-insert-link ()
(org-insert-link)
(org-redisplay-inline-images))
(add-hook 'org-mode-hook (local-keybind "C-c C-l" manx/org-insert-link))
#+END_SRC
* functions
** text
#+BEGIN_SRC emacs-lisp
(definteractive manx/kill-line()
(move-beginning-of-line nil)
(kill-whole-line))
(definteractive manx/format-whole-buffer()
(save-excursion
(indent-region (point-min) (point-max) nil)))
(global-set-key (kbd "C-c M-w") (lambdainteractive () (kill-ring-save (point-min) (point-max))))
(global-set-key (kbd "C-c k l") 'manx/kill-line)
(global-set-key (kbd "s-i") 'manx/format-whole-buffer)
(global-set-key (kbd "C-c r b") 'revert-buffer)
(global-set-key (kbd "<M-right>") 'forward-whitespace)
#+END_SRC
** buffers
#+BEGIN_SRC emacs-lisp
(definteractive manx/scratch-buffer ()
(switch-to-buffer (get-buffer-create "*scratch*"))
(lisp-interaction-mode))
(definteractive manx/lisp-buffer ()
(switch-to-buffer (get-buffer-create "*lisp playground*"))
(lisp-mode))
(definteractive manx/kill-all ()
(mapc 'kill-buffer (buffer-list))
(manx/scratch-buffer))
(global-set-key (kbd "C-c s b") 'manx/scratch-buffer)
(global-set-key (kbd "C-x k") (lambdainteractive () (kill-buffer (current-buffer))))
(global-set-key (kbd "C-M-s-k") 'manx/kill-all)
#+END_SRC
** frames
#+BEGIN_SRC emacs-lisp
(defmacro manx/split-and-follow (direction)
`(progn
,direction
(balance-windows)
(other-window 1)))
(global-set-key (kbd "C-x 3")
(lambdainteractive () (manx/split-and-follow (split-window-below))))
(global-set-key (kbd "C-x 2")
(lambdainteractive () (manx/split-and-follow (split-window-horizontally))))
#+END_SRC
** windows
#+BEGIN_SRC emacs-lisp
(definteractive manx/theme ()
"Themes don't load properly when using emacsclient"
(load-theme 'spacemacs-dark)
(spaceline-compile))
#+END_SRC
* misc
** unix line endings
#+BEGIN_SRC emacs-lisp
(defun unix-line-ends ()
(when (string-match
"-\\(?:dos\\|mac\\)$"
(symbol-name buffer-file-coding-system))
(set-buffer-file-coding-system 'unix)))
(add-hook 'find-file-hooks 'unix-line-ends)
#+END_SRC
** UTF8
#+BEGIN_SRC emacs-lisp
(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)
(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING))
#+END_SRC
** minor things
Things for GUI and basic config, like electric pairs and highlighting
parens.
*** set
#+BEGIN_SRC emacs-lisp
(line-number-mode 1)
(column-number-mode 1)
(display-battery-mode 1)
(show-paren-mode 1)
(electric-pair-mode 1)
(global-hl-line-mode 1)
(defalias 'yes-or-no-p 'y-or-n-p)
(setq scroll-conservatively 100
select-enable-clipboard t
vc-follow-symlinks t)
(setq browse-url-browser-function 'browse-url-generic
browse-url-generic-program "basilisk")
(setq backup-directory-alist
`(("." . ,(concat user-emacs-directory "autosaves"))))
#+END_SRC
*** unset
#+BEGIN_SRC emacs-lisp
(tool-bar-mode -1)
(menu-bar-mode -1)
(scroll-bar-mode -1)
(setq visible-bell nil
ring-bell-function 'ignore)
(global-unset-key (kbd "C-z")) ;; Fuck unix
#+END_SRC
** indentation
tabs > spaces. Except in Lisp.
#+BEGIN_SRC emacs-lisp
(setq-default tab-width 2
indent-tabs-mode t)
(add-hook 'lisp-mode-hook (lambda () (setq indent-tabs-mode nil)))
(add-hook 'emacs-lisp-mode-hook (lambda () (setq indent-tabs-mode nil)))
(defvaralias 'css-indent-offset 'tab-width)
(defvaralias 'js-indent-level 'tab-width)
#+END_SRC
** prettify symbols
#+BEGIN_SRC emacs-lisp
(global-prettify-symbols-mode t)
(defmacro manx/prettify (lst)
`(add-hook
(quote ,(car lst))
(lambda ()
(dolist (pair (quote ,(cdr lst)))
(push pair prettify-symbols-alist)))))
(manx/prettify
(emacs-lisp-mode-hook
("lambdainteractive" . )))
(manx/prettify
(prog-mode-hook
("||" . ?)
("&&" . ?∧)
("!=" . ?≠)))
(manx/prettify
(js-mode-hook
("=>" . ?⇒)))
#+END_SRC
* sensitive-minor-mode
#+BEGIN_SRC emacs-lisp
(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."
:init-value nil
:lighter " Sensitive"
:keymap nil
(if (symbol-value sensitive-minor-mode)
(progn
(setq make-backup-files nil)
(auto-save-mode -1))
(setq-local make-backup-files t)
(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)
("/etc/nginx/*" . sensitive-minor-mode))
auto-minor-mode-alist))
#+END_SRC