diff options
| author | Stefan Monnier | 2011-01-13 16:48:34 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2011-01-13 16:48:34 -0500 |
| commit | b49a2dbf58c276d48e3251e0d565557bf031a43e (patch) | |
| tree | a0c2782874ef7d05098a56ced5242a81de012764 | |
| parent | db5d03ea568aa674569d7792a04c95e0ebffac68 (diff) | |
| download | emacs-b49a2dbf58c276d48e3251e0d565557bf031a43e.tar.gz emacs-b49a2dbf58c276d48e3251e0d565557bf031a43e.zip | |
* lisp/mail/mail-utils.el (mail-strip-quoted-names): Make the regexp code
work for nested comments.
| -rw-r--r-- | lisp/ChangeLog | 3 | ||||
| -rw-r--r-- | lisp/mail/mail-utils.el | 73 |
2 files changed, 30 insertions, 46 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 6d531655d7f..94d2ba209aa 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,5 +1,8 @@ | |||
| 1 | 2011-01-13 Stefan Monnier <monnier@iro.umontreal.ca> | 1 | 2011-01-13 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 2 | ||
| 3 | * mail/mail-utils.el (mail-strip-quoted-names): Make the regexp code | ||
| 4 | work for nested comments. | ||
| 5 | |||
| 3 | * progmodes/prolog.el: Use syntax-propertize. Further code cleanup. | 6 | * progmodes/prolog.el: Use syntax-propertize. Further code cleanup. |
| 4 | (prolog-use-prolog-tokenizer-flag): Change default when | 7 | (prolog-use-prolog-tokenizer-flag): Change default when |
| 5 | syntax-propertize can be used. | 8 | syntax-propertize can be used. |
diff --git a/lisp/mail/mail-utils.el b/lisp/mail/mail-utils.el index 81a2bd49441..1e9412cb7a1 100644 --- a/lisp/mail/mail-utils.el +++ b/lisp/mail/mail-utils.el | |||
| @@ -182,56 +182,37 @@ Return a modified address list." | |||
| 182 | (mapconcat 'identity (rfc822-addresses address) ", ")) | 182 | (mapconcat 'identity (rfc822-addresses address) ", ")) |
| 183 | (let (pos) | 183 | (let (pos) |
| 184 | 184 | ||
| 185 | ;; Detect nested comments. | 185 | ;; Strip comments. |
| 186 | (if (string-match "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*(" address) | 186 | (while (setq pos (string-match |
| 187 | ;; Strip nested comments. | 187 | "[ \t]*(\\([^()\\]\\|\\\\.\\|\\\\\n\\)*)" |
| 188 | (with-temp-buffer | 188 | address)) |
| 189 | (insert address) | 189 | (setq address (replace-match "" nil nil address 0))) |
| 190 | (set-syntax-table lisp-mode-syntax-table) | ||
| 191 | (goto-char 1) | ||
| 192 | (while (search-forward "(" nil t) | ||
| 193 | (forward-char -1) | ||
| 194 | (skip-chars-backward " \t") | ||
| 195 | (delete-region (point) | ||
| 196 | (save-excursion | ||
| 197 | (condition-case () | ||
| 198 | (forward-sexp 1) | ||
| 199 | (error (goto-char (point-max)))) | ||
| 200 | (point)))) | ||
| 201 | (setq address (buffer-string))) | ||
| 202 | ;; Strip non-nested comments an easier way. | ||
| 203 | (while (setq pos (string-match | ||
| 204 | ;; This doesn't hack rfc822 nested comments | ||
| 205 | ;; `(xyzzy (foo) whinge)' properly. Big deal. | ||
| 206 | "[ \t]*(\\([^)\\]\\|\\\\.\\|\\\\\n\\)*)" | ||
| 207 | address)) | ||
| 208 | (setq address (replace-match "" nil nil address 0)))) | ||
| 209 | 190 | ||
| 210 | ;; strip surrounding whitespace | 191 | ;; strip surrounding whitespace |
| 211 | (string-match "\\`[ \t\n]*" address) | 192 | (string-match "\\`[ \t\n]*" address) |
| 212 | (setq address (substring address | 193 | (setq address (substring address |
| 213 | (match-end 0) | 194 | (match-end 0) |
| 214 | (string-match "[ \t\n]*\\'" address | 195 | (string-match "[ \t\n]*\\'" address |
| 215 | (match-end 0)))) | 196 | (match-end 0)))) |
| 216 | 197 | ||
| 217 | ;; strip `quoted' names (This is supposed to hack `"Foo Bar" <bar@host>') | 198 | ;; strip `quoted' names (This is supposed to hack `"Foo Bar" <bar@host>') |
| 218 | (setq pos 0) | 199 | (setq pos 0) |
| 219 | (while (setq pos (string-match | 200 | (while (setq pos (string-match |
| 220 | "\\([ \t]?\\)\\([ \t]*\"\\([^\"\\]\\|\\\\.\\|\\\\\n\\)*\"[ \t\n]*\\)" | 201 | "\\([ \t]?\\)\\([ \t]*\"\\([^\"\\]\\|\\\\.\\|\\\\\n\\)*\"[ \t\n]*\\)" |
| 221 | address pos)) | 202 | address pos)) |
| 222 | ;; If the next thing is "@", we have "foo bar"@host. Leave it. | 203 | ;; If the next thing is "@", we have "foo bar"@host. Leave it. |
| 223 | (if (and (> (length address) (match-end 0)) | 204 | (if (and (> (length address) (match-end 0)) |
| 224 | (= (aref address (match-end 0)) ?@)) | 205 | (= (aref address (match-end 0)) ?@)) |
| 225 | (setq pos (match-end 0)) | 206 | (setq pos (match-end 0)) |
| 226 | ;; Otherwise discard the "..." part. | 207 | ;; Otherwise discard the "..." part. |
| 227 | (setq address (replace-match "" nil nil address 2)))) | 208 | (setq address (replace-match "" nil nil address 2)))) |
| 228 | ;; If this address contains <...>, replace it with just | 209 | ;; If this address contains <...>, replace it with just |
| 229 | ;; the part between the <...>. | 210 | ;; the part between the <...>. |
| 230 | (while (setq pos (string-match "\\(,\\s-*\\|\\`\\)\\([^,]*<\\([^>,:]*\\)>[^,]*\\)\\(\\s-*,\\|\\'\\)" | 211 | (while (setq pos (string-match "\\(,\\s-*\\|\\`\\)\\([^,]*<\\([^>,:]*\\)>[^,]*\\)\\(\\s-*,\\|\\'\\)" |
| 231 | address)) | 212 | address)) |
| 232 | (setq address (replace-match (match-string 3 address) | 213 | (setq address (replace-match (match-string 3 address) |
| 233 | nil 'literal address 2))) | 214 | nil 'literal address 2))) |
| 234 | address)))) | 215 | address)))) |
| 235 | 216 | ||
| 236 | ;; The following piece of ugliness is legacy code. The name was an | 217 | ;; The following piece of ugliness is legacy code. The name was an |
| 237 | ;; unfortunate choice --- a flagrant violation of the Emacs Lisp | 218 | ;; unfortunate choice --- a flagrant violation of the Emacs Lisp |