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?

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.