From: Juri Linkov <juri@jurta.org>
Cc: emacs-devel@gnu.org
Subject: isearch hooks (was: query-replace-interactive not documented)
Date: Fri, 18 Jun 2004 23:00:09 +0300 [thread overview]
Message-ID: <87d63wy6ux.fsf_-_@mail.jurta.org> (raw)
In-Reply-To: <E1BYxfZ-0007PW-SR@fencepost.gnu.org> (Richard Stallman's message of "Fri, 11 Jun 2004 21:50:53 -0400")
Juri Linkov <juri@jurta.org> writes:
> I noticed that the commentary section of isearch.el has the following
> TODO item:
>
> ;; - Think about incorporating query-replace.
isearch.el has also another TODO item:
;; - Hooks and options for failed search.
I remember there was a discussion on emacs-devel two months ago about
searching across several buffers or Info nodes. Adding hooks for
failed and wrapped search will allow to implement these features.
The patch below adds two hooks `isearch-wrapped-hook' and
`isearch-failed-hook'. When these hooks are not specified, isearch
keeps its current behavior: when failed, it displays "Failing
I-search" message; and when wrapped, it moves the point to the
beginning/end of the buffer.
But with using these hooks many useful things are possible.
For example, to search across Info nodes `isearch-wrapped-hook' can
use `Info-search' to move between Info nodes, and `isearch-failed-hook'
to move to the next Info node immediately:
(add-hook 'Info-mode-hook
(lambda ()
(set (make-local-variable 'isearch-wrapped-hook)
(lambda ()
(Info-search isearch-string (unless isearch-forward 'backward))
(goto-char (if isearch-forward (point-min) (point-max)))
(setq isearch-cmds nil)))
(set (make-local-variable 'isearch-failed-hook)
(lambda ()
(isearch-repeat (if isearch-forward 'forward 'backward))))))
Another example is isearching multiple buffers:
(defvar my-buffer-list nil)
(add-hook 'isearch-mode-hook
(lambda () (setq my-buffer-list (cdr (buffer-list)))))
(add-hook 'isearch-wrapped-hook
(lambda ()
;; skip buffers with no isearch-string
(while (and my-buffer-list
(progn
(switch-to-buffer (car my-buffer-list))
(goto-char (point-min))
(prog1 (not (re-search-forward isearch-string nil t))
(setq my-buffer-list (cdr my-buffer-list))))))
(goto-char (if isearch-forward (point-min) (point-max)))
(setq isearch-cmds nil)))
These examples could be developed further to include them into info.el etc.
and to make options to enable hooks.
Anyway, I think the change which allows to call hooks can be installed
now, since it doesn't change the current behavior.
Index: lisp/isearch.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/isearch.el,v
retrieving revision 1.228
diff -u -r1.228 isearch.el
--- lisp/isearch.el 6 Jun 2004 13:57:39 -0000 1.228
+++ lisp/isearch.el 18 Jun 2004 16:15:25 -0000
@@ -57,48 +57,6 @@
;; keep the behavior. No point in forcing nonincremental search until
;; the last possible moment.
-;; TODO
-;; - Integrate the emacs 19 generalized command history.
-;; - Think about incorporating query-replace.
-;; - Hooks and options for failed search.
;;; Change Log:
@@ -199,6 +157,15 @@
(defvar isearch-mode-end-hook nil
"Function(s) to call after terminating an incremental search.")
+(defvar isearch-wrapped-hook nil
+ "Function(s) to call when search is wrapped.
+If nil, move point to the beginning of the buffer for forward search,
+or to the end of the buffer for reverse search.")
+
+(defvar isearch-failed-hook nil
+ "Function(s) to call when search is failed.
+If nil, ding.")
+
;; Search ring.
(defvar search-ring nil
@@ -990,7 +968,9 @@
;; If already have what to search for, repeat it.
(or isearch-success
(progn
- (goto-char (if isearch-forward (point-min) (point-max)))
+ (if isearch-wrapped-hook
+ (run-hooks 'isearch-wrapped-hook)
+ (goto-char (if isearch-forward (point-min) (point-max))))
(setq isearch-wrapped t))))
;; C-s in reverse or C-r in forward, change direction.
(setq isearch-forward (not isearch-forward)))
@@ -1786,6 +1867,7 @@
(or isearch-success (setq ellipsis nil))
(let ((m (concat (if isearch-success "" "failing ")
(if (and isearch-wrapped
+ (not isearch-wrapped-hook)
(if isearch-forward
(> (point) isearch-opoint)
(< (point) isearch-opoint)))
@@ -1876,9 +1961,9 @@
(if isearch-success
nil
;; Ding if failed this time after succeeding last time.
- (and (nth 3 (car isearch-cmds))
- (ding))
- (goto-char (nth 2 (car isearch-cmds)))))
+ (and (nth 3 (car isearch-cmds)) (or isearch-failed-hook (ding)))
+ (goto-char (nth 2 (car isearch-cmds)))
+ (if isearch-failed-hook (run-hooks 'isearch-failed-hook))))
;; Called when opening an overlay, and we are still in isearch.
--
Juri Linkov
http://www.jurta.org/emacs/
next prev parent reply other threads:[~2004-06-18 20:00 UTC|newest]
Thread overview: 101+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-28 16:16 query-replace-interactive not documented Werner LEMBERG
2004-05-29 17:02 ` Richard Stallman
2004-05-29 17:37 ` Luc Teirlinck
2004-05-29 20:33 ` Juri Linkov
2004-06-11 8:19 ` Juri Linkov
2004-06-11 8:39 ` Kim F. Storm
2004-06-11 9:00 ` David Kastrup
2004-06-12 8:21 ` Juri Linkov
2004-06-12 1:50 ` Richard Stallman
2004-06-12 8:16 ` Juri Linkov
2004-06-13 0:01 ` Richard Stallman
2004-06-13 0:46 ` Miles Bader
2004-06-13 9:03 ` David Kastrup
2004-06-14 18:50 ` Richard Stallman
2004-06-14 20:49 ` Kim F. Storm
2004-06-14 21:20 ` David Kastrup
2004-06-15 14:29 ` Juri Linkov
2004-06-15 15:43 ` David Kastrup
2004-06-15 18:17 ` Juri Linkov
2004-06-15 20:23 ` David Kastrup
2004-06-15 22:30 ` Andreas Schwab
2004-06-15 22:36 ` David Kastrup
2004-06-15 22:43 ` Kim F. Storm
2004-06-15 23:13 ` David Kastrup
2004-06-16 1:16 ` David Kastrup
2004-06-16 8:08 ` Juri Linkov
2004-06-16 9:23 ` David Kastrup
2004-06-16 8:02 ` Juri Linkov
2004-06-17 5:06 ` Richard Stallman
2004-06-16 8:17 ` Juri Linkov
2004-06-16 9:01 ` David Kastrup
2004-06-16 17:06 ` Kevin Rodgers
2004-06-16 9:02 ` Andreas Schwab
2004-06-16 1:41 ` Miles Bader
2004-06-16 2:01 ` David Kastrup
2004-06-16 2:11 ` Miles Bader
2004-06-16 16:57 ` Richard Stallman
2004-06-15 22:25 ` Andreas Schwab
2004-06-15 22:28 ` Kim F. Storm
2004-06-16 9:00 ` Juri Linkov
2004-06-16 9:25 ` Andreas Schwab
2004-06-16 9:32 ` David Kastrup
2004-06-16 11:30 ` Kim F. Storm
2004-06-16 12:15 ` David Kastrup
2004-06-16 14:35 ` David Kastrup
2004-06-16 15:23 ` Juri Linkov
2004-06-16 21:15 ` David Kastrup
2004-06-16 22:26 ` Kim F. Storm
2004-06-17 0:56 ` David Kastrup
2004-06-17 12:14 ` David Kastrup
2004-06-17 13:05 ` Kim F. Storm
2004-06-17 13:29 ` David Kastrup
2004-06-17 14:10 ` Kim F. Storm
2004-06-17 14:56 ` David Kastrup
2004-06-17 15:33 ` Juri Linkov
2004-06-17 17:03 ` David Kastrup
2004-06-18 6:43 ` Juri Linkov
2004-06-18 7:13 ` David Kastrup
2004-06-16 15:27 ` Kim F. Storm
2004-06-16 17:28 ` Juri Linkov
2004-06-16 21:07 ` David Kastrup
2004-06-17 0:47 ` David Kastrup
2004-06-17 23:05 ` Richard Stallman
2004-06-18 6:55 ` Juri Linkov
2004-06-19 3:19 ` Richard Stallman
2004-06-19 7:00 ` David Kastrup
2004-06-20 19:18 ` Richard Stallman
2004-06-20 21:05 ` David Kastrup
2004-06-21 9:31 ` Richard Stallman
2004-06-21 9:50 ` David Kastrup
2004-06-22 23:16 ` Richard Stallman
2004-06-25 23:12 ` Juri Linkov
2004-06-26 7:34 ` David Kastrup
2004-06-26 16:18 ` Juri Linkov
2004-06-27 17:41 ` Richard Stallman
2004-06-21 9:31 ` Richard Stallman
2004-06-21 9:38 ` David Kastrup
2004-06-22 23:17 ` Richard Stallman
2004-06-22 23:20 ` David Kastrup
2004-06-17 5:07 ` Richard Stallman
2004-06-14 16:59 ` Juri Linkov
2004-06-12 8:21 ` David Kastrup
2004-05-30 19:41 ` Richard Stallman
2004-05-30 22:00 ` Luc Teirlinck
2004-06-08 6:55 ` Juri Linkov
2004-06-11 8:22 ` Juri Linkov
2004-06-12 1:50 ` Richard Stallman
2004-06-18 20:00 ` Juri Linkov [this message]
2004-06-19 1:10 ` isearch hooks (was: query-replace-interactive not documented) Miles Bader
2004-06-19 18:09 ` isearch hooks Juri Linkov
2004-06-19 3:19 ` isearch hooks (was: query-replace-interactive not documented) Richard Stallman
2004-06-19 18:36 ` isearch hooks Juri Linkov
2004-06-20 19:18 ` Richard Stallman
2004-06-21 21:56 ` Juri Linkov
2004-06-22 23:17 ` Richard Stallman
2004-06-25 18:07 ` Juri Linkov
2004-06-27 17:41 ` Richard Stallman
2004-06-27 22:34 ` Juri Linkov
2004-06-28 14:57 ` Richard Stallman
2004-06-29 0:25 ` isearch hooks (was: query-replace-interactive not documented) Stefan
2004-06-29 1:17 ` isearch hooks Juri Linkov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87d63wy6ux.fsf_-_@mail.jurta.org \
--to=juri@jurta.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.