From 9347b58372ececd7717990ea1a5ca0a738b6d279 Mon Sep 17 00:00:00 2001 From: mattiasdrp Date: Thu, 5 Sep 2024 12:30:59 +0200 Subject: [PATCH] Use selected region as search value when starting isearch --- init.el | 12 ++++++++++++ init.org | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/init.el b/init.el index 69d94b6..fe84f5c 100644 --- a/init.el +++ b/init.el @@ -810,6 +810,18 @@ debian, and derivatives). On most it's 'fd'.") "M-c" 'mdrp/toggle-case "c" 'mdrp/toggle-case) :config + ;; use current region as first search + (defadvice isearch-mode (around isearch-mode-default-string (forward &optional regexp op-fun recursive-edit word-p) activate) + (if (and transient-mark-mode mark-active (not (eq (mark) (point)))) + (progn + (isearch-update-ring (buffer-substring-no-properties (mark) (point))) + (deactivate-mark) + ad-do-it + (if (not forward) + (isearch-repeat-backward) + (goto-char (mark)) + (isearch-repeat-forward))) + ad-do-it)) (defun mdrp/toggle-case () (interactive) (setq case-fold-search (not case-fold-search)) diff --git a/init.org b/init.org index a1b40eb..1645f93 100644 --- a/init.org +++ b/init.org @@ -1502,6 +1502,18 @@ This part will load packages that are useful for emacs and are not specific to m "M-c" 'mdrp/toggle-case "c" 'mdrp/toggle-case) :config + ;; use current region as first search + (defadvice isearch-mode (around isearch-mode-default-string (forward &optional regexp op-fun recursive-edit word-p) activate) + (if (and transient-mark-mode mark-active (not (eq (mark) (point)))) + (progn + (isearch-update-ring (buffer-substring-no-properties (mark) (point))) + (deactivate-mark) + ad-do-it + (if (not forward) + (isearch-repeat-backward) + (goto-char (mark)) + (isearch-repeat-forward))) + ad-do-it)) (defun mdrp/toggle-case () (interactive) (setq case-fold-search (not case-fold-search))