emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r102838: * lisp/mail/mail-utils.el (m


From: Stefan Monnier
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r102838: * lisp/mail/mail-utils.el (mail-strip-quoted-names): Make the regexp code
Date: Thu, 13 Jan 2011 16:48:34 -0500
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 102838
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Thu 2011-01-13 16:48:34 -0500
message:
  * lisp/mail/mail-utils.el (mail-strip-quoted-names): Make the regexp code
  work for nested comments.
modified:
  lisp/ChangeLog
  lisp/mail/mail-utils.el
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog    2011-01-13 20:46:38 +0000
+++ b/lisp/ChangeLog    2011-01-13 21:48:34 +0000
@@ -1,5 +1,8 @@
 2011-01-13  Stefan Monnier  <address@hidden>
 
+       * mail/mail-utils.el (mail-strip-quoted-names): Make the regexp code
+       work for nested comments.
+
        * progmodes/prolog.el: Use syntax-propertize.  Further code cleanup.
        (prolog-use-prolog-tokenizer-flag): Change default when
        syntax-propertize can be used.

=== modified file 'lisp/mail/mail-utils.el'
--- a/lisp/mail/mail-utils.el   2011-01-02 20:28:40 +0000
+++ b/lisp/mail/mail-utils.el   2011-01-13 21:48:34 +0000
@@ -182,56 +182,37 @@
               (mapconcat 'identity (rfc822-addresses address) ", "))
       (let (pos)
 
-       ;; Detect nested comments.
-       (if (string-match "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*(" address)
-          ;; Strip nested comments.
-          (with-temp-buffer
-            (insert address)
-            (set-syntax-table lisp-mode-syntax-table)
-            (goto-char 1)
-            (while (search-forward "(" nil t)
-              (forward-char -1)
-              (skip-chars-backward " \t")
-              (delete-region (point)
-                             (save-excursion
-                               (condition-case ()
-                                   (forward-sexp 1)
-                                 (error (goto-char (point-max))))
-                                 (point))))
-            (setq address (buffer-string)))
-        ;; Strip non-nested comments an easier way.
-        (while (setq pos (string-match
-                           ;; This doesn't hack rfc822 nested comments
-                           ;;  `(xyzzy (foo) whinge)' properly.  Big deal.
-                           "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*)"
-                           address))
-          (setq address (replace-match "" nil nil address 0))))
-
-       ;; strip surrounding whitespace
-       (string-match "\\`[ \t\n]*" address)
-       (setq address (substring address
-                               (match-end 0)
-                               (string-match "[ \t\n]*\\'" address
-                                             (match-end 0))))
-
-       ;; strip `quoted' names (This is supposed to hack `"Foo Bar" 
<address@hidden>')
-       (setq pos 0)
-       (while (setq pos (string-match
+        ;; Strip comments.
+        (while (setq pos (string-match
+                          "[ \t]*(\\([^()\\]\\|\\\\.\\|\\\\\n\\)*)"
+                          address))
+          (setq address (replace-match "" nil nil address 0)))
+
+        ;; strip surrounding whitespace
+        (string-match "\\`[ \t\n]*" address)
+        (setq address (substring address
+                                 (match-end 0)
+                                 (string-match "[ \t\n]*\\'" address
+                                               (match-end 0))))
+
+        ;; strip `quoted' names (This is supposed to hack `"Foo Bar" 
<address@hidden>')
+        (setq pos 0)
+        (while (setq pos (string-match
                           "\\([ \t]?\\)\\([ 
\t]*\"\\([^\"\\]\\|\\\\.\\|\\\\\n\\)*\"[ \t\n]*\\)"
                          address pos))
-        ;; If the next thing is "@", we have "foo bar"@host.  Leave it.
-        (if (and (> (length address) (match-end 0))
-                 (= (aref address (match-end 0)) ?@))
-            (setq pos (match-end 0))
-          ;; Otherwise discard the "..." part.
-          (setq address (replace-match "" nil nil address 2))))
-       ;; If this address contains <...>, replace it with just
-       ;; the part between the <...>.
-       (while (setq pos (string-match 
"\\(,\\s-*\\|\\`\\)\\([^,]*<\\([^>,:]*\\)>[^,]*\\)\\(\\s-*,\\|\\'\\)"
-                                     address))
-        (setq address (replace-match (match-string 3 address)
-                                     nil 'literal address 2)))
-       address))))
+          ;; If the next thing is "@", we have "foo bar"@host.  Leave it.
+          (if (and (> (length address) (match-end 0))
+                   (= (aref address (match-end 0)) ?@))
+              (setq pos (match-end 0))
+            ;; Otherwise discard the "..." part.
+            (setq address (replace-match "" nil nil address 2))))
+        ;; If this address contains <...>, replace it with just
+        ;; the part between the <...>.
+        (while (setq pos (string-match 
"\\(,\\s-*\\|\\`\\)\\([^,]*<\\([^>,:]*\\)>[^,]*\\)\\(\\s-*,\\|\\'\\)"
+                                       address))
+          (setq address (replace-match (match-string 3 address)
+                                       nil 'literal address 2)))
+        address))))
 
 ;; The following piece of ugliness is legacy code.  The name was an
 ;; unfortunate choice --- a flagrant violation of the Emacs Lisp


reply via email to

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