emacs/lisp/acdw.el

84 lines
2.2 KiB
EmacsLisp

:;;; 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