diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-29 04:41:40 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-29 04:41:40 -0400 |
| commit | 37d53dacf0636ae299b092b54dde78c0658a51c1 (patch) | |
| tree | 6eb61c1a9220bbbf13bafc931476d87b61c5b27d /modules/custom-format.el | |
| parent | 256027866f9ff2cbc3b6155950f21a92b54ea307 (diff) | |
| download | dotemacs-37d53dacf0636ae299b092b54dde78c0658a51c1.tar.gz dotemacs-37d53dacf0636ae299b092b54dde78c0658a51c1.zip | |
refactor: split custom-misc.el into focused modules
custom-misc.el was an incoherent grab-bag, so anything small defaulted to landing there. I split its eight commands by concern. Three moved into new modules: custom-format (region/buffer reformat), custom-counts (word and character counts), and custom-text-transform (fraction glyphs). The other three went to existing homes: the previous-buffer toggle to custom-buffer-file, the delimiter jump to custom-line-paragraph, and the align-regexp space advice with its alignment and fill bindings to custom-whitespace.
The C-; bindings, which-key labels, and the six test files moved with their functions, and custom-misc.el is deleted. No behavior change: every command keeps its name and its C-; key.
Diffstat (limited to 'modules/custom-format.el')
| -rw-r--r-- | modules/custom-format.el | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/modules/custom-format.el b/modules/custom-format.el new file mode 100644 index 000000000..47cd7d88d --- /dev/null +++ b/modules/custom-format.el @@ -0,0 +1,46 @@ +;;; custom-format.el --- Region and buffer reformatting -*- coding: utf-8; lexical-binding: t; -*- + +;;; Commentary: +;; +;; Layer: 2 (Core UX). +;; Category: L. +;; Load shape: eager. +;; Eager reason: registers its C-; f command binding at load. +;; Top-level side effects: binds cj/format-region-or-buffer under C-; f. +;; Runtime requires: keybindings. +;; Direct test load: yes (requires keybindings explicitly). +;; +;; Reformat the active region, or the whole buffer when no region is active: +;; untabify, reindent, and delete trailing whitespace. Split out of the +;; former custom-misc.el grab-bag. + +;;; Code: + +(require 'keybindings) ;; provides cj/register-command + +(defun cj/--format-region (start end) + "Internal implementation: Reformat text between START and END. +START and END define the region to operate on. +Replaces tabs with spaces, reindents, and deletes trailing whitespace." + (when (> start end) + (error "Invalid region: start (%d) is greater than end (%d)" start end)) + (save-excursion + (save-restriction + (narrow-to-region start end) + (untabify (point-min) (point-max)) + (indent-region (point-min) (point-max)) + (delete-trailing-whitespace (point-min) (point-max))))) + +(defun cj/format-region-or-buffer () + "Reformat the region or the entire buffer. +Replaces tabs with spaces, deletes trailing whitespace, and reindents." + (interactive) + (let ((start-pos (if (use-region-p) (region-beginning) (point-min))) + (end-pos (if (use-region-p) (region-end) (point-max)))) + (cj/--format-region start-pos end-pos) + (message "Formatted %s" (if (use-region-p) "region" "buffer")))) + +(cj/register-command "f" #'cj/format-region-or-buffer "format buffer") + +(provide 'custom-format) +;;; custom-format.el ends here |
