1
  1. I wonder if I can disable the 'failing overwrapped' warning in the minibuffer and directly wrap around instead if I do a search?

Does anyone know how to facilitate this?

  1. Also there is a slight delay in highlighting occurrences of the search-for expression, can I decrease this as well?

  2. Finally, how can I invoke custom function upon a key combination, only if Isearch is active?

Specifically, I want to invoke

  (defun contrib/isearchp-remove-failed-part-or-last-char ()
    "Remove failed part of search string, or last char if successful.
Do nothing if search string is empty to start with."
    (interactive)
    (if (equal isearch-string "")
        (isearch-update)
      (if isearch-success
          (isearch-delete-char)
        (while (isearch-fail-pos) (isearch-pop-state)))
      (isearch-update)))

if I hit <backspace> during Isearch.

2
  • You asked three questions here: (1) how to "disable 'failing overwrapped'", directly wrapping, (2) how to reduce the delay, and (3) *"how can I invoke...". Please remove two of them - move them to separate questions. Thx.
    – Drew
    Oct 7, 2019 at 17:34
  • And after removing 2 of the questions, please edit the question title, to make it specific.
    – Drew
    Oct 7, 2019 at 17:37

1 Answer 1

3

For quick direction change and wrap around you can use the following:

(defun isearch-repeat-forward+ ()
  (interactive)
  (unless isearch-forward
    (goto-char isearch-other-end))
  (isearch-repeat-forward)
  (unless isearch-success
    (isearch-repeat-forward)))

(defun isearch-repeat-backward+ ()
  (interactive)
  (when (and isearch-forward isearch-other-end)
    (goto-char isearch-other-end))
  (isearch-repeat-backward)
  (unless isearch-success
    (isearch-repeat-backward)))


(define-key isearch-mode-map (kbd "C-s") 'isearch-repeat-forward+)
(define-key isearch-mode-map (kbd "C-r") 'isearch-repeat-backward+)

By binding the keys in isearch-mode-map those bindings are only used when isearch is active, you can do the same with your contrib/isearchp-remove-failed-part-or-last-char command.

As for the delay question, you need to search for the variable for this setting. You can use apropos-user-option, apropos-documentation or just describe-variable (+ maybe using a completion framework of your choice) to find isearch-lazy-highlight-initial-delay which is obsoleted by lazy-highlight-initial-delay (as you can read in the docstring).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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