2018-07-07 21:34:00 +01:00
|
|
|
;;; em-emacs.el --- Module file for configuring Emacs itself.
|
2017-08-25 22:37:01 +01:00
|
|
|
;;
|
|
|
|
;; Copyright (C) 2017 Wojciech Kozlowski
|
|
|
|
;;
|
2018-02-04 17:18:18 +00:00
|
|
|
;; Author: Wojciech Kozlowski <wk@wojciechkozlowski.eu>
|
2017-08-25 22:37:01 +01:00
|
|
|
;; Created: 25 Aug 2017
|
|
|
|
;;
|
|
|
|
;; This file is not part of GNU Emacs.
|
|
|
|
;;
|
|
|
|
;;; Commentary:
|
|
|
|
;;
|
2017-08-28 19:21:48 +01:00
|
|
|
;; This module is used for generic Emacs configuration.
|
2017-08-25 22:37:01 +01:00
|
|
|
;;
|
|
|
|
;;; License: GPLv3
|
|
|
|
|
|
|
|
;;; Required packages:
|
|
|
|
|
2018-07-07 21:34:00 +01:00
|
|
|
;;; Code:
|
2017-08-27 11:52:04 +01:00
|
|
|
|
2018-07-07 21:34:00 +01:00
|
|
|
(defvar emodule/em-emacs-packages
|
2017-08-27 11:52:04 +01:00
|
|
|
|
2018-07-11 19:11:55 +01:00
|
|
|
'(deadgrep
|
|
|
|
discover-my-major
|
2018-07-07 21:34:00 +01:00
|
|
|
ibuffer-vc
|
2019-03-17 18:31:05 +01:00
|
|
|
objed
|
2019-02-10 10:56:01 +01:00
|
|
|
pdf-tools
|
2019-03-17 18:31:05 +01:00
|
|
|
rainbow-mode
|
2019-03-17 00:39:40 +01:00
|
|
|
treemacs
|
|
|
|
treemacs-projectile
|
|
|
|
treemacs-icons-dired
|
|
|
|
treemacs-magit
|
2018-07-07 21:34:00 +01:00
|
|
|
which-key
|
|
|
|
use-package)
|
|
|
|
|
|
|
|
)
|
2017-08-25 22:37:01 +01:00
|
|
|
|
|
|
|
;;; Configuration:
|
|
|
|
|
2018-07-07 21:34:00 +01:00
|
|
|
(defun emodule/em-emacs-init ()
|
|
|
|
"Initialise the `em-emacs' module."
|
2017-08-27 11:52:04 +01:00
|
|
|
|
2018-07-11 19:11:55 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
2019-03-17 18:31:05 +01:00
|
|
|
;; Enable objed.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package objed
|
2019-03-17 18:49:45 +01:00
|
|
|
:bind
|
|
|
|
(("M-/" . objed-activate))
|
2019-03-17 18:31:05 +01:00
|
|
|
:config
|
2019-03-31 14:19:45 +02:00
|
|
|
(unbind-key "M-o" objed-map))
|
2019-03-17 18:31:05 +01:00
|
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
2018-07-11 19:11:55 +01:00
|
|
|
;; Use deadgrep.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package deadgrep
|
|
|
|
:bind
|
|
|
|
(("C-x C-g" . deadgrep)))
|
|
|
|
|
2017-09-02 08:00:24 +01: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 17:32:34 +01:00
|
|
|
(use-package which-key
|
|
|
|
:init
|
|
|
|
(setq which-key-separator " ")
|
|
|
|
(setq which-key-prefix-prefix "+")
|
|
|
|
:config
|
|
|
|
(which-key-mode 1))
|
|
|
|
|
2017-09-02 08:00:24 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Configure `ibuffer'.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package ibuffer-vc
|
2018-07-08 00:29:39 +01:00
|
|
|
:defer t
|
2017-09-02 08:00:24 +01:00
|
|
|
:init
|
|
|
|
(add-hook 'ibuffer-hook
|
|
|
|
(lambda ()
|
|
|
|
(ibuffer-vc-set-filter-groups-by-vc-root)
|
|
|
|
(unless (eq ibuffer-sorting-mode 'alphabetic)
|
2018-07-07 21:34:00 +01:00
|
|
|
(ibuffer-do-sort-by-alphabetic))))
|
2017-09-02 08:00:24 +01:00
|
|
|
: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))))
|
|
|
|
|
2018-07-07 21:52:39 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Rainbow mode.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package rainbow-mode
|
|
|
|
:defer t)
|
|
|
|
|
2017-08-27 11:52:04 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 19:21:48 +01:00
|
|
|
;; Keep point in same position on the screen when scrolling.
|
2017-08-27 11:52:04 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
2017-08-28 19:21:48 +01:00
|
|
|
(setq-default scroll-preserve-screen-position 1)
|
|
|
|
|
|
|
|
;; --------------------------------------------------------------------------
|
2017-08-28 22:19:38 +01:00
|
|
|
;; Functions.
|
2017-08-28 19:21:48 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(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)
|
2017-09-02 22:15:42 +01:00
|
|
|
(member 'fci-mode minor-mode-list))
|
2017-08-28 19:21:48 +01:00
|
|
|
(fci-mode 1))
|
|
|
|
|
|
|
|
(when (and (fboundp 'highlight-parentheses-mode)
|
2017-09-02 22:15:42 +01:00
|
|
|
highlight-parentheses-mode)
|
2017-08-28 19:21:48 +01:00
|
|
|
(highlight-parentheses-mode 1)))
|
|
|
|
|
|
|
|
;; Key-bindings -------------------------------------------------------------
|
|
|
|
|
|
|
|
;; Kill other window (cyclic order).
|
2017-08-30 01:13:35 +01:00
|
|
|
(global-set-key (kbd "C-z") 'quit-other-window)
|
2017-08-28 19:21:48 +01:00
|
|
|
|
|
|
|
;; 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 00:24:23 +01:00
|
|
|
(global-set-key (kbd "M-O") (lambda () (interactive) (other-window -1)))
|
2017-08-28 19:21:48 +01:00
|
|
|
|
|
|
|
;; Scroll up/down, but keep point in place.
|
2017-09-02 21:02:33 +01:00
|
|
|
(global-set-key (kbd "C-<") (lambda()
|
|
|
|
(interactive)
|
2017-08-28 19:21:48 +01:00
|
|
|
(let ((scroll-preserve-screen-position nil))
|
|
|
|
(scroll-down 1))))
|
2017-09-02 21:02:33 +01:00
|
|
|
(global-set-key (kbd "C->") (lambda()
|
|
|
|
(interactive)
|
2017-08-28 19:21:48 +01:00
|
|
|
(let ((scroll-preserve-screen-position nil))
|
|
|
|
(scroll-up 1))))
|
|
|
|
|
2018-07-11 19:11:55 +01:00
|
|
|
;; Recursive grep. Use only if ripgrep not present.
|
|
|
|
(unless (executable-find "rg")
|
|
|
|
(global-set-key (kbd "C-x C-g") 'rgrep))
|
2017-09-02 22:20:28 +01:00
|
|
|
|
2017-08-28 19:21:48 +01:00
|
|
|
;; Setup key-bindings for switching between themes.
|
2017-09-02 21:02:33 +01: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 19:21:48 +01:00
|
|
|
|
2017-08-28 22:19:38 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Update buffers when files change.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(global-auto-revert-mode)
|
|
|
|
|
2017-08-28 19:21:48 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; 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 22:57:19 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Address mode.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(add-hook 'prog-mode-hook 'goto-address-mode)
|
|
|
|
(add-hook 'text-mode-hook 'goto-address-mode)
|
|
|
|
|
2019-02-10 10:56:01 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Use PDF Tools instead of DocView.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package pdf-tools
|
|
|
|
:config
|
|
|
|
(pdf-tools-install))
|
|
|
|
|
2017-09-02 23:37:02 +01:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Tramp configuration.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
(use-package tramp
|
|
|
|
:defer t
|
|
|
|
:config
|
2017-09-03 17:55:28 +01: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.
|
2018-07-08 00:29:39 +01:00
|
|
|
(add-to-list 'tramp-default-proxies-alist '("localhost" "\\`root\\'" nil))
|
|
|
|
|
|
|
|
(defun sudo ()
|
|
|
|
"Use TRAMP to `sudo' the current buffer"
|
|
|
|
(interactive)
|
|
|
|
(when buffer-file-name
|
|
|
|
(find-alternate-file
|
|
|
|
(concat "/sudo:root@localhost:"
|
|
|
|
buffer-file-name)))))
|
2017-09-02 23:37:02 +01:00
|
|
|
|
2017-08-28 19:21:48 +01: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)
|
|
|
|
|
2018-12-07 20:00:21 +00:00
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
;; Add directories to exec-path.
|
|
|
|
;; --------------------------------------------------------------------------
|
|
|
|
(setq exec-path (append exec-path '("/home/wojtek/.local/bin")))
|
|
|
|
|
2019-03-17 00:39:40 +01:00
|
|
|
(use-package treemacs
|
|
|
|
:defer t
|
|
|
|
:init
|
|
|
|
(with-eval-after-load 'winum
|
|
|
|
(define-key winum-keymap (kbd "M-m") #'treemacs-select-window))
|
|
|
|
:config
|
|
|
|
(progn
|
|
|
|
(setq treemacs-collapse-dirs (if (executable-find "python") 3 0)
|
|
|
|
treemacs-deferred-git-apply-delay 0.5
|
|
|
|
treemacs-display-in-side-window t
|
|
|
|
treemacs-file-event-delay 5000
|
|
|
|
treemacs-file-follow-delay 0.2
|
|
|
|
treemacs-follow-after-init t
|
|
|
|
treemacs-git-command-pipe ""
|
|
|
|
treemacs-goto-tag-strategy 'refetch-index
|
|
|
|
treemacs-indentation 2
|
|
|
|
treemacs-indentation-string " "
|
|
|
|
treemacs-is-never-other-window t
|
|
|
|
treemacs-max-git-entries 5000
|
|
|
|
treemacs-no-png-images nil
|
|
|
|
treemacs-no-delete-other-windows t
|
|
|
|
treemacs-project-follow-cleanup nil
|
|
|
|
treemacs-persist-file (expand-file-name ".cache/treemacs-persist" user-emacs-directory)
|
|
|
|
treemacs-recenter-distance 0.1
|
|
|
|
treemacs-recenter-after-file-follow nil
|
|
|
|
treemacs-recenter-after-tag-follow nil
|
|
|
|
treemacs-recenter-after-project-jump 'always
|
|
|
|
treemacs-recenter-after-project-expand 'on-distance
|
|
|
|
treemacs-show-cursor nil
|
|
|
|
treemacs-show-hidden-files t
|
|
|
|
treemacs-silent-filewatch nil
|
|
|
|
treemacs-silent-refresh nil
|
|
|
|
treemacs-sorting 'alphabetic-desc
|
|
|
|
treemacs-space-between-root-nodes t
|
|
|
|
treemacs-tag-follow-cleanup t
|
|
|
|
treemacs-tag-follow-delay 1.5
|
|
|
|
treemacs-width 35)
|
|
|
|
|
|
|
|
;; The default width and height of the icons is 22 pixels. If you are
|
|
|
|
;; using a Hi-DPI display, uncomment this to double the icon size.
|
|
|
|
;;(treemacs-resize-icons 44)
|
|
|
|
|
|
|
|
(treemacs-follow-mode t)
|
|
|
|
(treemacs-filewatch-mode t)
|
|
|
|
(treemacs-fringe-indicator-mode t)
|
|
|
|
(pcase (cons (not (null (executable-find "git")))
|
|
|
|
(not (null (executable-find "python3"))))
|
|
|
|
(`(t . t)
|
|
|
|
(treemacs-git-mode 'deferred))
|
|
|
|
(`(t . _)
|
|
|
|
(treemacs-git-mode 'simple))))
|
|
|
|
|
|
|
|
:bind
|
|
|
|
(:map global-map
|
|
|
|
("M-m" . treemacs-select-window)
|
|
|
|
("C-x t 1" . treemacs-delete-other-windows)
|
|
|
|
("C-x t t" . treemacs)
|
|
|
|
("C-x t B" . treemacs-bookmark)
|
|
|
|
("C-x t C-t" . treemacs-find-file)
|
|
|
|
("C-x t M-t" . treemacs-find-tag)))
|
|
|
|
|
|
|
|
(use-package treemacs-projectile
|
|
|
|
:after treemacs projectile)
|
|
|
|
|
|
|
|
(use-package treemacs-icons-dired
|
|
|
|
:after treemacs dired
|
|
|
|
:config (treemacs-icons-dired-mode))
|
|
|
|
|
|
|
|
(use-package treemacs-magit
|
|
|
|
:after treemacs magit)
|
|
|
|
|
2017-08-27 11:52:04 +01:00
|
|
|
)
|
2018-07-07 21:34:00 +01:00
|
|
|
|
|
|
|
(provide 'em-emacs)
|
|
|
|
;;; em-emacs.el ends here
|