help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: killing the result of isearch


From: Tomas Nordin
Subject: Re: killing the result of isearch
Date: Sun, 12 Nov 2017 21:02:05 +0100

Jean-Christophe Helary <jean.christophe.helary@gmail.com> writes:

>> On Nov 8, 2017, at 2:53, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> 
>> Many Emacs users rely on isearch for navigation, in which case the above 
>> could prove annoying.  Also, currently isearch pushes a mark at the position 
>> where you started the search
>
> Thank you, that confirms my understanding. I've been using it with that 
> purpose a number of times and it is very practical, but the fact that it does 
> not give access by default to the match makes it more a navigation (find 
> location) function than something to actually use the match.

As an exercise I wrote this. Can you try it. I think it behaves the way
you expect sort of.

(defun tn-frozen-search (arg &optional start-point)
  "Search forward for a preloaded frozen term.

With a prefix argument prompt for a search term (a regular
expression). With no prefix argument, use the last search from
the search-ring.

Activate the match as a region. Then, if `delete-selection-mode'
has been toggled on, one can \"just act\" on that region.

This function is for interactive use only. There will be an
overwrap with no ding."

  (interactive "P")
  (when arg
    (push (read-string "Search: ") search-ring))
  (unless start-point
    (push-mark nil t nil))
  (let ((success (re-search-forward (car search-ring) nil t)))
    (cond
     (success
      (push-mark (car (match-data)) t t))
     ((and (= (point) (point-min)) (not success))
      (if start-point
          ;; if search fail and start-point is defined, go back to start
          ;; point (recursive call)
          (goto-char start-point)
        )
      (ding)
      (message "No match for %S" (car search-ring)))
     ((not success)
      (if (not start-point)
          (setq start-point (point)))
      ;; this makes it just over-wrap with no ding
      (goto-char (point-min))
      (message "frozen search ****OVERWRAP****")
      (tn-frozen-search nil start-point)) 
     (t
      (message "semantic error in code"))))) ; hit C-x C-e

(global-set-key (kbd "<f9>") 'tn-frozen-search)

With this setup, hitting F9 will search and select the last searched
term. Hitting C-u F9 will giva a prompt for a search term.

There are room for improvement of course, but as a starting point maybe.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]