From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.devel Subject: Re: Interpretation of a space in regexp isearch? Date: Wed, 29 Aug 2012 14:46:20 +0800 Message-ID: <874nnmry9v.fsf@gnu.org> References: <502B2845.9070200@yandex.ru> <878vdgiv2d.fsf@gnu.org> <87r4qu8ffq.fsf@gnu.org> <87haro6v5y.fsf@gnu.org> <87k3wjto4o.fsf@mail.jurta.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1346222797 27559 80.91.229.3 (29 Aug 2012 06:46:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 29 Aug 2012 06:46:37 +0000 (UTC) Cc: emacs-devel@gnu.org To: Juri Linkov Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Aug 29 08:46:38 2012 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 1T6c2v-00032N-3l for ged-emacs-devel@m.gmane.org; Wed, 29 Aug 2012 08:46:37 +0200 Original-Received: from localhost ([::1]:44980 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6c2s-0000PO-Te for ged-emacs-devel@m.gmane.org; Wed, 29 Aug 2012 02:46:34 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58944) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6c2q-0000PH-BE for emacs-devel@gnu.org; Wed, 29 Aug 2012 02:46:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T6c2m-0002HG-5R for emacs-devel@gnu.org; Wed, 29 Aug 2012 02:46:32 -0400 Original-Received: from mail-pz0-f41.google.com ([209.85.210.41]:57905) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T6c2l-0002H7-Sm for emacs-devel@gnu.org; Wed, 29 Aug 2012 02:46:28 -0400 Original-Received: by dadi14 with SMTP id i14so189468dad.0 for ; Tue, 28 Aug 2012 23:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=Nugbi66+NBNZh2f3JpeJorzEJiZsGv8XR3RuJ9ZjScU=; b=erHZhpw8mGTcIxMOjWOJ4R6fTwbatYhZzWJed1/kJFQE6UB/mOpJwwcxvFfcrK5Qg7 QYxhDJicbrScSFE2mJzeZemVydlcLEbTisBJdw7enXyDAF2ZW6LBTFn8FF0hu3/MiwiE vndvxQYLoesVnIOSNYSP9St7I0A6KnQTykVklUbi1YHXGuIv7D4Y/MtnNuQBjdAMVnAM BScjMzjo6bQeO/RIMobIDLm++LQcIuS6r91i8zFbZw+uKW8vfzLfmtuRRDBBu2jllqNc Kz6bCifvDpt1mHE71N+Au9WuqzIVtIuGt/q1pnWQPKLqYPv/sZdczeMyGzY5qOSAHY6y Rprw== Original-Received: by 10.68.236.102 with SMTP id ut6mr2491006pbc.113.1346222786688; Tue, 28 Aug 2012 23:46:26 -0700 (PDT) Original-Received: from ulysses ([155.69.17.225]) by mx.google.com with ESMTPS id uu10sm18716226pbc.2.2012.08.28.23.46.23 (version=SSLv3 cipher=OTHER); Tue, 28 Aug 2012 23:46:25 -0700 (PDT) In-Reply-To: <87k3wjto4o.fsf@mail.jurta.org> (Juri Linkov's message of "Tue, 28 Aug 2012 11:30:15 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.85.210.41 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:152884 Archived-At: Juri Linkov writes: >> The magic of `C-q SPC' is missing for non-regexp searches though. > > `C-q SPC' inserts "[ ]" in regexp search. The problem for non-regexp > search is how to avoid quoting "[ ]" in `regexp-quote'. Good point. Here's how to handle this: when isearch-regexp is nil, make isearch-process-search-string call regexp-quote for each addition to the search string; then have isearch-quote-char suppress quoting by passing an optional arg to isearch-process-search-string. Then in isearch-search-fun-default, we can use re-search-forward for plain isearch as well, since the search string will have been appropriately quoted when processed. See attached patch. *** lisp/isearch.el 2012-08-26 04:08:32 +0000 --- lisp/isearch.el 2012-08-29 06:38:42 +0000 *************** *** 2200,2217 **** "Quote special characters for incremental search." (interactive) (let ((char (read-quoted-char (isearch-message t)))) ! ;; Assume character codes 0200 - 0377 stand for characters in some ! ;; single-byte character set, and convert them to Emacs ! ;; characters. ! (if (and isearch-regexp (= char ?\s)) ! (if (subregexp-context-p isearch-string (length isearch-string)) ! (isearch-process-search-string "[ ]" " ") ! (isearch-process-search-char char)) (and enable-multibyte-characters (>= char ?\200) (<= char ?\377) (setq char (unibyte-char-to-multibyte char))) ! (isearch-process-search-char char)))) (defun isearch-printing-char () "Add this ordinary printing character to the search string and search." --- 2200,2222 ---- "Quote special characters for incremental search." (interactive) (let ((char (read-quoted-char (isearch-message t)))) ! (cond ! ((/= char ?\s) ! ;; Assume character codes 0200 - 0377 stand for characters in ! ;; some single-byte character set, and convert them to Emacs ! ;; characters. (and enable-multibyte-characters (>= char ?\200) (<= char ?\377) (setq char (unibyte-char-to-multibyte char))) ! (isearch-process-search-char char)) ! ((and isearch-regexp ! (null (subregexp-context-p isearch-string ! (length isearch-string)))) ! (isearch-process-search-char char)) ! ;; Handle C-q SPC by disabling `search-whitespace-regexp' match. ! (t ! (isearch-process-search-string "[ ]" " " t))))) (defun isearch-printing-char () "Add this ordinary printing character to the search string and search." *************** *** 2239,2245 **** (char-to-string char) (isearch-text-char-description char)))) ! (defun isearch-process-search-string (string message) (setq isearch-string (concat isearch-string string) isearch-message (concat isearch-message message)) (isearch-search-and-update)) --- 2244,2252 ---- (char-to-string char) (isearch-text-char-description char)))) ! (defun isearch-process-search-string (string message &optional no-quote) ! (unless (or isearch-regexp no-quote) ! (setq string (regexp-quote string))) (setq isearch-string (concat isearch-string string) isearch-message (concat isearch-message message)) (isearch-search-and-update)) *************** *** 2443,2458 **** (funcall isearch-word string lax) (word-search-regexp string lax)) bound noerror count)))) - (isearch-regexp - (if isearch-forward 're-search-forward 're-search-backward)) (t ! (if isearch-forward 'isearch-search-forward 'isearch-search-backward)))) ! ! (defun isearch-search-forward (string &optional bound noerror count) ! (re-search-forward (regexp-quote string) bound noerror count)) ! ! (defun isearch-search-backward (string &optional bound noerror count) ! (re-search-backward (regexp-quote string) bound noerror count)) (defun isearch-search-string (string bound noerror) "Search for the first occurrence of STRING or its translation. --- 2450,2457 ---- (funcall isearch-word string lax) (word-search-regexp string lax)) bound noerror count)))) (t ! (if isearch-forward 're-search-forward 're-search-backward)))) (defun isearch-search-string (string bound noerror) "Search for the first occurrence of STRING or its translation.