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

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

Re: [:upper:] inconsistency


From: Francis Wright
Subject: Re: [:upper:] inconsistency
Date: Sun, 14 Jan 2007 20:19:05 -0000

From: "Stefan Monnier" <address@hidden>
To: "Francis Wright" <address@hidden>
Cc: <address@hidden>
Sent: Sunday, January 07, 2007 7:32 PM
Subject: Re: [:upper:] inconsistency


I would expect the regexp [[:upper:]] to behave the same as [A-Z] (in
English text).  However, by default [[:upper:]] matches all letters,
whereas [A-Z] matches only upper case letters, as I expect.

Hmm... I can't see to get A-Z to only match upper-case letters ...
Oh I see what you mean now.  Does the patch below fix it for you?
(I guess we could also allows the use of [:UPPER:] so you could workaround
this problem ;-)


       Stefan


--- orig/lisp/isearch.el
+++ mod/lisp/isearch.el
@@ -2297,7 +2297,15 @@
       (setq found t))
   (setq quote-flag nil)))
      (setq i (1+ i)))
-    (not found)))
+    (or (not found)
+ ;; Even if there's no uppercase char, we want to detect the use of
+        ;; [:upper:] char-class.
+        (and regexp-flag (string-match "\\[:upper:]" string)
+             (condition-case err
+ (progn (string-match (substring string 0 (match-string 0)) "")
+                        nil)
+               (invalid-regexp
+                (equal "Unmatched [ or [^" (cadr err))))))))

;; Portability functions to support various Emacs versions.


Thanks for the patch. However, it doesn't fix the problem. The following version of the function that you patched does seem to work. I have moved the `not' outside the `or' at the start of your patch. The code from your patch that I have commented out does not work but I don't understand it well enough to suggest a fix. The sexpr `(match-string 0)' returns a string, whereas `substring' wants an integer argument.

(defun isearch-no-upper-case-p (string regexp-flag)
 "Return t if there are no upper case chars in STRING.
If REGEXP-FLAG is non-nil, disregard letters preceded by `\\' (but not `\\\\')
since they have special meaning in a regexp."
 (let (quote-flag (i 0) (len (length string)) found)
   (while (and (not found) (< i len))
     (let ((char (aref string i)))
       (if (and regexp-flag (eq char ?\\))
           (setq quote-flag (not quote-flag))
         (if (and (not quote-flag) (not (eq char (downcase char))))
             (setq found t))
         (setq quote-flag nil)))
     (setq i (1+ i)))
   (not
    (or found
        ;; Even if there's no uppercase char, we want to detect the
        ;; use of [:upper:] char-class.
        (and regexp-flag (string-match "\\[:upper:]" string)
;;            (condition-case err
;; (progn (string-match (substring string 0 (match-string 0)) "")
;;                       nil)
;;              (invalid-regexp
;;               (equal "Unmatched [ or [^" (cadr err))))
             )))))

I think this problem really needs fixing at a lower level. When the regexp matcher is matching character classes such as [:upper:] and [:lower:] it should ignore case-fold-search.

Francis




reply via email to

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