This repository has been archived on 2022-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
emacs/modules/emacs.el

231 lines
7.6 KiB
EmacsLisp
Raw Normal View History

;;; emacs.el --- Module file for configuring Emacs itself.
2017-08-25 23:37:01 +02:00
;;
;; Copyright (C) 2017 Wojciech Kozlowski
;;
2018-02-04 18:18:18 +01:00
;; Author: Wojciech Kozlowski <wk@wojciechkozlowski.eu>
2017-08-25 23:37:01 +02:00
;; Created: 25 Aug 2017
;;
;; This file is not part of GNU Emacs.
;;
;;; Commentary:
;;
;; This module is used for generic Emacs configuration.
2017-08-25 23:37:01 +02:00
;;
;;; License: GPLv3
;;; Required packages:
2017-09-02 14:45:42 +02:00
(setq emodule/emacs-packages
2017-09-02 09:00:24 +02:00
'(info+
discover-my-major
help+
help-fns+
help-mode+
ibuffer-vc
rainbow-mode
2018-07-07 18:32:34 +02:00
which-key
2017-09-02 09:00:24 +02:00
use-package)
)
2017-08-25 23:37:01 +02:00
;;; Configuration:
2017-09-02 14:45:42 +02:00
(defun emodule/emacs-init ()
2017-09-02 09:00:24 +02:00
;; --------------------------------------------------------------------------
;; Help extensions.
;; --------------------------------------------------------------------------
(use-package info+)
(use-package discover-my-major
:init
(global-unset-key (kbd "C-h h"))
:bind
(("C-h h m" . discover-my-major)))
(use-package help+)
(use-package help-fns+)
(use-package help-mode+)
2018-07-07 18:32:34 +02:00
(use-package which-key
:init
(setq which-key-separator " ")
(setq which-key-prefix-prefix "+")
:config
(which-key-mode 1))
2017-09-02 09:00:24 +02:00
;; --------------------------------------------------------------------------
;; Configure `ibuffer'.
;; --------------------------------------------------------------------------
(use-package ibuffer-vc
:init
(add-hook 'ibuffer-hook
(lambda ()
(ibuffer-vc-set-filter-groups-by-vc-root)
(unless (eq ibuffer-sorting-mode 'alphabetic)
((insert )buffer-do-sort-by-alphabetic))))
:config
(setq ibuffer-formats
'((mark modified read-only vc-status-mini " "
(name 36 36 :left :elide)
" "
(size 9 -1 :right)
" "
(mode 16 16 :left :elide)
" "
(vc-status 16 16 :left)
" "
filename-and-process))))
;; --------------------------------------------------------------------------
;; Rainbow mode.
;; --------------------------------------------------------------------------
(use-package rainbow-mode
:defer t)
;; --------------------------------------------------------------------------
;; Keep point in same position on the screen when scrolling.
;; --------------------------------------------------------------------------
(setq-default scroll-preserve-screen-position 1)
;; --------------------------------------------------------------------------
2017-08-28 23:19:38 +02:00
;; Functions.
;; --------------------------------------------------------------------------
(defun quit-other-window ()
"Quit the next window in cyclic order"
(interactive)
(quit-window t (next-window (selected-window))))
(defun kill-default-buffer ()
"Kill the currently active buffer with no confirmation."
(interactive)
(let (kill-buffer-query-functions) (kill-buffer)))
(defun refresh-non-face-colours ()
"Restart modes that use colours not set with face variables.
This has to be called whenever the active theme changes to
refresh these colours."
(when (and (fboundp 'fci-mode)
(member 'fci-mode minor-mode-list))
(fci-mode 1))
(when (and (fboundp 'highlight-parentheses-mode)
highlight-parentheses-mode)
(highlight-parentheses-mode 1)))
;; Key-bindings -------------------------------------------------------------
;; Kill other window (cyclic order).
2017-08-30 02:13:35 +02:00
(global-set-key (kbd "C-z") 'quit-other-window)
;; Kill current buffer without prompting.
(global-set-key (kbd "C-x k") 'kill-default-buffer)
;; --------------------------------------------------------------------------
;; Additional key-bindings.
;; --------------------------------------------------------------------------
;; Change active window. More convenient than "C-x o".
(global-set-key (kbd "M-o") 'other-window)
2017-09-09 01:24:23 +02:00
(global-set-key (kbd "M-O") (lambda () (interactive) (other-window -1)))
;; Scroll up/down, but keep point in place.
2017-09-02 22:02:33 +02:00
(global-set-key (kbd "C-<") (lambda()
(interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-down 1))))
2017-09-02 22:02:33 +02:00
(global-set-key (kbd "C->") (lambda()
(interactive)
(let ((scroll-preserve-screen-position nil))
(scroll-up 1))))
2017-09-02 23:20:28 +02:00
;; Recursive grep.
(global-set-key (kbd "C-c g") 'rgrep)
;; Setup key-bindings for switching between themes.
2017-09-02 22:02:33 +02:00
(global-set-key (kbd "C-x t l") (lambda ()
(interactive)
(load-theme 'havoc-light t)
(refresh-non-face-colours)))
(global-set-key (kbd "C-x t d") (lambda ()
(interactive)
(load-theme 'havoc-dark t)
(refresh-non-face-colours)))
2017-08-28 23:19:38 +02:00
;; --------------------------------------------------------------------------
;; Update buffers when files change.
;; --------------------------------------------------------------------------
(global-auto-revert-mode)
;; --------------------------------------------------------------------------
;; Aliases.
;; --------------------------------------------------------------------------
;; y or n is enough.
(defalias 'yes-or-no-p 'y-or-n-p)
;; Always use ibuffer.
(defalias 'list-buffers 'ibuffer)
2017-08-30 23:57:19 +02:00
;; --------------------------------------------------------------------------
;; Address mode.
;; --------------------------------------------------------------------------
(add-hook 'prog-mode-hook 'goto-address-mode)
(add-hook 'text-mode-hook 'goto-address-mode)
2017-09-03 00:37:02 +02:00
;; --------------------------------------------------------------------------
;; Tramp configuration.
;; --------------------------------------------------------------------------
(use-package tramp
:defer t
:config
2017-09-03 18:55:28 +02:00
(setq-default tramp-default-method "ssh")
;; This line proxies all sudo connections via an ssh connection to the
;; provided hostname.
(add-to-list 'tramp-default-proxies-alist '(nil "\\`root\\'" "/ssh:%h:"))
;; This rule is an exception to the above so that local sudo does not proxy
;; via ssh. This has to be added last so that it is the first element of
;; the list.
(add-to-list 'tramp-default-proxies-alist '("localhost" "\\`root\\'" nil)))
2017-09-03 00:37:02 +02:00
;; --------------------------------------------------------------------------
;; Configure garbage collection.
;;
;; Based on advice from:
;; http://bling.github.io/blog/2016/01/18/why-are-you-changing-gc-cons-threshold/
;; --------------------------------------------------------------------------
(defun minibuffer-gc-setup-hook ()
(setq gc-cons-threshold most-positive-fixnum))
(defun minibuffer-gc-exit-hook ()
(setq gc-cons-threshold 800000))
(add-hook 'minibuffer-setup-hook #'minibuffer-gc-setup-hook)
(add-hook 'minibuffer-exit-hook #'minibuffer-gc-exit-hook)
;; --------------------------------------------------------------------------
;; Increase recursion limits.
;; --------------------------------------------------------------------------
(setq-default max-specpdl-size 20000) ;; ~15x original value
(setq-default max-lisp-eval-depth 24000) ;; 30x orignal value
2018-03-31 10:54:05 +02:00
;; --------------------------------------------------------------------------
;; This slows down cursor scrolling.
;; --------------------------------------------------------------------------
(setq-default auto-window-vscroll nil)
)