Massively refactor
- Redefine as much as possible as `setup' forms - Reorganize into "Setup", "Basics", and "Packages" sections - Within each section, alphabetize sexps - Also (mostly) alphabetize acdw- files - (Not the ones that are almost completely others' code) - Sidebar: Why is this not a thing in elisp!? Should write a function - Break karthink's thing into another library `acdw-re' - Add a function to `acdw': `acdw/find-emacs-source' - Should refactor that to better find the source I think everything looks much more better now!
This commit is contained in:
parent
27ae0a2ab8
commit
407771183e
|
@ -22,64 +22,60 @@
|
|||
(require 'simple-modeline)
|
||||
(require 'minions)
|
||||
|
||||
;; modified from `simple-modeline'
|
||||
(defun acdw-modeline/modified ()
|
||||
"Displays a color-coded buffer modification/read-only
|
||||
indicator in the mode-line."
|
||||
(if (not (string-match-p "\\*.*\\*" (buffer-name)))
|
||||
(let* ((read-only (and buffer-read-only (buffer-file-name)))
|
||||
(modified (buffer-modified-p)))
|
||||
(propertize
|
||||
(if read-only " =" (if modified " +" " -"))
|
||||
'help-echo (format
|
||||
(concat "Buffer is %s and %smodified\n"
|
||||
"mouse-1: Toggle read-only status.")
|
||||
(if read-only "read-only" "writable")
|
||||
(if modified "" "not "))
|
||||
'local-map (purecopy (simple-modeline-make-mouse-map
|
||||
'mouse-1
|
||||
(lambda (event)
|
||||
(interactive "e")
|
||||
(with-selected-window
|
||||
(posn-window (event-start event))
|
||||
(read-only-mode 'toggle)))))
|
||||
'mouse-face 'mode-line-highlight))))
|
||||
|
||||
;; all me, baby
|
||||
(defun acdw-modeline/minions ()
|
||||
"Display a button for `minions-minor-modes-menu'."
|
||||
(concat
|
||||
" "
|
||||
(propertize
|
||||
"&"
|
||||
'help-echo (format
|
||||
"Minor modes menu\nmouse-1: show menu.")
|
||||
'local-map (purecopy (simple-modeline-make-mouse-map
|
||||
'mouse-1
|
||||
(lambda (event)
|
||||
(interactive "e")
|
||||
(with-selected-window (posn-window
|
||||
(event-start event))
|
||||
(minions-minor-modes-menu)))))
|
||||
'mouse-face 'mode-line-highlight)))
|
||||
|
||||
;; from https://www.gonsie.com/blorg/modeline.html, from Doom
|
||||
(defun acdw-modeline/vc-branch ()
|
||||
(if-let ((backend (vc-backend buffer-file-name)))
|
||||
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))
|
||||
|
||||
;; from gonsie
|
||||
(defun acdw-modeline/buffer-name ()
|
||||
(defun acdw-modeline/buffer-name () ; gonsie
|
||||
(propertize " %b "
|
||||
'face
|
||||
(if (buffer-modified-p)
|
||||
'font-lock-warning-face
|
||||
'font-lock-type-face)
|
||||
'help-echo (buffer-file-name)))
|
||||
'face
|
||||
(if (buffer-modified-p)
|
||||
'font-lock-warning-face
|
||||
'font-lock-type-face)
|
||||
'help-echo (buffer-file-name)))
|
||||
|
||||
;; god-mode indicator
|
||||
(defun acdw-modeline/god-mode-indicator ()
|
||||
(when (bound-and-true-p god-local-mode)
|
||||
" God"))
|
||||
|
||||
(defun acdw-modeline/modified () ; modified from `simple-modeline'
|
||||
"Displays a color-coded buffer modification/read-only
|
||||
indicator in the mode-line."
|
||||
(if (not (string-match-p "\\*.*\\*" (buffer-name)))
|
||||
(let* ((read-only (and buffer-read-only (buffer-file-name)))
|
||||
(modified (buffer-modified-p)))
|
||||
(propertize
|
||||
(if read-only " =" (if modified " +" " -"))
|
||||
'help-echo (format
|
||||
(concat "Buffer is %s and %smodified\n"
|
||||
"mouse-1: Toggle read-only status.")
|
||||
(if read-only "read-only" "writable")
|
||||
(if modified "" "not "))
|
||||
'local-map (purecopy (simple-modeline-make-mouse-map
|
||||
'mouse-1
|
||||
(lambda (event)
|
||||
(interactive "e")
|
||||
(with-selected-window
|
||||
(posn-window (event-start event))
|
||||
(read-only-mode 'toggle)))))
|
||||
'mouse-face 'mode-line-highlight))))
|
||||
|
||||
(defun acdw-modeline/minions () ; by me
|
||||
"Display a button for `minions-minor-modes-menu'."
|
||||
(concat
|
||||
" "
|
||||
(propertize
|
||||
"&"
|
||||
'help-echo (format
|
||||
"Minor modes menu\nmouse-1: show menu.")
|
||||
'local-map (purecopy (simple-modeline-make-mouse-map
|
||||
'mouse-1
|
||||
(lambda (event)
|
||||
(interactive "e")
|
||||
(with-selected-window (posn-window
|
||||
(event-start event))
|
||||
(minions-minor-modes-menu)))))
|
||||
'mouse-face 'mode-line-highlight)))
|
||||
|
||||
(defun acdw-modeline/vc-branch ()
|
||||
;; from https://www.gonsie.com/blorg/modeline.html, from Doom
|
||||
(if-let ((backend (vc-backend buffer-file-name)))
|
||||
(substring vc-mode (+ (if (eq backend 'Hg) 2 3) 2))))
|
||||
|
||||
(provide 'acdw-modeline)
|
||||
|
|
|
@ -0,0 +1,66 @@
|
|||
;;; acdw-re.el -*- lexical-binding: t; coding: utf-8-unix -*-
|
||||
;; Author: Case Duckworth <acdw@acdw.net>
|
||||
;; Created: 2021-04-29
|
||||
;; Keywords: configuration
|
||||
;; URL: https://tildegit.org/acdw/emacs
|
||||
|
||||
;; 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:
|
||||
;; Pulled mostly from karthinks:
|
||||
;; https://karthinks.com/software/bridging-islands-in-emacs-1/
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defvar acdw/re-builder-positions nil
|
||||
"Store point and region bounds before calling re-builder")
|
||||
|
||||
(defun acdw/re-builder-save-state (&rest _)
|
||||
"Save into `acdw/re-builder-positions' the point and region
|
||||
positions before calling `re-builder'."
|
||||
(setq acdw/re-builder-positions
|
||||
(cons (point)
|
||||
(when (region-active-p)
|
||||
(list (region-beginning)
|
||||
(region-end))))))
|
||||
|
||||
(defun reb-replace-regexp (&optional delimited)
|
||||
"Run `query-replace-regexp' with the contents of re-builder. With
|
||||
non-nil optional argument DELIMITED, only replace matches
|
||||
surrounded by word boundaries."
|
||||
(interactive "P")
|
||||
(reb-update-regexp)
|
||||
(let* ((re (reb-target-binding reb-regexp))
|
||||
(replacement (query-replace-read-to
|
||||
re
|
||||
(concat "Query replace"
|
||||
(if current-prefix-arg
|
||||
(if (eq current-prefix-arg '-)
|
||||
" backward"
|
||||
" word")
|
||||
"")
|
||||
" regexp"
|
||||
(if (with-selected-window reb-target-window
|
||||
(region-active-p)) " in region" ""))
|
||||
t))
|
||||
(pnt (car acdw/re-builder-positions))
|
||||
(beg (cadr acdw/re-builder-positions))
|
||||
(end (caddr acdw/re-builder-positions)))
|
||||
(with-selected-window reb-target-window
|
||||
;; replace with (goto-char (match-beginning 0)) if you want to control
|
||||
;; where in the buffer the replacement starts with re-builder
|
||||
(goto-char pnt)
|
||||
(setq acdw/re-builder-positions nil)
|
||||
(reb-quit)
|
||||
(query-replace-regexp re replacement delimited beg end))))
|
||||
|
||||
(provide 'acdw-re)
|
||||
|
||||
;;; acdw-re.el ends here
|
129
lisp/acdw.el
129
lisp/acdw.el
|
@ -19,7 +19,7 @@
|
|||
|
||||
;;; Code:
|
||||
|
||||
;; Utility constants
|
||||
;;; Variables
|
||||
|
||||
(defconst acdw/system (pcase system-type
|
||||
('gnu/linux :home)
|
||||
|
@ -28,19 +28,15 @@
|
|||
"Which computer system is currently being used.")
|
||||
|
||||
|
||||
;; Utility functions
|
||||
;;; Utility functions
|
||||
|
||||
(defmacro when-unfocused (name &rest forms)
|
||||
"Define a function NAME, executing FORMS, that fires when Emacs
|
||||
is unfocused."
|
||||
(declare (indent 1))
|
||||
(let ((func-name (intern (concat "when-unfocused-" (symbol-name name)))))
|
||||
`(progn
|
||||
(defun ,func-name () "Defined by `when-unfocused'."
|
||||
(when (seq-every-p #'null
|
||||
(mapcar #'frame-focus-state (frame-list)))
|
||||
,@forms))
|
||||
(add-function :after after-focus-change-function #',func-name))))
|
||||
(defun expand-file-name-exists-p (&rest expand-file-name-args)
|
||||
"Call `expand-file-name' on EXPAND-FILE-NAME-ARGS, returning
|
||||
its name if it exists, or NIL otherwise."
|
||||
(let ((file (apply #'expand-file-name expand-file-name-args)))
|
||||
(if (file-exists-p file)
|
||||
file
|
||||
nil)))
|
||||
|
||||
(defmacro hook-defun (name hooks &rest forms)
|
||||
"Define a function NAME that executes FORMS, and add it to
|
||||
|
@ -88,13 +84,17 @@ With a prefix argument, run git pull on the repo first."
|
|||
(when (file-exists-p file)
|
||||
(load-file file))))))
|
||||
|
||||
(defun expand-file-name-exists-p (&rest expand-file-name-args)
|
||||
"Call `expand-file-name' on EXPAND-FILE-NAME-ARGS, returning
|
||||
its name if it exists, or NIL otherwise."
|
||||
(let ((file (apply #'expand-file-name expand-file-name-args)))
|
||||
(if (file-exists-p file)
|
||||
file
|
||||
nil)))
|
||||
(defmacro when-unfocused (name &rest forms)
|
||||
"Define a function NAME, executing FORMS, that fires when Emacs
|
||||
is unfocused."
|
||||
(declare (indent 1))
|
||||
(let ((func-name (intern (concat "when-unfocused-" (symbol-name name)))))
|
||||
`(progn
|
||||
(defun ,func-name () "Defined by `when-unfocused'."
|
||||
(when (seq-every-p #'null
|
||||
(mapcar #'frame-focus-state (frame-list)))
|
||||
,@forms))
|
||||
(add-function :after after-focus-change-function #',func-name))))
|
||||
|
||||
(defmacro with-message (message &rest body)
|
||||
"Execute BODY, messaging 'MESSAGE...' before and 'MESSAGE... Done.' after."
|
||||
|
@ -105,6 +105,9 @@ With a prefix argument, run git pull on the repo first."
|
|||
,@body)
|
||||
(message "%s... Done." ,message)))
|
||||
|
||||
|
||||
;;; Specialized functions
|
||||
|
||||
(defun acdw/dir (&optional file make-directory)
|
||||
"Place Emacs files in one place.
|
||||
|
||||
|
@ -122,16 +125,56 @@ if MAKE-DIRECTORY is non-nil."
|
|||
file-name)
|
||||
dir)))
|
||||
|
||||
(defun acdw/gc-enable ()
|
||||
"Enable the Garbage collector."
|
||||
(setq gc-cons-threshold (* 800 1024 1024)
|
||||
gc-cons-percentage 0.1))
|
||||
(defun acdw/find-emacs-dotfiles ()
|
||||
"Finds lisp files in `user-emacs-directory' and passes them to
|
||||
`completing-read'."
|
||||
(interactive)
|
||||
(find-file (completing-read ".emacs: "
|
||||
(directory-files-recursively
|
||||
user-emacs-directory "\.el$"))))
|
||||
|
||||
(defun acdw/find-emacs-source ()
|
||||
"Find where Emacs keeps its source tree."
|
||||
(pcase acdw/system
|
||||
(:work (expand-file-name
|
||||
(concat "~/src/emacs-" emacs-version "/src")))
|
||||
(:home (expand-file-name "~/src/pkg/emacs/src/emacs-git/src"))
|
||||
(:other nil)))
|
||||
|
||||
(defun acdw/gc-disable ()
|
||||
"Functionally disable the Garbage collector."
|
||||
(setq gc-cons-threshold most-positive-fixnum
|
||||
gc-cons-percentage 0.8))
|
||||
|
||||
(defun acdw/gc-enable ()
|
||||
"Enable the Garbage collector."
|
||||
(setq gc-cons-threshold (* 800 1024 1024)
|
||||
gc-cons-percentage 0.1))
|
||||
|
||||
(defun acdw/insert-iso-date (with-time)
|
||||
"Insert the ISO-8601-formatted date, with optional time."
|
||||
(interactive "P")
|
||||
(let ((format (if with-time "%FT%T%z" "%F")))
|
||||
(insert (format-time-string format (current-time)))))
|
||||
|
||||
(defun acdw/kill-a-buffer (&optional prefix)
|
||||
"Kill a buffer based on the following rules:
|
||||
|
||||
C-x k => Kill CURRENT buffer and window
|
||||
C-u C-x k => Kill OTHER buffer and window
|
||||
C-u C-u C-x k => Kill ALL OTHER buffers and windows
|
||||
|
||||
Prompt only if there are unsaved changes."
|
||||
(interactive "P")
|
||||
(pcase (or (car prefix) 0)
|
||||
(0 (kill-current-buffer)
|
||||
(unless (one-window-p) (delete-window)))
|
||||
(4 (other-window 1)
|
||||
(kill-current-buffer)
|
||||
(unless (one-window-p) (delete-window)))
|
||||
(16 (mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
|
||||
(delete-other-windows))))
|
||||
|
||||
(defun acdw/sunrise-sunset (sunrise-command sunset-command)
|
||||
"Run commands at sunrise and sunset."
|
||||
(let* ((times-regex (rx (* nonl)
|
||||
|
@ -153,40 +196,9 @@ if MAKE-DIRECTORY is non-nil."
|
|||
(run-at-time sunset-time (* 60 60 24) sunset-command)
|
||||
(run-at-time "12:00am" (* 60 60 24) sunset-command)))
|
||||
|
||||
(defun acdw/find-emacs-dotfiles ()
|
||||
"Finds lisp files in `user-emacs-directory' and passes them to
|
||||
`completing-read'."
|
||||
(interactive)
|
||||
(find-file (completing-read ".emacs: "
|
||||
(directory-files-recursively
|
||||
user-emacs-directory "\.el$"))))
|
||||
|
||||
(defun acdw/kill-a-buffer (&optional prefix)
|
||||
"Kill a buffer based on the following rules:
|
||||
|
||||
C-x k => Kill CURRENT buffer and window
|
||||
C-u C-x k => Kill OTHER buffer and window
|
||||
C-u C-u C-x k => Kill ALL OTHER buffers and windows
|
||||
|
||||
Prompt only if there are unsaved changes."
|
||||
(interactive "P")
|
||||
(pcase (or (car prefix) 0)
|
||||
(0 (kill-current-buffer)
|
||||
(unless (one-window-p) (delete-window)))
|
||||
(4 (other-window 1)
|
||||
(kill-current-buffer)
|
||||
(unless (one-window-p) (delete-window)))
|
||||
(16 (mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
|
||||
(delete-other-windows))))
|
||||
|
||||
(defun acdw/insert-iso-date (with-time)
|
||||
"Insert the ISO-8601-formatted date, with optional time."
|
||||
(interactive "P")
|
||||
(let ((format (if with-time "%FT%T%z" "%F")))
|
||||
(insert (format-time-string format (current-time)))))
|
||||
|
||||
|
||||
;; Make `C-z' more useful
|
||||
;;; Keymaps
|
||||
|
||||
(defvar acdw/leader
|
||||
(let ((map (make-sparse-keymap))
|
||||
(c-z (global-key-binding "\C-z")))
|
||||
|
@ -195,7 +207,8 @@ Prompt only if there are unsaved changes."
|
|||
map))
|
||||
|
||||
|
||||
;; `acdw/reading-mode'
|
||||
;;; Minor modes
|
||||
|
||||
(define-minor-mode acdw/reading-mode
|
||||
"A mode for reading."
|
||||
:init-value nil
|
||||
|
|
Loading…
Reference in New Issue