bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Suggestion: check for \n, \t in regexp for query-replace-regexp


From: Michael John Downes
Subject: Suggestion: check for \n, \t in regexp for query-replace-regexp
Date: Fri, 30 Nov 2001 09:07:00 -0500 (EST)

In GNU Emacs 20.7.1 (sparc-sun-solaris2.7, X toolkit)
 of Thu Sep 21 2000 on thor
configured using `configure  --with-x'

Please describe exactly what actions triggered the bug
and the precise symptoms of the bug:

> From: David Richard Larochelle <drl7x@cs.Virginia.EDU>
> Newsgroups: gnu.emacs.help
> Subject: \n in regular expressions
> Date: Thu, 29 Nov 2001 21:24:18 -0500
> Message-ID: 
> <Pine.LNX.4.33.0111292116530.15849-100000@matthews.cs.Virginia.EDU>
 ...
> Does anyone know how to use new line characters in emacs regular
> expressions?
> 
> I read the section on regular expressions in Learning GNU emacs which
> seems to indicate \n should work.
> 
> But for some reason \n  seems to be treated as 'n' instead
> of new line in query-replace-regexp
> 
> 
> I've tried using \\n also but that doesn't work either.

Because this was a point of confusion for me when I started using Emacs,
and apparently for many other people also, judging by the recurrence of
this question on gnu.emacs.help, I suggest that a check of the regexp
string be added to query-replace-regexp, isearch-forward-regexp, and the
other user-level commands that read a regexp, to give a warning, for
example:
  
(defun query-replace-read-args (string regexp-flag)
  (let (from to)
    (if query-replace-interactive
        (setq from (car (if regexp-flag regexp-search-ring search-ring)))
      (setq from (read-from-minibuffer (format "%s: " string)
                                       nil nil nil
                                       query-replace-from-history-variable
                                       nil t)))
    (while (probable-regexp-error from)
      (setq from (read-from-minibuffer (format "%s: " string)
                                       from nil nil
                                       query-replace-from-history-variable
                                       nil t)))
    (setq to (read-from-minibuffer (format "%s %s with: " string from)
                                   nil nil nil
                                   query-replace-to-history-variable from t))
    (list from to current-prefix-arg)))

(defun probable-regexp-error (rx)
  (if (string-match "\\(\\`\\|[^\\\\]\\)\\(\\\\[nt]\\)" rx)
      (let ((match (match-string 2 rx)))
        (message "'%s' does't work here, try C-q %s instead"
                 match
                 (cond
                  ((string= match "\\n") "C-j")
                  ((string= match "\\t") "TAB")))
        (sit-for 2)
        t)))


Recent input:
f8 r e p o r return

Recent messages:
Mark set [2 times]
Region saved
Loading emacsbug...
Loading emacsbug...done




reply via email to

[Prev in Thread] Current Thread [Next in Thread]