Skip to content

Commit

Permalink
Use selected region as search value when starting isearch
Browse files Browse the repository at this point in the history
  • Loading branch information
mattiasdrp committed Sep 5, 2024
1 parent d04faa0 commit 9347b58
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
12 changes: 12 additions & 0 deletions init.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
12 changes: 12 additions & 0 deletions init.org
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 9347b58

Please sign in to comment.