1

I'm trying to write a function that exits isearch leaving the current match selected "transiently", so that the mark is deactivated by any unshifted movement command.

I've tried to modify this function,

(defun isearch-exit-mark-match ()
  "Exit isearch and mark the current match."
  (interactive)
  (isearch-exit)
  (push-mark isearch-other-end)
  (activate-mark))

[source] which does select the matching string, but doesn't do so with a transient mark. How can I fix it?

Drew
  • 75,699
  • 9
  • 109
  • 225
Arch Stanton
  • 1,525
  • 9
  • 22

1 Answers1

1

Base on the implementation of the function handle-shift-selection, you can try something like this

(defun isearch-exit-mark-match ()
  "Exit isearch and mark the current match."
  (interactive)
  (isearch-exit)
  (setq-local transient-mark-mode
              (cons 'only transient-mark-mode))
  (push-mark isearch-other-end nil t))

(define-key isearch-mode-map (kbd "<C-return>") #'isearch-exit-mark-match)
xuchunyang
  • 14,302
  • 1
  • 18
  • 39