diff options
| author | Simon Marshall | 1997-05-14 07:27:25 +0000 |
|---|---|---|
| committer | Simon Marshall | 1997-05-14 07:27:25 +0000 |
| commit | e28449ed4b58cb59416314eaa9b1c84f4f28e910 (patch) | |
| tree | 288c5df51e15c1ab99c17867bd69c6a4f6bc4797 | |
| parent | 1abf89b818fefc8e23655b05a500e894b260a0cd (diff) | |
| download | emacs-e28449ed4b58cb59416314eaa9b1c84f4f28e910.tar.gz emacs-e28449ed4b58cb59416314eaa9b1c84f4f28e910.zip | |
make expand-mail-aliases interactive
| -rw-r--r-- | lisp/mail/mailalias.el | 119 |
1 files changed, 63 insertions, 56 deletions
diff --git a/lisp/mail/mailalias.el b/lisp/mail/mailalias.el index e653c0e97bb..54362f11014 100644 --- a/lisp/mail/mailalias.el +++ b/lisp/mail/mailalias.el | |||
| @@ -121,75 +121,82 @@ Three types of values are possible: | |||
| 121 | 121 | ||
| 122 | ;; Called from sendmail-send-it, or similar functions, | 122 | ;; Called from sendmail-send-it, or similar functions, |
| 123 | ;; only if some mail aliases are defined. | 123 | ;; only if some mail aliases are defined. |
| 124 | ;;;###autoload | ||
| 124 | (defun expand-mail-aliases (beg end &optional exclude) | 125 | (defun expand-mail-aliases (beg end &optional exclude) |
| 125 | "Expand all mail aliases in suitable header fields found between BEG and END. | 126 | "Expand all mail aliases in suitable header fields found between BEG and END. |
| 127 | If interactive, expand in header fields before `mail-header-separator'. | ||
| 126 | Suitable header fields are `To', `From', `CC' and `BCC', `Reply-to', and | 128 | Suitable header fields are `To', `From', `CC' and `BCC', `Reply-to', and |
| 127 | their `Resent-' variants. | 129 | their `Resent-' variants. |
| 128 | 130 | ||
| 129 | Optional second arg EXCLUDE may be a regular expression defining text to be | 131 | Optional second arg EXCLUDE may be a regular expression defining text to be |
| 130 | removed from alias expansions." | 132 | removed from alias expansions." |
| 133 | (interactive | ||
| 134 | (save-excursion | ||
| 135 | (list (goto-char (point-min)) | ||
| 136 | (search-forward (concat "\n" mail-header-separator "\n"))))) | ||
| 131 | (sendmail-sync-aliases) | 137 | (sendmail-sync-aliases) |
| 132 | (if (eq mail-aliases t) | 138 | (when (eq mail-aliases t) |
| 133 | (progn (setq mail-aliases nil) (build-mail-aliases))) | 139 | (setq mail-aliases nil) |
| 134 | (goto-char beg) | 140 | (build-mail-aliases)) |
| 135 | (setq end (set-marker (make-marker) end)) | 141 | (save-excursion |
| 136 | (let ((case-fold-search nil)) | 142 | (goto-char beg) |
| 137 | (while (let ((case-fold-search t)) | 143 | (setq end (set-marker (make-marker) end)) |
| 138 | (re-search-forward mail-address-field-regexp end t)) | 144 | (let ((case-fold-search nil)) |
| 139 | (skip-chars-forward " \t") | 145 | (while (let ((case-fold-search t)) |
| 140 | (let ((beg1 (point)) | 146 | (re-search-forward mail-address-field-regexp end t)) |
| 141 | end1 pos epos seplen | 147 | (skip-chars-forward " \t") |
| 142 | ;; DISABLED-ALIASES records aliases temporarily disabled | 148 | (let ((beg1 (point)) |
| 143 | ;; while we scan text that resulted from expanding those aliases. | 149 | end1 pos epos seplen |
| 144 | ;; Each element is (ALIAS . TILL-WHEN), where TILL-WHEN | 150 | ;; DISABLED-ALIASES records aliases temporarily disabled |
| 145 | ;; is where to reenable the alias (expressed as number of chars | 151 | ;; while we scan text that resulted from expanding those aliases. |
| 146 | ;; counting from END1). | 152 | ;; Each element is (ALIAS . TILL-WHEN), where TILL-WHEN |
| 147 | (disabled-aliases nil)) | 153 | ;; is where to reenable the alias (expressed as number of chars |
| 148 | (re-search-forward "^[^ \t]" end 'move) | 154 | ;; counting from END1). |
| 149 | (beginning-of-line) | 155 | (disabled-aliases nil)) |
| 150 | (skip-chars-backward " \t\n") | 156 | (re-search-forward "^[^ \t]" end 'move) |
| 151 | (setq end1 (point-marker)) | 157 | (beginning-of-line) |
| 152 | (goto-char beg1) | 158 | (skip-chars-backward " \t\n") |
| 153 | (while (< (point) end1) | 159 | (setq end1 (point-marker)) |
| 154 | (setq pos (point)) | 160 | (goto-char beg1) |
| 155 | ;; Reenable any aliases which were disabled for ranges | 161 | (while (< (point) end1) |
| 156 | ;; that we have passed out of. | 162 | (setq pos (point)) |
| 157 | (while (and disabled-aliases (> pos (- end1 (cdr (car disabled-aliases))))) | 163 | ;; Reenable any aliases which were disabled for ranges |
| 158 | (setq disabled-aliases (cdr disabled-aliases))) | 164 | ;; that we have passed out of. |
| 159 | ;; EPOS gets position of end of next name; | 165 | (while (and disabled-aliases |
| 160 | ;; SEPLEN gets length of whitespace&separator that follows it. | 166 | (> pos (- end1 (cdr (car disabled-aliases))))) |
| 161 | (if (re-search-forward "[ \t]*[\n,][ \t]*" end1 t) | 167 | (setq disabled-aliases (cdr disabled-aliases))) |
| 162 | (setq epos (match-beginning 0) | 168 | ;; EPOS gets position of end of next name; |
| 163 | seplen (- (point) epos)) | 169 | ;; SEPLEN gets length of whitespace&separator that follows it. |
| 164 | (setq epos (marker-position end1) seplen 0)) | 170 | (if (re-search-forward "[ \t]*[\n,][ \t]*" end1 t) |
| 165 | (let (translation | 171 | (setq epos (match-beginning 0) |
| 166 | (string (buffer-substring-no-properties pos epos))) | 172 | seplen (- (point) epos)) |
| 167 | (if (and (not (assoc string disabled-aliases)) | 173 | (setq epos (marker-position end1) seplen 0)) |
| 168 | (setq translation | 174 | (let ((string (buffer-substring-no-properties pos epos)) |
| 169 | (cdr (assoc string mail-aliases)))) | 175 | translation) |
| 170 | (progn | 176 | (if (and (not (assoc string disabled-aliases)) |
| 171 | ;; This name is an alias. Disable it. | 177 | (setq translation (cdr (assoc string mail-aliases)))) |
| 172 | (setq disabled-aliases (cons (cons string (- end1 epos)) | 178 | (progn |
| 173 | disabled-aliases)) | 179 | ;; This name is an alias. Disable it. |
| 174 | ;; Replace the alias with its expansion | 180 | (setq disabled-aliases (cons (cons string (- end1 epos)) |
| 175 | ;; then rescan the expansion for more aliases. | 181 | disabled-aliases)) |
| 176 | (goto-char pos) | 182 | ;; Replace the alias with its expansion |
| 177 | (insert translation) | 183 | ;; then rescan the expansion for more aliases. |
| 178 | (if exclude | 184 | (goto-char pos) |
| 179 | (let ((regexp | 185 | (insert translation) |
| 180 | (concat "\\b\\(" exclude "\\)\\b")) | 186 | (when exclude |
| 187 | (let ((regexp (concat "\\b\\(" exclude "\\)\\b")) | ||
| 181 | (end (point-marker))) | 188 | (end (point-marker))) |
| 182 | (goto-char pos) | 189 | (goto-char pos) |
| 183 | (while (re-search-forward regexp end t) | 190 | (while (re-search-forward regexp end t) |
| 184 | (replace-match "")) | 191 | (replace-match "")) |
| 185 | (goto-char end))) | 192 | (goto-char end))) |
| 186 | (delete-region (point) (+ (point) (- epos pos))) | 193 | (delete-region (point) (+ (point) (- epos pos))) |
| 187 | (goto-char pos)) | 194 | (goto-char pos)) |
| 188 | ;; Name is not an alias. Skip to start of next name. | 195 | ;; Name is not an alias. Skip to start of next name. |
| 189 | (goto-char epos) | 196 | (goto-char epos) |
| 190 | (forward-char seplen)))) | 197 | (forward-char seplen)))) |
| 191 | (set-marker end1 nil))) | 198 | (set-marker end1 nil))) |
| 192 | (set-marker end nil))) | 199 | (set-marker end nil)))) |
| 193 | 200 | ||
| 194 | ;; Called by mail-setup, or similar functions, only if the file specified | 201 | ;; Called by mail-setup, or similar functions, only if the file specified |
| 195 | ;; by mail-personal-alias-file (usually `~/.mailrc') exists. | 202 | ;; by mail-personal-alias-file (usually `~/.mailrc') exists. |