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-allow-move [Was: isearch-allow-prefix] Date: Fri, 07 Jun 2013 23:04:15 +0300 Organization: JURTA Message-ID: <8761xpk7r4.fsf@mail.jurta.org> References: <20130524093858.GA2754@acm.acm> <87hahstd47.fsf@mail.jurta.org> <20130525200103.GA3451@acm.acm> <878v32aj3c.fsf@mail.jurta.org> <20130602210512.GC2765@acm.acm> <87sj0xn484.fsf@mail.jurta.org> <20130604212400.GB2492@acm.acm> <87d2s1otjb.fsf@mail.jurta.org> <20130605210241.GA3730@acm.acm> <8761xr93h5.fsf_-_@mail.jurta.org> <20130606200719.GA3911@acm.acm> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1370635656 28674 80.91.229.3 (7 Jun 2013 20:07:36 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 7 Jun 2013 20:07:36 +0000 (UTC) Cc: Stefan Monnier , Drew Adams , emacs-devel@gnu.org To: Alan Mackenzie Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jun 07 22:07:36 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Ul2we-0007gw-N1 for ged-emacs-devel@m.gmane.org; Fri, 07 Jun 2013 22:07:32 +0200 Original-Received: from localhost ([::1]:48707 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul2we-0008LB-8m for ged-emacs-devel@m.gmane.org; Fri, 07 Jun 2013 16:07:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48627) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul2wZ-0008KC-VL for emacs-devel@gnu.org; Fri, 07 Jun 2013 16:07:30 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Ul2wW-0007hq-Vz for emacs-devel@gnu.org; Fri, 07 Jun 2013 16:07:27 -0400 Original-Received: from ps18281.dreamhost.com ([69.163.218.105]:49069 helo=ps18281.dreamhostps.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Ul2wW-0007h2-MG for emacs-devel@gnu.org; Fri, 07 Jun 2013 16:07:24 -0400 Original-Received: from localhost (ps18281.dreamhostps.com [69.163.218.105]) by ps18281.dreamhostps.com (Postfix) with ESMTP id 83FAC258B9E938; Fri, 7 Jun 2013 13:07:22 -0700 (PDT) In-Reply-To: <20130606200719.GA3911@acm.acm> (Alan Mackenzie's message of "Thu, 6 Jun 2013 20:07:19 +0000") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (x86_64-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x (no timestamps) [generic] X-Received-From: 69.163.218.105 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:160251 Archived-At: > You could then use it to erase the entire search string and then > convert a forward search into backward search by another C-b. Converting a forward search into backward search turned out to be a very good idea. After trying it I see that this is the most natural thing to do. The updated part of the patch is below (most code should be refactored to more general functions, so the remaining code should leave about 30 lines here): === modified file 'lisp/isearch.el' --- lisp/isearch.el 2013-06-05 20:57:09 +0000 +++ lisp/isearch.el 2013-06-07 19:55:08 +0000 @@ -2336,6 +2540,72 @@ (defun isearch-other-meta-char (&optiona (isearch-back-into-window (eq ab-bel 'above) isearch-point) (goto-char isearch-point))) (isearch-update)) + ;; Handle a motion function. + ((and (or isearch-allow-move isearch-allow-move-temporarily) + (progn (setq key (isearch-reread-key-sequence-naturally keylist)) + (setq keylist (listify-key-sequence key)) + (setq main-event (aref key 0)) + (setq move-command (or + (isearch-lookup-move-key key) + (isearch-lookup-move-key + ;; Use the last key in the sequence. + (vector (aref key (1- (length key))))))) + isearch-success)) + (setq prefix-arg arg) + (let* ((old-point (point)) + (new-point (save-excursion + (condition-case () + (command-execute move-command) + (error nil)) + (point)))) + ;; Change search direction between forward and backward. + (when (and isearch-other-end + (not isearch-error) ; for regexp incomplete input + (if isearch-forward + (< new-point isearch-other-end) + (> new-point isearch-other-end))) + (setq isearch-forward (not isearch-forward)) + (setq isearch-string "" isearch-message "") + (setq old-point isearch-other-end)) + (if (< old-point new-point) + ;; Add text to the search string. + (if isearch-forward + (isearch-yank-string + (buffer-substring-no-properties old-point new-point)) + ;; In backward search delete text from beginning of search string. + (setq isearch-string (substring isearch-string + (min (- new-point old-point) + (length isearch-string)) + (length isearch-string)) + isearch-message (mapconcat 'isearch-text-char-description + isearch-string "")) + (setq isearch-yank-flag t) + (goto-char new-point) + (isearch-search-and-update)) + (if isearch-forward + (progn + ;; Delete text from the search string. + (setq isearch-string (substring isearch-string 0 + (max (- (length isearch-string) + (- old-point new-point)) 0)) + isearch-message (mapconcat 'isearch-text-char-description + isearch-string "")) + (setq isearch-yank-flag t) + (isearch-search-and-update)) + ;; In backward search add text to beginning of search string. + (setq isearch-string + (concat + (if isearch-regexp + (regexp-quote + (buffer-substring-no-properties old-point new-point)) + (buffer-substring-no-properties old-point new-point)) + isearch-string) + isearch-message (mapconcat 'isearch-text-char-description + isearch-string "")) + (setq isearch-yank-flag t) + (goto-char new-point) + (isearch-search-and-update)))) + (setq isearch-allow-move-temporarily t)) ;; A mouse click on the isearch message starts editing the search string ((and (eq (car-safe main-event) 'down-mouse-1) (window-minibuffer-p (posn-window (event-start main-event))))