From 407771183e9d70b7e4b8ed9e2d773c9bc8e7af14 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 29 Apr 2021 12:16:03 -0500 Subject: 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! --- lisp/acdw-re.el | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 lisp/acdw-re.el (limited to 'lisp/acdw-re.el') diff --git a/lisp/acdw-re.el b/lisp/acdw-re.el new file mode 100644 index 0000000..ea1c42a --- /dev/null +++ b/lisp/acdw-re.el @@ -0,0 +1,66 @@ +;;; acdw-re.el -*- lexical-binding: t; coding: utf-8-unix -*- +;; Author: Case Duckworth +;; 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 -- cgit 1.4.1-21-gabe81