summary refs log tree commit diff stats
path: root/lisp/acdw.el
blob: 03e4a62f0f7d455b82fabbc0298fcfe4a80a95b4 (plain)
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
:;;; acdw.el -*- lexical-binding: t; coding: utf-8-unix -*-
;;
;; Author: Case Duckworth <acdw@acdw.net>
;; Created: Sometime during Covid-19, 2020
;; Keywords: configuration
;; URL: https://tildegit.org/acdw/emacs
;; Bankruptcy: 5b
;;
;; This file is NOT part of GNU Emacs.
;;
;;; License:
;;
;; Everyone is permitted to do whatever with this software, without
;; limitation.  This software comes without any warranty whatsoever,
;; but with two pieces of advice:
;; - Don't hurt yourself.
;; - Make good choices.
;;
;;; Commentary:
;; `acdw.el' contains `acdw/map', its mode, and assorted ease-of-life
;; functions for me, acdw.
;;
;;; Code:

;;; Directories (think `no-littering')

(defvar acdw/dir (expand-file-name
		  (convert-standard-filename "var/")
		  user-emacs-directory)
  "A directory to hold extra configuration and emacs data.")

(defun acdw/in-dir (file &optional make-directory)
  "Expand FILE relative to `acdw/dir', optionally creating its
directory."
  (let ((f (expand-file-name (convert-standard-filename file)
			     acdw/dir)))
    (when make-directory
      (make-directory (file-name-directory) 'parents))
    f))

;;; Settings

(defun acdw/set (assignments)
  "Perform `customize-set-variable' on each of ASSIGNMENTS.

ASSIGNMENTS is a list where each element is of the form
(VARIABLE VALUE [COMMENT])."
  (dolist (assn assignments)
    (customize-set-variable (car assignment)
			    (cadr assignment)
			    (if (and (caddr assignment)
				     (stringp (caddr assignment)))
				(caddr assignment)
			      "Customized by `acdw/set'."))))

;;; Keymap & Mode

(defvar acdw/map (make-sparse-keymap)
  "A keymap for my custom bindings.")

(define-minor-mode acdw/mode
  "A mode for `acdw/map'."
  :init-value t
  :lighter " acdw"
  :keymap acdw/map)
(define-globalized-minor-mode acdw/global-mode acdw/mode acdw/mode)

;; Disable `acdw/mode' in the minibuffer
(defun acdw/mode--disable ()
  "Disable `acdw/mode'."
  (acdw/mode -1))
(add-hook 'minibuffer-setup-hook #'acdw/mode--disable)

;; Set up a leader key for `acdw/mode'
(defvar acdw/leader
  (let ((map (make-sparse-keymap))
	(c-z (global-key-binding "\C-z")))
    (define-key acdw/map "\C-z" map)
    (define-key map "\C-z" c-z)
    map))

(provide 'acdw)
;;; acdw.el ends here