From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.devel Subject: Re: isearch multiple buffers Date: Sat, 20 Oct 2007 03:08:08 +0300 Organization: JURTA Message-ID: <87lk9ylkbb.fsf@jurta.org> References: <87odfcggvl.fsf@jurta.org> <87myut77c2.fsf@jurta.org> <873awlidih.fsf@offby1.atm01.sea.blarg.net> <871wc51any.fsf@jurta.org> <878x6a6ktw.fsf@jurta.org> <871wc15m2b.fsf@jurta.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1192839524 24495 80.91.229.12 (20 Oct 2007 00:18:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 20 Oct 2007 00:18:44 +0000 (UTC) Cc: emacs-devel@gnu.org To: rms@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 20 02:18:44 2007 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1Ij238-0004Pz-SF for ged-emacs-devel@m.gmane.org; Sat, 20 Oct 2007 02:18:43 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ij230-0008VA-U2 for ged-emacs-devel@m.gmane.org; Fri, 19 Oct 2007 20:18:34 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Ij22v-0008Tf-Sx for emacs-devel@gnu.org; Fri, 19 Oct 2007 20:18:29 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Ij22v-0008TP-Aw for emacs-devel@gnu.org; Fri, 19 Oct 2007 20:18:29 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Ij22v-0008TK-4R for emacs-devel@gnu.org; Fri, 19 Oct 2007 20:18:29 -0400 Original-Received: from mailman.kiev.sovam.com ([89.162.150.100]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Ij22o-000232-Dl; Fri, 19 Oct 2007 20:18:23 -0400 Original-Received: from relay01.kiev.sovam.com ([62.64.120.200]) by mailman.kiev.sovam.com with esmtp (Exim 4.63 (FreeBSD)) (envelope-from ) id 1Ij4qU-000H3w-Ts; Sat, 20 Oct 2007 03:17:50 +0000 Original-Received: from [83.170.232.243] (helo=smtp.svitonline.com) by relay01.kiev.sovam.com with esmtp (Exim 4.67) (envelope-from ) id 1Ij22m-000IjD-5G; Sat, 20 Oct 2007 03:18:20 +0300 In-Reply-To: (Richard Stallman's message of "Fri\, 12 Oct 2007 11\:59\:45 -0400") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/23.0.50 (gnu/linux) X-Scanner-Signature: d6f54fc49b391dd6658b0b3e8f81a7e7 X-DrWeb-checked: yes X-SpamTest-Envelope-From: juri@jurta.org X-SpamTest-Group-ID: 00000000 X-SpamTest-Header: Not Detected X-SpamTest-Info: Profiles 1644 [Oct 20 2007] X-SpamTest-Info: helo_type=3 X-SpamTest-Method: none X-SpamTest-Rate: 0 X-SpamTest-Status: Not detected X-SpamTest-Status-Extended: not_detected X-SpamTest-Version: SMTP-Filter Version 3.0.0 [0255], KAS30/Release X-detected-kernel: by monty-python.gnu.org: FreeBSD 6.x (1) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:81270 Archived-At: --=-=-= > > Perhaps, we should add a new user option with 3 possible values: > > 1. don't stop in the initial buffer > > 2. stop once in the initial buffer > 3. stop in every buffer which contains the search string > (and always stop in the first buffer) > > So there are three useful options (and let's try using the 3-rd as the > default). > > If you want to implement all three, please do. I implemented a new user option isearch-buffers-pause with these three values, with the default to pause in every buffer that contains the search string. Also I implemented a new minor mode isearch-buffers-minor-mode that sets a group of variables necessary for this feature. Turning off this minor mode deletes all created buffer-local bindings. So any major mode that uses this feature can simply set the variable isearch-buffers-next-buffer-function and call isearch-buffers-minor-mode. The code implementing this feature has so many lines now that I think it needs a separate file. One possible name would be isearchb.el, but this name is already occupied by another package. So I think a good name will be isearch-et.el (isearch everything :-) as I plan to add more isearch extensions to this new file. Below are two NEWS entries, a patch for the first package add-log.el that uses this feature, a small patch for isearch.el, and a new file isearch-et.el: ** The package isearch-et.el has been added. It implements a new mode `isearch-buffers-minor-mode' that allows isearch to search through multiple buffers. In this mode a new variable `isearch-buffers-next-buffer-function' defines the function to call to get the next buffer to search in the series of multiple buffers. ** isearch can now search through multiple ChangeLog files. When running isearch in a ChangeLog file, if the search fails, then another C-s tries searching the previous ChangeLog, if there is one (e.g. go from ChangeLog to ChangeLog.12). Index: lisp/add-log.el =================================================================== RCS file: /sources/emacs/emacs/lisp/add-log.el,v retrieving revision 1.197 diff -c -r1.197 add-log.el *** lisp/add-log.el 10 Oct 2007 18:52:44 -0000 1.197 --- lisp/add-log.el 20 Oct 2007 00:00:55 -0000 *************** *** 760,766 **** 'change-log-resolve-conflict) (set (make-local-variable 'adaptive-fill-regexp) "\\s *") (set (make-local-variable 'font-lock-defaults) ! '(change-log-font-lock-keywords t nil nil backward-paragraph))) ;; It might be nice to have a general feature to replace this. The idea I ;; have is a variable giving a regexp matching text which should not be --- 760,788 ---- 'change-log-resolve-conflict) (set (make-local-variable 'adaptive-fill-regexp) "\\s *") (set (make-local-variable 'font-lock-defaults) ! '(change-log-font-lock-keywords t nil nil backward-paragraph)) ! (set (make-local-variable 'isearch-buffers-next-buffer-function) ! 'change-log-next-buffer) ! (isearch-buffers-minor-mode)) ! ! (defun change-log-next-buffer (&optional buffer wrap) ! "Return the next buffer in the series of ChangeLog file buffers. ! This function is used for multiple buffers isearch. ! A sequence of buffers is formed by ChangeLog files with decreasing ! numeric file name suffixes in the directory of the initial ChangeLog ! file were isearch was started." ! (let* ((name (change-log-name)) ! (files (cons name (sort (file-expand-wildcards ! (concat name "[-.][0-9]*")) ! (lambda (a b) ! (version< (substring b (length name)) ! (substring a (length name))))))) ! (files (if isearch-forward files (reverse files)))) ! (find-file-noselect ! (if wrap ! (car files) ! (cadr (member (file-name-nondirectory (buffer-file-name buffer)) ! files)))))) ;; It might be nice to have a general feature to replace this. The idea I ;; have is a variable giving a regexp matching text which should not be Index: lisp/isearch.el =================================================================== RCS file: /sources/emacs/emacs/lisp/isearch.el,v retrieving revision 1.303 diff -c -r1.303 isearch.el *** lisp/isearch.el 29 Aug 2007 05:28:05 -0000 1.303 --- lisp/isearch.el 20 Oct 2007 00:02:31 -0000 *************** *** 2035,2042 **** (if isearch-forward (< pos2 pos1) (> pos2 pos1)))) (setq pos1 pos2) (set-match-data match-data))))) ! (if pos1 ! (goto-char pos1)) pos1)) (defun isearch-search () --- 2045,2059 ---- (if isearch-forward (< pos2 pos1) (> pos2 pos1)))) (setq pos1 pos2) (set-match-data match-data))))) ! (when pos1 ! ;; When using multiple buffers isearch, switch to the new buffer here, ! ;; because `save-excursion' above doesn't allow doing it inside funcall. ! (if (and (boundp 'isearch-buffers-next-buffer-function) ! isearch-buffers-next-buffer-function ! (boundp 'isearch-buffers-current-buffer) ! (buffer-live-p isearch-buffers-current-buffer)) ! (switch-to-buffer isearch-buffers-current-buffer)) ! (goto-char pos1)) pos1)) (defun isearch-search () --=-=-= Content-Type: application/emacs-lisp Content-Disposition: inline; filename=isearch-et.el Content-Transfer-Encoding: quoted-printable ;;; isearch-et.el --- isearch everything ;; Copyright (C) 2007 Free Software Foundation, Inc. ;; Author: Juri Linkov ;; Keywords: matching ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; This file adds more dimensions to the search space. It implements ;; various features that extend isearch. One of them is an ability to ;; search through multiple buffers. ;;; Code: ;;; Search multiple buffers (defgroup isearch-buffers nil "Using isearch to search through multiple buffers." :version "23.1" :group 'isearch) (defcustom isearch-buffers-pause t "A choice defining where to pause the search. If the value is nil, don't pause before going to the next buffer. If the value is `initial', pause only after a failing search in the initial buffer. If t, pause in all buffers that contain the search string." :type '(choice (const :tag "Don't pause" nil) (const :tag "Only in initial buffer" initial) (const :tag "All buffers" t)) :version "23.1" :group 'isearch-buffers) (defvar isearch-buffers-current-buffer nil "The buffer where the search is currently searching. The value is nil when the search still is in the initial buffer.") (defvar isearch-buffers-next-buffer-function nil "Function to call to get the next buffer to search. When this variable is set to a function that returns a buffer, then after typing another C-s or C-r at a failing search, the search goes to the next buffer in the series and continues searching for the next occurrence. The first argument of this function is the current buffer where the search is currently searching. It defines the base buffer relative to which this function should find the next buffer. When the isearch direction is backward (when isearch-forward is nil), this function should return the previous buffer to search. If the second argument of this function WRAP is non-nil, then it should return the first buffer in the series; and for the backward search, it should return the last buffer in the series.") ;;;###autoload (define-minor-mode isearch-buffers-minor-mode "Minor mode for using isearch to search through multiple buffers. With arg, turn isearch-buffers minor mode on if arg is positive, off otherw= ise." :group 'isearch-buffers (if isearch-buffers-minor-mode (progn (add-hook 'isearch-mode-hook 'isearch-buffers-init nil t) (set (make-local-variable 'isearch-search-fun-function) 'isearch-buffers-search-fun) (set (make-local-variable 'isearch-wrap-function) 'isearch-buffers-wrap) (set (make-local-variable 'isearch-push-state-function) 'isearch-buffers-push-state)) (remove-hook 'isearch-mode-hook 'isearch-buffers-init t) (kill-local-variable 'isearch-search-fun-function) (kill-local-variable 'isearch-wrap-function) (kill-local-variable 'isearch-push-state-function))) (defun isearch-buffers-init () "Set up isearch to search multiple buffers. Intended to be added to `isearch-mode-hook'." (setq isearch-buffers-current-buffer nil)) (defun isearch-buffers-search-fun () "Return the proper search function, for isearch in multiple buffers." (lambda (string bound noerror) (let ((search-fun ;; Use standard functions to search within one buffer (cond (isearch-word (if isearch-forward 'word-search-forward 'word-search-backward)) (isearch-regexp (if isearch-forward 're-search-forward 're-search-backward)) (t (if isearch-forward 'search-forward 'search-backward)))) found buffer) (or ;; 1. First try searching in the initial buffer (let ((res (funcall search-fun string bound noerror))) ;; Reset wrapping for all-buffers pause after successful search (if (and res (eq isearch-buffers-pause t)) (setq isearch-buffers-current-buffer nil)) res) ;; 2. If the above search fails, start visiting next/prev buffers ;; successively, and search the string in them. Do this only ;; when bound is nil (i.e. not while lazy-highlighting search ;; strings in the current buffer). (unless bound ;; If no-pause or there was one attempt to leave the current buffer (if (or (null isearch-buffers-pause) (and isearch-buffers-pause isearch-buffers-current-buffer)) (condition-case nil (progn (while (not found) ;; Find the next buffer to search (setq buffer (funcall isearch-buffers-next-buffer-function buffer)) (with-current-buffer buffer (goto-char (if isearch-forward (point-min) (point-max))) (setq isearch-barrier (point) isearch-opoint (point)) ;; After visiting the next/prev buffer search the ;; string in it again, until the function in ;; isearch-buffers-next-buffer-function raises an error ;; at the beginning/end of the buffer sequence. (setq found (funcall search-fun string bound noerror)))) ;; Set buffer for isearch-search-string to switch (if buffer (setq isearch-buffers-current-buffer buffer)) ;; Return point of the new search result found) ;; Return nil when isearch-buffers-next-buffer-function fails (error nil)) (signal 'search-failed (list string "Repeat for next buffer")))))))) (defun isearch-buffers-wrap () "Wrap the multiple buffers search when search is failed. Switch buffer to the first buffer for a forward search, or to the last buffer for a backward search. Set `isearch-buffers-current-buffer' to the current buffer to display the isearch suffix message [initial buffer] only when isearch leaves the initial buffer." (if (or (null isearch-buffers-pause) (and isearch-buffers-pause isearch-buffers-current-buffer)) (progn (switch-to-buffer (setq isearch-buffers-current-buffer (funcall isearch-buffers-next-buffer-function (current-buffer) t))) (goto-char (if isearch-forward (point-min) (point-max)))) (setq isearch-buffers-current-buffer (current-buffer)) (setq isearch-wrapped nil))) (defun isearch-buffers-push-state () "Save a function restoring the state of multiple buffers search. Save the current buffer to the additional state parameter in the search status stack." `(lambda (cmd) (isearch-buffers-pop-state cmd ,(current-buffer)))) (defun isearch-buffers-pop-state (cmd buffer) "Restore the multiple buffers search state. Switch to the buffer restored from the search status stack." (unless (equal buffer (current-buffer)) (switch-to-buffer (setq isearch-buffers-current-buffer buffer)))) (provide 'isearch-et) ;;; isearch-et.el ends here --=-=-= -- Juri Linkov http://www.jurta.org/emacs/ --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Emacs-devel mailing list Emacs-devel@gnu.org http://lists.gnu.org/mailman/listinfo/emacs-devel --=-=-=--