From 30cd6555bfa43e792eaac5ae32e39d7cafa5a3e2 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Sat, 25 Dec 2021 01:25:25 -0600 Subject: Bunch of changes; notably +filldent-dwim I might add this into filldent.el as `filldent-stupidly', later. --- lisp/+emacs.el | 49 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 12 deletions(-) (limited to 'lisp') diff --git a/lisp/+emacs.el b/lisp/+emacs.el index 3fe243c..ecf1ec5 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el @@ -201,20 +201,45 @@ kill without asking." (save-buffers-kill-emacs)) (server-save-buffers-kill-terminal nil))) +(defun +filldent-dwim (&optional arg) + "Fill and indent region if active, or current defun/paragraph. +Optional ARG causes the paragraph to \"unfill.\"" + ;; I wrote a whole package for this --- filldent.el --- but under further + ;; inspection it seems as though Emacs is smart enough in most cases. + ;; Possible TODO: make calling this twice in a row restore the buffer how it + ;; was. + (interactive "*P") + (let ((fill-column (if arg most-positive-fixnum fill-column))) + (if (region-active-p) + (progn + (fill-region (region-beginning) (region-end)) + (indent-region (region-beginning) (region-end))) + (progn + (fill-paragraph) + (save-excursion + (mark-defun) + (indent-region (region-beginning) (region-end))))))) + ;;; Bindings -(global-set-key (kbd "C-x C-c") '+save-buffers-quit) -(global-set-key (kbd "M-SPC") '+cycle-spacing) -(global-set-key (kbd "M-/") 'hippie-expand) -(global-set-key (kbd "M-=") 'count-words) -(global-set-key (kbd "C-x C-b") 'ibuffer) -(global-set-key (kbd "C-s") 'isearch-forward-regexp) -(global-set-key (kbd "C-r") 'isearch-backward-regexp) -(global-set-key (kbd "C-M-s") 'isearch-forward) -(global-set-key (kbd "C-M-r") 'isearch-backward) -(global-set-key (kbd "M-u") 'upcase-dwim) -(global-set-key (kbd "M-l") 'downcase-dwim) -(global-set-key (kbd "M-c") 'capitalize-dwim) +;; I need to place these bindings under `+key-mode-map' so that they aren't +;; shadowed by other maps. There might be a better way to do this. +(require +key) + +(dolist (binding '(("C-x C-c" . +save-buffers-quit) + ("M-SPC" . +cycle-spacing) + ("M-/" . hippie-expand) + ("M-=" . count-words) + ("M-q" . +filldent-dwim) + ("C-x C-b" . ibuffer) + ("C-s" . isearch-forward-regexp) + ("C-r" . isearch-backward-regexp) + ("C-M-s" . isearch-forward) + ("C-M-r" . isearch-backward) + ("M-u" . upcase-dwim) + ("M-l" . downcase-dwim) + ("M-c" . capitalize-dwim))) + (define-key +key-mode-map (kbd (car binding)) (cdr binding))) ;;; Required libraries -- cgit 1.4.1-21-gabe81