~chambln/dots

ref: 8c1b88ef6cd0fdc96cf4996ca5f2172f5edd594f dots/pkgs/emacs/.emacs.d/init.el -rw-r--r-- 5.5 KiB
8c1b88efGregory Chamberlain Fix whitespace a month ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
;; Enable extra Dired functionality.
(require 'dired-x nil 'noerror)

;; Simple macro for selecting and configuring packages.
(require 'package)
(defmacro with-package (package &rest body)
  "Add PACKAGE to ‘package-selected-packages’, then
attempt to ‘require’ PACKAGE and, if successful,
evaluate BODY."
  (declare (indent 1))
  `(and (add-to-list 'package-selected-packages ,package)
        (require ,package nil 'noerror)
        (progn ,@body)))

;; Add package repositories.
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)

;; Custom functions.

(defun transpose-windows (arg)
  "Transpose the buffers shown in two windows."
  (interactive "p")
  (let ((selector (if (< arg 0) #'previous-window #'next-window)))
    (dotimes (_ (abs arg))
      (let ((this-win (window-buffer))
            (next-win (window-buffer (funcall selector))))
        (set-window-buffer (selected-window) next-win)
        (set-window-buffer (funcall selector) this-win)
        (select-window (funcall-selector))))))

(defun shrink-other-window-if-larger-than-buffer ()
  "Shrink height of ‘other-window’ if its buffer doesn’t need so
many lines.  See also ‘shrink-window-if-larger-than-buffer’."
  (interactive)
  (shrink-window-if-larger-than-buffer (next-window)))

(defun kill-other-buffer-and-window (count)
  "Delete other window, killing its buffer.  See `other-window'."
  (interactive "p")
  (other-window (or count 1))
  (kill-buffer-and-window))

(defun switch-theme (theme)
  "Load THEME, disabling all others."
  (interactive
   (let ((prompt "Switch to custom theme: ")
         (collection (custom-available-themes)))
     (list (completing-read prompt collection nil t))))
  (mapc #'disable-theme custom-enabled-themes)
  (when theme (load-theme (intern-soft theme))))

(defun diff-current-buffer-dwim ()
  "Compare the present buffer with its associated file or file
revision."
  (interactive)
  (if (buffer-modified-p)
      (diff-buffer-with-file (current-buffer))
    (vc-diff)))

;; Disable noob-friendly settings, GUI elements, sounds, etc.
(setq disabled-command-function nil)
(setq enable-recursive-minibuffers t)
(scroll-bar-mode 0)
(tool-bar-mode 0)
(menu-bar-mode 0)
(setq ring-bell-function (lambda nil))

;; Disable interactive pager.
(setenv "PAGER" "cat")

;; Allow scrolling during incremental search.
(setq isearch-allow-scroll t)

;; Keep file backups in one place.
(setq backup-directory-alist
      `(("." . ,(expand-file-name "backups" user-emacs-directory))))

;; Always indent with spaces.
(setq-default indent-tabs-mode nil)

;; Always use view-mode with read-only buffers.
(setq view-read-only t)

;; Enable visualisation of matching parentheses.
(setq show-paren-delay 0)
(show-paren-mode 1)

;; Display date and time in the mode line.
(setq display-time-default-load-average nil
      display-time-format " %d %a %H:%M ")

;; Completion settings.
(add-to-list 'completion-styles 'substring t)
(setq completion-ignore-case t)
(setq read-file-name-completion-ignore-case t)
(setq read-buffer-completion-ignore-case t)

;; Consider all themes to be safe.
(setq custom-safe-themes t)

;; Use ‘hl-line-mode’ with line-oriented modes.
(dolist (hook '(tabulated-list-mode-hook
                dired-mode-hook
                ibuffer-hook
                eww-bookmark-mode-hook
                bookmark-bmenu-mode-hook
                occur-mode-hook
                finder-mode-hook
                gnus-summary-mode-hook
                gnus-group-mode-hook
                vc-dir-mode-hook
                vc-git-log-view-mode-hook
                org-agenda-mode-hook
                authinfo-mode-hook))
  (add-hook hook #'hl-line-mode))

;; Global key bindings.
(global-set-key (kbd "<f5>") #'switch-theme)
(global-set-key (kbd "C-z") #'previous-buffer)
(global-set-key (kbd "C-M-z") #'next-buffer)
(global-set-key (kbd "C-x c") #'compile)
(global-set-key (kbd "C-x 7") #'calendar)
(global-set-key (kbd "C-h C-o") (kbd "C-h o RET"))
(global-set-key (kbd "C-x C-o") (kbd "C-u - C-x o"))
(global-set-key (kbd "C-x C-k") #'kill-this-buffer)
(global-set-key (kbd "C-x C-b") #'ibuffer)
(global-set-key (kbd "C-x 4 k") #'kill-other-buffer-and-window)
(global-set-key (kbd "C-x 4 t") #'transpose-windows)
(global-set-key (kbd "C-x r 4 b") #'bookmark-jump-other-window)
(global-set-key (kbd "C-x 4 -") #'shrink-other-window-if-larger-than-buffer)
(global-set-key (kbd "C-x x t") #'toggle-truncate-lines)
(global-set-key (kbd "C-x x g") #'revert-buffer)
(global-set-key (kbd "C-x v =") #'diff-current-buffer-dwim)

;; Esperantaj klavoj.
(global-set-key (kbd "C-ŝ") (lookup-key global-map (kbd "C-q")))
(global-set-key (kbd "C-ĝ") (lookup-key global-map (kbd "C-w")))
(global-set-key (kbd "C-ŭ") (lookup-key global-map (kbd "C-y")))
(global-set-key (kbd "C-ĵ") (lookup-key global-map (kbd "C-[")))
(global-set-key (kbd "C-ĥ") (lookup-key global-map (kbd "C-]")))
(global-set-key (kbd "C-ĉ") (lookup-key global-map (kbd "C-x")))

(with-package 'remember
  (setq remember-notes-initial-major-mode #'outline-mode)
  (global-set-key (kbd "C-x r e m") #'remember)
  (global-set-key (kbd "C-x r e l") #'remember-notes))

(with-package 'modus-themes
  (setq modus-themes-bold-constructs t)
  (setq modus-themes-italic-constructs t)
  (setq modus-themes-variable-pitch-ui t)
  (setq modus-themes-syntax '(yellow-comments green-strings))
  (setq modus-themes-prompts '(bold))
  (setq modus-themes-mode-line '(accented))
  (unless custom-enabled-themes (load-theme 'modus-operandi t)))

(with-package 'magit
  (global-set-key (kbd "C-x g") #'magit-status))