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.el patch for `M-e' to put point at mismatch position Date: Sat, 10 Sep 2011 14:54:37 +0300 Organization: JURTA Message-ID: <87vct1zh4q.fsf@mail.jurta.org> References: <79A3EFE6965F48DC99409B8AC2363D2A@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1315655757 21870 80.91.229.12 (10 Sep 2011 11:55:57 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 10 Sep 2011 11:55:57 +0000 (UTC) Cc: emacs-devel@gnu.org To: "Drew Adams" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Sep 10 13:55:53 2011 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1R2MA4-0002Sk-Uq for ged-emacs-devel@m.gmane.org; Sat, 10 Sep 2011 13:55:53 +0200 Original-Received: from localhost ([::1]:35829 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2MA4-0001aW-A7 for ged-emacs-devel@m.gmane.org; Sat, 10 Sep 2011 07:55:52 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:40212) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2MA2-0001aR-6m for emacs-devel@gnu.org; Sat, 10 Sep 2011 07:55:51 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R2MA1-000466-4v for emacs-devel@gnu.org; Sat, 10 Sep 2011 07:55:50 -0400 Original-Received: from smarty.dreamhost.com ([208.113.175.8]:39593) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R2MA0-00045x-US for emacs-devel@gnu.org; Sat, 10 Sep 2011 07:55:49 -0400 Original-Received: from ps18281.dreamhostps.com (ps18281.dreamhost.com [69.163.218.105]) by smarty.dreamhost.com (Postfix) with ESMTP id 28F2D6E80BB; Sat, 10 Sep 2011 04:55:48 -0700 (PDT) Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id CA22D451C474; Sat, 10 Sep 2011 04:55:46 -0700 (PDT) In-Reply-To: <79A3EFE6965F48DC99409B8AC2363D2A@us.oracle.com> (Drew Adams's message of "Mon, 16 May 2011 14:36:39 -0700") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 208.113.175.8 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:143846 Archived-At: > The attached patch makes `M-e' (`isearch-edit-string') put point at the first > mismatch position (or the search-string end if no mismatch). > > When you hit `M-e' you are ready to edit at the mismatch position. This makes > it easy to change or insert a char or two to make the string match. (`C-g', on > the other hand just removes all of the mismatch.) > > (This feature complements the use of highlighting to show users where the > mismatch starts.) > > *** isearch.el Mon May 16 11:38:22 2011 > --- isearch-patched-2011-05-16.el Mon May 16 14:21:04 2011 > *************** > *** 1060,1065 **** > --- 1060,1080 ---- > > (defvar minibuffer-history-symbol) ;; from external package gmhist.el > > + (defun isearch-fail-pos () > + "Position of first mismatch in search string, or its length if none." > + (let ((cmds isearch-cmds) > + succ-msg) > + (if (and isearch-success (not isearch-error)) > + (length isearch-message) > + (while (or (not (isearch-success-state (car cmds))) > + (isearch-error-state (car cmds))) > + (pop cmds)) > + (setq succ-msg (and cmds (isearch-message-state (car cmds)))) > + (if (and (stringp succ-msg) (< (length succ-msg) (length isearch-message)) > + (equal succ-msg (substring isearch-message 0 (length succ-msg)))) > + (length succ-msg) > + 0)))) > + > (defun isearch-edit-string () > "Edit the search string in the minibuffer. > The following additional command keys are active while editing. > *************** > *** 1139,1145 **** > (setq isearch-new-string > (read-from-minibuffer > (isearch-message-prefix nil nil isearch-nonincremental) > ! isearch-string > minibuffer-local-isearch-map nil > (if isearch-regexp > (cons 'regexp-search-ring > --- 1154,1160 ---- > (setq isearch-new-string > (read-from-minibuffer > (isearch-message-prefix nil nil isearch-nonincremental) > ! (cons isearch-string (1+ (isearch-fail-pos))) I discovered now that you can't mix `isearch-message' and `isearch-string'. Test case to reproduce the bug: 1. emacs -Q 2. insert a few TABs with e.g. `C-q TAB C-q TAB C-q TAB' 3. `M-<' (`beginning-of-buffer') 4. `C-s C-q TAB M-e' fails with the error message "End of buffer". The reason is that `isearch-message' is longer than `isearch-string', because `isearch-text-char-description' replaces a single TAB with two characters "^I" in `isearch-message'. `isearch-fail-pos' calculates the position based on `isearch-message', but uses it for `isearch-string' in `(cons isearch-string (1+ (isearch-fail-pos)))' in `isearch-edit-string'. Replacing `isearch-message' with `isearch-string' in `isearch-fail-pos' will fix this bug. BTW, there is exactly the same algorithm used in two functions `isearch-fail-pos' and `isearch-message'. Currently both functions use the same variable `isearch-message', but after this fix the same algorithm will use different variables `isearch-message' and `isearch-string'. So sharing code between them will be more difficult. Maybe it would be better to add a new argument to `isearch-fail-pos' that will define whether it should return the failed position in `isearch-message' or `isearch-string'?