summaryrefslogtreecommitdiffstats
path: root/.emacs.d/init.el
blob: 9267ce4eb8b71aea88ed07962c742548aab24d61 (plain) (blame)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
;;; init.el --- bandali's emacs configuration -*- lexical-binding: t -*-

;; Copyright (c) 2018-2025 Amin Bandali <bandali@gnu.org>

;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with this program.  If not, see <https://www.gnu.org/licenses/>.

;;; Commentary:

;; bandali's opinionated GNU Emacs configs.  I tend to use the latest
;; development trunk of emacs.git, but I try to maintain backward
;; compatibility with a few of the recent older GNU Emacs releases
;; so I could easily reuse it on machines stuck with older Emacsen.

;;; Code:

;; whoami
(setq
 user-full-name "Amin Bandali"
 user-mail-address "bandali@kelar.org")


;;; Package management

(setq
 use-package-verbose init-file-debug
 use-package-expand-minimally (not init-file-debug)
 use-package-compute-statistics init-file-debug
 debug-on-error init-file-debug
 debug-on-quit init-file-debug)

(require 'package)
;; Install use-package on older Emascen if needed.
(when (< emacs-major-version 29)
  (unless (package-installed-p 'use-package)
    (unless package-archive-contents
      (package-refresh-contents))
    (package-install 'use-package)))


;;; Initial setup

(eval-and-compile
  (defsubst b/emacs.d (path)
    "Expand path PATH relative to `user-emacs-directory'."
    (expand-file-name
     (convert-standard-filename path) user-emacs-directory))

  ;; Wrappers around the new keybinding functions, with fallback to
  ;; the corresponding older lower level function on older Emacsen.
  (defsubst b/keymap-set (keymap key definition)
    (if (version< emacs-version "29")
        (define-key keymap (kbd key) definition)
      (keymap-set keymap key definition)))
  (defsubst b/keymap-global-set (key command)
    (if (version< emacs-version "29")
        (global-set-key (kbd key) command)
      (keymap-global-set key command)))
  (defsubst b/keymap-local-set (key command)
    (if (version< emacs-version "29")
        (local-set-key (kbd key) command)
      (keymap-local-set key command)))
  (defsubst b/keymap-global-unset (key)
    (if (version< emacs-version "29")
        (global-unset-key (kbd key))
      (keymap-global-unset key 'remove)))
  (defsubst b/keymap-local-unset (key)
    (if (version< emacs-version "29")
        (local-unset-key (kbd key))
      (keymap-local-unset key 'remove)))

  (when (version< emacs-version "29")
    ;; Emacs 29 introduced the handy `setopt' macro for setting user
    ;; options (defined with `defcustom') with a syntax similar to
    ;; `setq'.  So, we define it on older Emacsen that don't have it.
    (defmacro setopt (&rest pairs)
      "Set VARIABLE/VALUE pairs, and return the final VALUE.
This is like `setq', but is meant for user options instead of
plain variables.  This means that `setopt' will execute any
`custom-set' form associated with VARIABLE.

\(fn [VARIABLE VALUE]...)"
      (declare (debug setq))
      (unless (zerop (mod (length pairs) 2))
        (error "PAIRS must have an even number of variable/value members"))
      (let ((expr nil))
        (while pairs
          (unless (symbolp (car pairs))
            (error "Attempting to set a non-symbol: %s" (car pairs)))
          (push `(setopt--set ',(car pairs) ,(cadr pairs))
                expr)
          (setq pairs (cddr pairs)))
        (macroexp-progn (nreverse expr))))

    (defun setopt--set (variable value)
      (custom-load-symbol variable)
      ;; Check that the type is correct.
      (when-let ((type (get variable 'custom-type)))
        (unless (widget-apply (widget-convert type) :match value)
          (warn "Value `%S' does not match type %s" value type)))
      (put variable 'custom-check-value (list value))
      (funcall (or (get variable 'custom-set) #'set-default) variable value))))

;; Separate custom file (don't want it mixing with init.el).
(setopt custom-file (b/emacs.d "custom.el"))
(with-eval-after-load 'custom
  (load custom-file 'noerror))

;; Start Emacs server
;; https://www.gnu.org/software/emacs/manual/html_node/emacs/Emacs-Server.html
(run-with-idle-timer 0.5 nil #'require 'server)
(with-eval-after-load 'server
  (declare-function server-edit "server")
  (b/keymap-global-set "C-c F D" #'server-edit)
  (declare-function server-running-p "server")
  (or (server-running-p) (server-mode)))


;;; Essential packages

(add-to-list 'load-path (b/emacs.d "lisp"))

(require 'bandali-essentials)
(require 'bandali-prog)
;; (require 'bandali-exwm)
(require 'bandali-eshell)
(require 'bandali-ibuffer)
(require 'bandali-dired)
;;; Email with Gnus and message
(require 'bandali-gnus)
(require 'bandali-message)
;; (with-eval-after-load 'sendmail
;;   (setopt mail-header-separator ""))
;; (with-eval-after-load 'smtpmail
;;   (setopt smtpmail-queue-mail t
;;           smtpmail-queue-dir (concat b/maildir "queue/")))
;;; IRC with ERC
(require 'bandali-erc)
;; (require 'bandali-misc)
(require 'bandali-po)


;;; Emacs enhancements & auxiliary packages
;; `debbugs'
(b/keymap-global-set "C-c D d" #'debbugs-gnu)
(b/keymap-global-set "C-c D b" #'debbugs-gnu-bugs)
(b/keymap-global-set "C-c D e"          ; bug-gnu-emacs
                (lambda ()
                  (interactive)         
                  (setq debbugs-gnu-current-suppress t)
                  (debbugs-gnu debbugs-gnu-default-severities
                               '("emacs"))))
(b/keymap-global-set "C-c D g"          ; bug-gnuzilla
                (lambda ()
                  (interactive)
                  (setq debbugs-gnu-current-suppress t)
                  (debbugs-gnu debbugs-gnu-default-severities
                               '("gnuzilla"))))

(use-package mml
  :delight " mml")

(add-to-list 'load-path (b/emacs.d "lisp/ffs"))
(run-with-idle-timer 0.5 nil #'require 'ffs)
(with-eval-after-load 'ffs
  (setopt ffs-default-face-height 250)
  (global-set-key (kbd "C-c f s") #'ffs))
(add-hook 'ffs-start-hook
          (lambda ()
            (mapc
             (lambda (mode) (funcall mode 1)) ; enable
             '(ffs--no-mode-line-minor-mode
               ffs--no-cursor-minor-mode))
            (mapc
             (lambda (mode) (funcall mode -1)) ; disable
             '(show-paren-local-mode
               display-battery-mode
               display-fill-column-indicator-mode
               flyspell-mode
               tool-bar-mode
               menu-bar-mode
               scroll-bar-mode))
            (fringe-mode 0)))
(add-hook 'ffs-quit-hook
          (lambda ()
            (mapc
             (lambda (mode) (funcall mode -1)) ; disable
             '(ffs--no-mode-line-minor-mode
               ffs--no-cursor-minor-mode))
            (mapc
             (lambda (mode) (funcall mode 1)) ; enable
             '(show-paren-local-mode
               display-battery-mode
               display-fill-column-indicator-mode
               flyspell-mode
               tool-bar-mode
               menu-bar-mode
               scroll-bar-mode))
            (fringe-mode nil)))

(add-to-list 'load-path (b/emacs.d "lisp/debian-el"))
(run-with-idle-timer 0.5 nil #'require 'debian-el)
(with-eval-after-load 'debian-el
  (require 'apt-sources)
  (require 'apt-utils)
  (require 'debian-bug)
  (require 'deb-view)
  (require 'gnus-BTS)
  (require 'preseed))

(add-to-list 'load-path (b/emacs.d "lisp/dpkg-dev-el"))
(run-with-idle-timer 0.5 nil #'require 'dpkg-dev-el)
(with-eval-after-load 'dpkg-dev-el
  (require 'debian-changelog-mode)
  (require 'debian-bts-control)
  (require 'debian-changelog-mode)
  (require 'debian-control-mode)
  (require 'debian-copyright)
  (require 'readme-debian))

;;; init.el ends here