Subject: Re: bug#13480: 24.3.50; `C-w' from Isearch should translate newlines to spaces

From: Juri Linkov <[email-masked]>
Date: Sat, 19 Jan 2013 11:59:22 +0200

> 1. It loses information that may be useful.  In the future we could
> want to implement a feature whereby the user can toggle the
> lax-whitespace-matching behavior during an Isearch session.  In fact I
> think it would be a good feature (and ISTR that Drew proposed some
> time ago).

We already have this feature with `M-SPC'.

> That feature would not be possible if we change the text
> that the user supplies to search for.

Yes, there is no way to restore the original text in the search string
and to un-translate a space back to the newline.

> 2. It is less surprising and more clean to me to see in the echo area
> exactly the text I'm supplying, without translations of any kind.

Then this is possible to not translate newlines to a space
in the search string but process it internally with this code:

(defun search-whitespace-regexp (string)
  "Return a regexp which ignores whitespace.
Uses the value of the variable `search-whitespace-regexp'."
  (if (or (not (stringp search-whitespace-regexp))
          (null (if isearch-regexp
                    isearch-regexp-lax-whitespace
                  isearch-lax-whitespace)))
      string
    ;; FIXME: this is not strictly correct implementation because it ignores
    ;; `subregexp-context-p' and replaces spaces inside char set group like
    ;; in `C-M-s M-s SPC [ ]', it converts it to ["\\(\\s-\\|\n\\)+"] !
    (replace-regexp-in-string
     search-whitespace-regexp ;; " "
     search-whitespace-regexp
     string nil t)))
(defun search-forward-lax-whitespace (string &optional bound noerror count)
  (re-search-forward (search-whitespace-regexp (regexp-quote string)) bound noerror count))
(defun search-backward-lax-whitespace (string &optional bound noerror count)
  (re-search-backward (search-whitespace-regexp (regexp-quote string)) bound noerror count))
(defun re-search-forward-lax-whitespace (regexp &optional bound noerror count)
  (re-search-forward (search-whitespace-regexp regexp) bound noerror count))
(defun re-search-backward-lax-whitespace (regexp &optional bound noerror count)
  (re-search-backward (search-whitespace-regexp regexp) bound noerror count))