summary refs log tree commit diff stats
path: root/init.el
diff options
context:
space:
mode:
authorCase Duckworth2021-04-29 10:01:32 -0500
committerCase Duckworth2021-04-29 10:01:32 -0500
commit27ae0a2ab8d9aca7757ea2deb2f4ec102c6168d0 (patch)
treebff0c32cbe0a8d3fee77e1742f5c5378e03c4dd9 /init.el
parentUse my fork of `beginend' (diff)
downloademacs-27ae0a2ab8d9aca7757ea2deb2f4ec102c6168d0.tar.gz
emacs-27ae0a2ab8d9aca7757ea2deb2f4ec102c6168d0.zip
Replace anzu with karthink's re-builder glue
Diffstat (limited to 'init.el')
-rw-r--r--init.el68
1 files changed, 54 insertions, 14 deletions
diff --git a/init.el b/init.el index 4205222..fcbfd09 100644 --- a/init.el +++ b/init.el
@@ -392,6 +392,60 @@
392 nil) 392 nil)
393 t))) 393 t)))
394 394
395(setup re-builder
396 ;; https://karthinks.com/software/bridging-islands-in-emacs-1/
397
398 (defvar acdw/re-builder-positions nil
399 "Store point and region bounds before calling re-builder")
400
401 (advice-add 're-builder
402 :before
403 (defun acdw/re-builder-save-state (&rest _)
404 "Save into `acdw/re-builder-positions' the point and region
405positions before calling `re-builder'."
406 (setq acdw/re-builder-positions
407 (cons (point)
408 (when (region-active-p)
409 (list (region-beginning)
410 (region-end)))))))
411
412 (defun reb-replace-regexp (&optional delimited)
413 "Run `query-replace-regexp' with the contents of re-builder. With
414non-nil optional argument DELIMITED, only replace matches
415surrounded by word boundaries."
416 (interactive "P")
417 (reb-update-regexp)
418 (let* ((re (reb-target-binding reb-regexp))
419 (replacement (query-replace-read-to
420 re
421 (concat "Query replace"
422 (if current-prefix-arg
423 (if (eq current-prefix-arg '-) " backward" " word")
424 "")
425 " regexp"
426 (if (with-selected-window reb-target-window
427 (region-active-p)) " in region" ""))
428 t))
429 (pnt (car acdw/re-builder-positions))
430 (beg (cadr acdw/re-builder-positions))
431 (end (caddr acdw/re-builder-positions)))
432 (with-selected-window reb-target-window
433 (goto-char pnt) ; replace with (goto-char (match-beginning 0)) if you want
434 ; to control where in the buffer the replacement starts
435 ; with re-builder
436 (setq acdw/re-builder-positions nil)
437 (reb-quit)
438 (query-replace-regexp re replacement delimited beg end))))
439
440 (:global "C-M-%" re-builder)
441
442 (dolist (map '(reb-mode-map reb-lisp-mode-map))
443 (let ((setup-map map))
444 (:bind "RET" reb-replace-regexp
445 "M-n" reb-next-match
446 "M-p" reb-prev-match
447 "M-q" reb-quit))))
448
395 449
396;;; Applications 450;;; Applications
397 451
@@ -621,20 +675,6 @@ call `zzz-to-char'."
621 675
622 (:global "M-z" acdw/zzz-up-to-char)) 676 (:global "M-z" acdw/zzz-up-to-char))
623 677
624(setup (:straight anzu)
625 (:option anzu-replace-to-string-separator " → "
626 anzu-cons-mode-line-p nil)
627 (add-to-list 'mode-line-misc-info '(:eval (anzu--update-mode-line)))
628
629 (:global [remap query-replace] anzu-query-replace
630 [remap query-replace-regexp] anzu-query-replace-regexp)
631 (:with-map isearch-mode-map
632 (:bind [remap isearch-query-replace] anzu-isearch-query-replace
633 [remap isearch-query-replace-regexp]
634 anzu-isearch-query-replace-regexp))
635
636 (global-anzu-mode +1))
637
638(setup (:straight async) 678(setup (:straight async)
639 (autoload 'dired-async-mode "dired-async.el" nil t) 679 (autoload 'dired-async-mode "dired-async.el" nil t)
640 (dired-async-mode +1)) 680 (dired-async-mode +1))