aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath1992-04-05 23:25:04 +0000
committerRoland McGrath1992-04-05 23:25:04 +0000
commit5aefeebac37a94659c853a90c5c855027374c71d (patch)
tree1629b07ef2004638ceb07e7575ae9d956771d3ba
parent8c0e7b739deaa08033e465190a0cb9f98d054062 (diff)
downloademacs-5aefeebac37a94659c853a90c5c855027374c71d.tar.gz
emacs-5aefeebac37a94659c853a90c5c855027374c71d.zip
*** empty log message ***
-rw-r--r--lisp/mail/mailabbrev.el273
1 files changed, 142 insertions, 131 deletions
diff --git a/lisp/mail/mailabbrev.el b/lisp/mail/mailabbrev.el
index 438ca88d26c..40e8374c22e 100644
--- a/lisp/mail/mailabbrev.el
+++ b/lisp/mail/mailabbrev.el
@@ -1,7 +1,7 @@
1;;; Abbrev-expansion of mail aliases. 1;;; Abbrev-expansion of mail aliases.
2;;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc. 2;;; Copyright (C) 1985, 1986, 1987, 1992 Free Software Foundation, Inc.
3;;; Created: 19 oct 90, Jamie Zawinski <jwz@lucid.com> 3;;; Created: 19 oct 90, Jamie Zawinski <jwz@lucid.com>
4;;; Last change 16-mar-92. roland@gnu.ai.mit.edu 4;;; Last change 24-mar-92. jwz
5 5
6;;; This file is part of GNU Emacs. 6;;; This file is part of GNU Emacs.
7 7
@@ -133,70 +133,18 @@ no aliases, which is represented by this being a table with no entries.)")
133 133
134;;;###autoload 134;;;###autoload
135(defun mail-aliases-setup () 135(defun mail-aliases-setup ()
136 "Put on `mail-setup-hook' to use mail-abbrevs."
137 (if (and (not (vectorp mail-aliases)) 136 (if (and (not (vectorp mail-aliases))
138 (file-exists-p (mail-abbrev-mailrc-file))) 137 (file-exists-p (mail-abbrev-mailrc-file)))
139 (build-mail-aliases)) 138 (build-mail-aliases))
140 (if (boundp 'pre-abbrev-expand-hook) 139 (make-local-variable 'pre-abbrev-expand-hook)
141 (progn 140 (setq pre-abbrev-expand-hook
142 (make-local-variable 'pre-abbrev-expand-hook) 141 (cond ((and (listp pre-abbrev-expand-hook)
143 (setq pre-abbrev-expand-hook 142 (not (eq 'lambda (car pre-abbrev-expand-hook))))
144 (cond ((and (listp pre-abbrev-expand-hook) 143 (cons 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook))
145 (not (eq 'lambda (car pre-abbrev-expand-hook)))) 144 (t
146 (cons 'sendmail-pre-abbrev-expand-hook 145 (list 'sendmail-pre-abbrev-expand-hook pre-abbrev-expand-hook))))
147 pre-abbrev-expand-hook))
148 (t
149 (list 'sendmail-pre-abbrev-expand-hook
150 pre-abbrev-expand-hook)))))
151 (or mail-abbrevs-map-munged
152 (mail-abbrevs-munge-map))
153 (use-local-map mail-mode-map))
154 (abbrev-mode 1)) 146 (abbrev-mode 1))
155 147
156(defvar mail-abbrevs-map-munged nil)
157(defun mail-abbrevs-munge-map ()
158 ;; If mail-mode-map is a sparse-keymap, convert it to a non-sparse one.
159 ;; If a given key would be bound to self-insert-command in mail-mode (that
160 ;; is, it is bound to it in mail-mode-map or in global-map) then bind it
161 ;; to sendmail-self-insert-command in mail-mode-map.
162 (let* ((sparse-p (consp mail-mode-map))
163 (map (make-keymap))
164 (L (length map))
165 (i 0))
166 (while (< i L)
167 (let ((old (or (if sparse-p
168 (cdr (assq i mail-mode-map))
169 (aref mail-mode-map i))
170 (aref global-map i))))
171 (aset map i (if (eq old 'self-insert-command)
172 'sendmail-self-insert-command
173 old)))
174 (setq i (1+ i)))
175 (setq mail-mode-map map))
176 (setq mail-abbrevs-map-munged t))
177
178(defun sendmail-self-insert-command (arg)
179 "Just like self-insert-command, except that, if `mail-aliases' is an abbrev
180table, and point is in an appropriate header field of the message being
181composed, then the local-abbrev-table will be set to mail-aliases. Otherwise
182the local-abbrev-table is mail-mode-abbrev-table (the normal state). The
183variable mail-abbrev-mode-regexp controls which header-fields use the
184mail-aliases table."
185 (interactive "p")
186 (if (= (char-syntax last-command-char) ? )
187 (progn
188 (sendmail-pre-abbrev-expand-hook)
189 ;; Unhack expand-abbrev, so it will work right next time around.
190 (setq abbrev-start-location nil)))
191 (self-insert-command arg))
192
193(defun expand-mail-aliases (&rest args)
194 "Obsoleted by mail-abbrevs. Does nothing."
195 nil)
196
197(or (fboundp 'buffer-disable-undo)
198 (fset 'buffer-disable-undo 'buffer-flush-undo))
199
200;;; Originally defined in mailalias.el. Changed to call define-mail-alias 148;;; Originally defined in mailalias.el. Changed to call define-mail-alias
201;;; with an additional argument. 149;;; with an additional argument.
202;;;###autoload 150;;;###autoload
@@ -207,7 +155,7 @@ mail-aliases table."
207 nil 155 nil
208 (setq mail-aliases nil) 156 (setq mail-aliases nil)
209 (define-abbrev-table 'mail-aliases '())) 157 (define-abbrev-table 'mail-aliases '()))
210 (message "Parsing %s ..." file) 158 (message "Parsing %s..." file)
211 (let ((buffer nil) 159 (let ((buffer nil)
212 (obuf (current-buffer))) 160 (obuf (current-buffer)))
213 (unwind-protect 161 (unwind-protect
@@ -263,7 +211,7 @@ mail-aliases table."
263 mail-aliases) 211 mail-aliases)
264 (if buffer (kill-buffer buffer)) 212 (if buffer (kill-buffer buffer))
265 (set-buffer obuf))) 213 (set-buffer obuf)))
266 (message "Parsing %s ... done" file)) 214 (message "Parsing %s... done" file))
267 215
268(defvar mail-alias-seperator-string ", " 216(defvar mail-alias-seperator-string ", "
269 "*A string inserted between addresses in multi-address mail aliases. 217 "*A string inserted between addresses in multi-address mail aliases.
@@ -360,38 +308,28 @@ If DEFINITION contains multiple addresses, seperate them with commas."
360 After expanding a mail-abbrev, if fill-mode is on and we're past the 308 After expanding a mail-abbrev, if fill-mode is on and we're past the
361fill-column, break the line at the previous comma, and indent the next 309fill-column, break the line at the previous comma, and indent the next
362line." 310line."
363 (save-excursion 311 (let (p bol)
364 (let ((p (point)) 312 (while (and auto-fill-function
365 (bol (save-excursion 313 (>= (current-column) fill-column))
366 (re-search-backward mail-abbrev-mode-regexp) 314 (setq p (point))
367 (match-end 0))))
368 (goto-char bol)
369 (while (re-search-forward
370 "\\(\\s *,?\\s *\\(\"?\\)\\(/[^,]+\\)\\2\\)\\(,\\|\\s +\\|$\\)"
371 p t)
372 (save-excursion 315 (save-excursion
373 (goto-char p)
374 (insert "\nFCC: " (buffer-substring (match-beginning 3)
375 (match-end 3))))
376 (delete-region (match-beginning 1) (match-end 1)))
377 (if (and (if (boundp 'auto-fill-function)
378 auto-fill-function
379 auto-fill-hook)
380 (or (>= (current-column) fill-column)
381 (> (count-lines bol p) 1)))
382 (let (fp) 316 (let (fp)
317 (beginning-of-line)
318 (setq bol (point))
383 (goto-char p) 319 (goto-char p)
384 (while (search-backward "," bol t) 320 (while (and (>= (current-column) fill-column)
385 (save-excursion 321 (search-backward "," bol t)))
386 (forward-char 1) 322 (save-excursion
387 (insert "\n") 323 (forward-char 1)
388 (delete-horizontal-space) 324 (insert "\n")
389 (setq p (point)) 325 (delete-horizontal-space)
390 (indent-relative) 326 (setq p (point))
391 (setq fp (buffer-substring p (point))))) 327 (indent-relative)
328 (setq fp (buffer-substring p (point))))
392 (if (> (current-column) fill-column) 329 (if (> (current-column) fill-column)
393 (let ((fill-prefix (or fp "\t"))) 330 (let ((fill-prefix (or fp "\t")))
394 (do-auto-fill)))))))) 331 (do-auto-fill))))))))
332
395 333
396;;; Syntax tables and abbrev-expansion 334;;; Syntax tables and abbrev-expansion
397 335
@@ -424,7 +362,7 @@ turned on.")
424 ;; Do this if you want to have aliases with hyphens in them. This causes 362 ;; Do this if you want to have aliases with hyphens in them. This causes
425 ;; hyphens to be considered word-syntax, so forward-word will not stop at 363 ;; hyphens to be considered word-syntax, so forward-word will not stop at
426 ;; hyphens. 364 ;; hyphens.
427 ;;(modify-syntax-entry ?- "w" tab) 365 (modify-syntax-entry ?- "w" tab)
428 tab) 366 tab)
429 "The syntax table used in send-mail mode when in a mail-address header. 367 "The syntax table used in send-mail mode when in a mail-address header.
430mail-mode-syntax-table is used when the cursor is in the message body or in 368mail-mode-syntax-table is used when the cursor is in the message body or in
@@ -468,51 +406,61 @@ characters which may be a part of the name of a mail-alias.")
468 406
469(defvar mail-mode-abbrev-table) ; quiet the compiler 407(defvar mail-mode-abbrev-table) ; quiet the compiler
470 408
471(defun sendmail-pre-abbrev-expand-hook () 409;; If INSERT is non-nil, self-insert it instead of doing expand-abbrev.
410(defun sendmail-pre-abbrev-expand-hook (&optional insert)
472 (if mail-abbrev-aliases-need-to-be-resolved 411 (if mail-abbrev-aliases-need-to-be-resolved
473 (mail-resolve-all-aliases)) 412 (mail-resolve-all-aliases))
474 (if (and mail-aliases (not (eq mail-aliases t))) 413 (let ((in-header (mail-abbrev-in-expansion-header-p)))
475 (if (not (mail-abbrev-in-expansion-header-p)) 414 (if in-header
476 ;;
477 ;; If we're not in a mail header in which mail aliases should
478 ;; be expanded, then use the normal mail-mode abbrev table (if any)
479 ;; and the normal mail-mode syntax table.
480 ;;
481 (progn 415 (progn
482 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table) 416 (if (or (null mail-aliases) (eq mail-aliases t))
483 mail-mode-abbrev-table)) 417 (if insert
484 (set-syntax-table mail-mode-syntax-table)) 418 (self-insert-command insert))
419 ;;
420 ;; We are in a To: (or CC:, or whatever) header, and
421 ;; should use word-abbrevs to expand mail aliases.
422 ;; - First, install mail-aliases as the word-abbrev table.
423 ;; - Then install the mail-abbrev-syntax-table, which
424 ;; temporarily marks all of the
425 ;; non-alphanumeric-atom-characters (the "_" syntax
426 ;; ones) as being normal word-syntax. We do this
427 ;; because the C code for expand-abbrev only works on
428 ;; words, and we want these characters to be considered
429 ;; words for the purpose of abbrev expansion.
430 ;; - Then we call expand-abbrev again, recursively, to do
431 ;; the abbrev expansion with the above syntax table.
432 ;; - Then we do a trick which tells the expand-abbrev
433 ;; frame which invoked us to not continue (and thus not
434 ;; expand twice.)
435 ;; - Then we set the syntax table to
436 ;; mail-mode-header-syntax-table, which doesn't have
437 ;; anything to do with abbrev expansion, but is just for
438 ;; the user's convenience (see its doc string.)
439 ;;
440 (setq local-abbrev-table mail-aliases)
441 (set-syntax-table mail-abbrev-syntax-table)
442 (if insert
443 (self-insert-command insert)
444 ;; If the character just typed was non-alpha-symbol-syntax,
445 ;; then don't expand the abbrev now (that is, don't expand when
446 ;; the user types -.)
447 (or (= (char-syntax last-command-char) ?_)
448 (let ((pre-abbrev-expand-hook nil)) ; that's us; don't loop
449 (expand-abbrev)))
450 (setq abbrev-start-location (point) ; this is the trick
451 abbrev-start-location-buffer (current-buffer))))
452 ;; and do this just because.
453 (set-syntax-table mail-mode-header-syntax-table))
485 ;; 454 ;;
486 ;; Otherwise, we are in a To: (or CC:, or whatever) header, and 455 ;; If we're not in a mail header in which mail aliases should
487 ;; should use word-abbrevs to expand mail aliases. 456 ;; be expanded, then use the normal mail-mode abbrev table (if any)
488 ;; - First, install the mail-aliases as the word-abbrev table. 457 ;; and the normal mail-mode syntax table.
489 ;; - Then install the mail-abbrev-syntax-table, which temporarily
490 ;; marks all of the non-alphanumeric-atom-characters (the "_"
491 ;; syntax ones) as being normal word-syntax. We do this because
492 ;; the C code for expand-abbrev only works on words, and we want
493 ;; these characters to be considered words for the purpose of
494 ;; abbrev expansion.
495 ;; - Then we call expand-abbrev again, recursively, to do the abbrev
496 ;; expansion with the above syntax table.
497 ;; - Then we do a trick which tells the expand-abbrev frame which
498 ;; invoked us to not continue (and thus not expand twice.)
499 ;; - Then we set the syntax table to mail-mode-header-syntax-table,
500 ;; which doesn't have anything to do with abbrev expansion, but
501 ;; is just for the user's convenience (see its doc string.)
502 ;; 458 ;;
503 (setq local-abbrev-table mail-aliases) 459 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table)
504 ;; If the character just typed was non-alpha-symbol-syntax, then don't 460 mail-mode-abbrev-table))
505 ;; expand the abbrev now (that is, don't expand when the user types -.) 461 (set-syntax-table mail-mode-syntax-table)
506 (or (= (char-syntax last-command-char) ?_) 462 (if insert
507 (let ((pre-abbrev-expand-hook nil)) ; that's us; don't loop 463 (self-insert-command insert)))))
508 (set-syntax-table mail-abbrev-syntax-table)
509 (expand-abbrev)))
510 (setq abbrev-start-location (point) ; this is the trick
511 abbrev-start-location-buffer (current-buffer))
512 ;; and do this just because.
513 (set-syntax-table mail-mode-header-syntax-table)
514 )))
515
516 464
517;;; utilities 465;;; utilities
518 466
@@ -565,8 +513,8 @@ end of line."
565 513
566(define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias) 514(define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias)
567 515
568(define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line) 516;;(define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line)
569(define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer) 517;;(define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer)
570 518
571 519
572;;; Patching it in: 520;;; Patching it in:
@@ -579,3 +527,66 @@ end of line."
579;;; Add an autoload of define-mail-alias 527;;; Add an autoload of define-mail-alias
580 528
581(provide 'mail-abbrevs) 529(provide 'mail-abbrevs)
530
531
532;;; V18 compatibility
533;;; these defuns and defvars aren't inside the cond in deference to the
534;;; intense brokenness of the v18 byte-compiler.
535
536(defun sendmail-v18-self-insert-command (arg)
537 "Just like self-insert-command, but runs sendmail-pre-abbrev-expand-hook."
538 (interactive "p")
539 (sendmail-pre-abbrev-expand-hook arg))
540
541(defvar mail-abbrevs-v18-map-munged nil)
542
543(defun mail-abbrevs-v18-munge-map ()
544 ;; If mail-mode-map is a sparse-keymap, convert it to a non-sparse one.
545 ;; If a given key would be bound to self-insert-command in mail-mode (that
546 ;; is, it is bound to it in mail-mode-map or in global-map) then bind it
547 ;; to sendmail-self-insert-command in mail-mode-map.
548 (let* ((sparse-p (consp mail-mode-map))
549 (map (make-keymap))
550 (L (length map))
551 (i 0))
552 (while (< i L)
553 (let ((old (or (if sparse-p
554 (cdr (assq i mail-mode-map))
555 (aref mail-mode-map i))
556 (aref global-map i))))
557 (aset map i (if (eq old 'self-insert-command)
558 'sendmail-v18-self-insert-command
559 old)))
560 (setq i (1+ i)))
561 (setq mail-mode-map map))
562 (setq mail-abbrevs-v18-map-munged t))
563
564(defun mail-aliases-v18-setup ()
565 "Put this on `mail-setup-hook' to use mail-abbrevs."
566 (if (and (not (vectorp mail-aliases))
567 (file-exists-p (mail-abbrev-mailrc-file)))
568 (build-mail-aliases))
569 (or mail-abbrevs-v18-map-munged (mail-abbrevs-v18-munge-map))
570 (use-local-map mail-mode-map)
571 (abbrev-mode 1))
572
573
574(defun mail-abbrev-expand-hook-v18 ()
575 (let ((auto-fill-function auto-fill-hook)) ; new name
576 (mail-abbrev-expand-hook-v19)))
577
578
579(cond ((or (string-match "^18\\." emacs-version)
580 (and (boundp 'epoch::version) epoch::version))
581 (or (fboundp 'buffer-disable-undo)
582 (fset 'buffer-disable-undo 'buffer-flush-undo))
583 (or (fboundp 'mail-abbrev-expand-hook-v19)
584 (fset 'mail-abbrev-expand-hook-v19
585 (symbol-function 'mail-abbrev-expand-hook)))
586 (fset 'mail-abbrev-expand-hook 'mail-abbrev-expand-hook-v18)
587 (fset 'expand-mail-aliases
588 '(lambda (&rest args) "Obsoleted by mail-abbrevs. Does nothing."
589 nil))
590 )
591 (t ; v19
592 (fmakunbound 'expand-mail-aliases)))