summary refs log tree commit diff stats
path: root/lisp/acdw-re.el
diff options
context:
space:
mode:
authorCase Duckworth2021-04-29 12:16:03 -0500
committerCase Duckworth2021-04-29 12:29:03 -0500
commit407771183e9d70b7e4b8ed9e2d773c9bc8e7af14 (patch)
tree8917ccaf502cbf8e96869fcd8a735a2122daf7a3 /lisp/acdw-re.el
parentReplace anzu with karthink's re-builder glue (diff)
downloademacs-407771183e9d70b7e4b8ed9e2d773c9bc8e7af14.tar.gz
emacs-407771183e9d70b7e4b8ed9e2d773c9bc8e7af14.zip
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!
Diffstat (limited to 'lisp/acdw-re.el')
-rw-r--r--lisp/acdw-re.el66
1 files changed, 66 insertions, 0 deletions
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 @@
1;;; acdw-re.el -*- lexical-binding: t; coding: utf-8-unix -*-
2;; Author: Case Duckworth <acdw@acdw.net>
3;; Created: 2021-04-29
4;; Keywords: configuration
5;; URL: https://tildegit.org/acdw/emacs
6
7;; This file is NOT part of GNU Emacs.
8
9;;; License:
10;; Everyone is permitted to do whatever with this software, without
11;; limitation. This software comes without any warranty whatsoever,
12;; but with two pieces of advice:
13;; - Don't hurt yourself.
14;; - Make good choices.
15
16;;; Commentary:
17;; Pulled mostly from karthinks:
18;; https://karthinks.com/software/bridging-islands-in-emacs-1/
19
20;;; Code:
21
22(defvar acdw/re-builder-positions nil
23 "Store point and region bounds before calling re-builder")
24
25(defun acdw/re-builder-save-state (&rest _)
26 "Save into `acdw/re-builder-positions' the point and region
27positions before calling `re-builder'."
28 (setq acdw/re-builder-positions
29 (cons (point)
30 (when (region-active-p)
31 (list (region-beginning)
32 (region-end))))))
33
34(defun reb-replace-regexp (&optional delimited)
35 "Run `query-replace-regexp' with the contents of re-builder. With
36non-nil optional argument DELIMITED, only replace matches
37surrounded by word boundaries."
38 (interactive "P")
39 (reb-update-regexp)
40 (let* ((re (reb-target-binding reb-regexp))
41 (replacement (query-replace-read-to
42 re
43 (concat "Query replace"
44 (if current-prefix-arg
45 (if (eq current-prefix-arg '-)
46 " backward"
47 " word")
48 "")
49 " regexp"
50 (if (with-selected-window reb-target-window
51 (region-active-p)) " in region" ""))
52 t))
53 (pnt (car acdw/re-builder-positions))
54 (beg (cadr acdw/re-builder-positions))
55 (end (caddr acdw/re-builder-positions)))
56 (with-selected-window reb-target-window
57 ;; replace with (goto-char (match-beginning 0)) if you want to control
58 ;; where in the buffer the replacement starts with re-builder
59 (goto-char pnt)
60 (setq acdw/re-builder-positions nil)
61 (reb-quit)
62 (query-replace-regexp re replacement delimited beg end))))
63
64(provide 'acdw-re)
65
66;;; acdw-re.el ends here