Mercurial > emacs
comparison lisp/mail/mailabbrev.el @ 43136:9c1aa7b635bd
Require sendmail only at compile time.
(mail-mode-header-syntax-table): Var deleted.
(mail-abbrev-syntax-table): Init to nil, will compute when needed.
(sendmail-pre-abbrev-expand-hook): Only temporarily change
local-abbrev-table and the syntax table.
Compute mail-abbrev-syntax-table if that has not been done.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 06 Feb 2002 15:42:34 +0000 |
parents | b85c94030e4a |
children | c7e8bcec1caf |
comparison
equal
deleted
inserted
replaced
43135:10b506b00785 | 43136:9c1aa7b635bd |
---|---|
1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases | 1 ;;; mailabbrev.el --- abbrev-expansion of mail aliases |
2 | 2 |
3 ;; Copyright (C) 1985, 86, 87, 92, 93, 96, 1997, 2000 | 3 ;; Copyright (C) 1985, 86, 87, 92, 93, 96, 1997, 2000, 2002 |
4 ;; Free Software Foundation, Inc. | 4 ;; Free Software Foundation, Inc. |
5 | 5 |
6 ;; Author: Jamie Zawinski <jwz@lucid.com>, now <jwz@jwz.org> | 6 ;; Author: Jamie Zawinski <jwz@lucid.com>, now <jwz@jwz.org> |
7 ;; Maintainer: FSF | 7 ;; Maintainer: FSF |
8 ;; Created: 19 Oct 90 | 8 ;; Created: 19 Oct 90 |
126 | 126 |
127 ;; To use this package, do (add-hook 'mail-mode-hook 'mail-abbrevs-setup). | 127 ;; To use this package, do (add-hook 'mail-mode-hook 'mail-abbrevs-setup). |
128 | 128 |
129 ;;; Code: | 129 ;;; Code: |
130 | 130 |
131 (require 'sendmail) | 131 (eval-when-compile |
132 (require 'sendmail)) | |
132 | 133 |
133 (defgroup mail-abbrev nil | 134 (defgroup mail-abbrev nil |
134 "Expand mail aliases as abbrevs, in certain mail headers." | 135 "Expand mail aliases as abbrevs, in certain mail headers." |
135 :group 'abbrev-mode) | 136 :group 'abbrev-mode) |
136 | 137 |
396 of the current line; if it matches, abbrev mode will be turned on, otherwise | 397 of the current line; if it matches, abbrev mode will be turned on, otherwise |
397 it will be turned off. (You don't need to worry about continuation lines.) | 398 it will be turned off. (You don't need to worry about continuation lines.) |
398 This should be set to match those mail fields in which you want abbreviations | 399 This should be set to match those mail fields in which you want abbreviations |
399 turned on.") | 400 turned on.") |
400 | 401 |
401 (defvar mail-mode-header-syntax-table | 402 (defvar mail-abbrev-syntax-table nil |
402 (let ((tab (copy-syntax-table text-mode-syntax-table))) | |
403 ;; This makes the characters "@%!._-" be considered symbol-constituents | |
404 ;; but not word-constituents, so forward-sexp will move you over an | |
405 ;; entire address, but forward-word will only move you over a sequence | |
406 ;; of alphanumerics. (Clearly the right thing.) | |
407 (modify-syntax-entry ?@ "_" tab) | |
408 (modify-syntax-entry ?% "_" tab) | |
409 (modify-syntax-entry ?! "_" tab) | |
410 (modify-syntax-entry ?. "_" tab) | |
411 (modify-syntax-entry ?_ "_" tab) | |
412 (modify-syntax-entry ?- "_" tab) | |
413 (modify-syntax-entry ?< "(>" tab) | |
414 (modify-syntax-entry ?> ")<" tab) | |
415 tab) | |
416 "The syntax table used in send-mail mode when in a mail-address header. | |
417 `mail-mode-syntax-table' is used when the cursor is in the message body or in | |
418 non-address headers.") | |
419 | |
420 (defvar mail-abbrev-syntax-table | |
421 (let* ((tab (copy-syntax-table mail-mode-header-syntax-table)) | |
422 (_ (aref (standard-syntax-table) ?_)) | |
423 (w (aref (standard-syntax-table) ?w))) | |
424 (map-char-table | |
425 (function (lambda (key value) | |
426 (if (equal value _) | |
427 (set-char-table-range tab key w)))) | |
428 tab) | |
429 tab) | |
430 "The syntax-table used for abbrev-expansion purposes. | 403 "The syntax-table used for abbrev-expansion purposes. |
431 This is not actually made the current syntax table of the buffer, but | 404 This is not actually made the current syntax table of the buffer, but |
432 simply controls the set of characters which may be a part of the name | 405 simply controls the set of characters which may be a part of the name |
433 of a mail alias.") | 406 of a mail alias. The value is set up, buffer-local, when first needed.") |
434 | 407 |
435 | 408 |
436 (defun mail-abbrev-in-expansion-header-p () | 409 (defun mail-abbrev-in-expansion-header-p () |
437 "Whether point is in a mail-address header field." | 410 "Whether point is in a mail-address header field." |
438 (let ((case-fold-search t)) | 411 (let ((case-fold-search t)) |
450 (defvar mail-mode-abbrev-table) ; quiet the compiler | 423 (defvar mail-mode-abbrev-table) ; quiet the compiler |
451 | 424 |
452 (defun sendmail-pre-abbrev-expand-hook () | 425 (defun sendmail-pre-abbrev-expand-hook () |
453 (and (and mail-abbrevs (not (eq mail-abbrevs t))) | 426 (and (and mail-abbrevs (not (eq mail-abbrevs t))) |
454 (if (mail-abbrev-in-expansion-header-p) | 427 (if (mail-abbrev-in-expansion-header-p) |
455 (progn | 428 |
456 ;; | 429 ;; We are in a To: (or CC:, or whatever) header, and |
457 ;; We are in a To: (or CC:, or whatever) header, and | 430 ;; should use word-abbrevs to expand mail aliases. |
458 ;; should use word-abbrevs to expand mail aliases. | 431 (let ((local-abbrev-table mail-abbrevs) |
432 (old-syntax-table (syntax-table))) | |
459 | 433 |
460 ;; Before anything else, resolve aliases if they need it. | 434 ;; Before anything else, resolve aliases if they need it. |
461 (and mail-abbrev-aliases-need-to-be-resolved | 435 (and mail-abbrev-aliases-need-to-be-resolved |
462 (mail-resolve-all-aliases)) | 436 (mail-resolve-all-aliases)) |
463 | 437 |
464 ;; Now proceed with the abbrev section. | 438 ;; Now proceed with the abbrev section. |
465 ;; - First, install the mail-abbrevs as the word-abbrev table. | 439 ;; - We already installed mail-abbrevs as the abbrev table. |
466 ;; - Then install the mail-abbrev-syntax-table, which | 440 ;; - Then install the mail-abbrev-syntax-table, which |
467 ;; temporarily marks all of the | 441 ;; temporarily marks all of the |
468 ;; non-alphanumeric-atom-characters (the "_" | 442 ;; non-alphanumeric-atom-characters (the "_" |
469 ;; syntax ones) as being normal word-syntax. We do this | 443 ;; syntax ones) as being normal word-syntax. We do this |
470 ;; because the C code for expand-abbrev only works on words, | 444 ;; because the C code for expand-abbrev only works on words, |
471 ;; and we want these characters to be considered words for | 445 ;; and we want these characters to be considered words for |
472 ;; the purpose of abbrev expansion. | 446 ;; the purpose of abbrev expansion. |
473 ;; - Then we call expand-abbrev again, recursively, to do | 447 ;; - Then we call expand-abbrev again, recursively, to do |
474 ;; the abbrev expansion with the above syntax table. | 448 ;; the abbrev expansion with the above syntax table. |
449 ;; - Restore the previous syntax table. | |
475 ;; - Then we do a trick which tells the expand-abbrev frame | 450 ;; - Then we do a trick which tells the expand-abbrev frame |
476 ;; which invoked us to not continue (and thus not | 451 ;; which invoked us to not continue (and thus not |
477 ;; expand twice.) This means that any abbrev expansion | 452 ;; expand twice.) This means that any abbrev expansion |
478 ;; will happen as a result of this function's call to | 453 ;; will happen as a result of this function's call to |
479 ;; expand-abbrev, and not as a result of the call to | 454 ;; expand-abbrev, and not as a result of the call to |
480 ;; expand-abbrev which invoked *us*. | 455 ;; expand-abbrev which invoked *us*. |
481 ;; - Then we set the syntax table to | 456 |
482 ;; mail-mode-header-syntax-table, which doesn't have | 457 (make-local-variable 'mail-abbrev-syntax-table) |
483 ;; anything to do with abbrev expansion, but | 458 (unless mail-abbrev-syntax-table |
484 ;; is just for the user's convenience (see its doc string.) | 459 (let ((tab (copy-syntax-table old-syntax-table)) |
485 ;; | 460 (_ (aref (standard-syntax-table) ?_)) |
486 | 461 (w (aref (standard-syntax-table) ?w))) |
487 (setq local-abbrev-table mail-abbrevs) | 462 (map-char-table |
463 (function (lambda (key value) | |
464 (if (equal value _) | |
465 (set-char-table-range tab key w)))) | |
466 tab) | |
467 (setq mail-abbrev-syntax-table tab))) | |
488 | 468 |
489 ;; If the character just typed was non-alpha-symbol-syntax, | 469 ;; If the character just typed was non-alpha-symbol-syntax, |
490 ;; then don't expand the abbrev now (that is, don't expand | 470 ;; then don't expand the abbrev now (that is, don't expand |
491 ;; when the user types -.) Check the character's syntax in | 471 ;; when the user types -.) Check the character's syntax in |
492 ;; the mail-mode-header-syntax-table. | 472 ;; the usual syntax table. |
493 | 473 |
494 (set-syntax-table mail-mode-header-syntax-table) | |
495 (or (and (integerp last-command-char) | 474 (or (and (integerp last-command-char) |
496 (eq (char-syntax last-command-char) ?_)) | 475 (eq (char-syntax last-command-char) ?_)) |
497 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop. | 476 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop. |
498 ;; Use this table so that abbrevs can have hyphens in them. | 477 ;; Use this table so that abbrevs can have hyphens in them. |
499 (set-syntax-table mail-abbrev-syntax-table) | 478 (set-syntax-table mail-abbrev-syntax-table) |
500 (expand-abbrev) | 479 (unwind-protect |
501 ;; Now set it back to what it was before. | 480 (expand-abbrev) |
502 (set-syntax-table mail-mode-header-syntax-table))) | 481 ;; Now set it back to what it was before. |
482 (set-syntax-table old-syntax-table)))) | |
503 (setq abbrev-start-location (point-max) ; This is the trick. | 483 (setq abbrev-start-location (point-max) ; This is the trick. |
504 abbrev-start-location-buffer (current-buffer))) | 484 abbrev-start-location-buffer (current-buffer))) |
505 | 485 |
506 (if (or (not mail-abbrevs-only) | 486 (if (or (not mail-abbrevs-only) |
507 (eq this-command 'expand-abbrev)) | 487 (eq this-command 'expand-abbrev)) |
508 (progn | 488 ;; We're not in a mail header where mail aliases should |
509 ;; We're not in a mail header where mail aliases should | 489 ;; be expanded, then use the normal mail-mode abbrev table |
510 ;; be expanded, then use the normal mail-mode abbrev table | 490 ;; (if any) and the normal mail-mode syntax table. |
511 ;; (if any) and the normal mail-mode syntax table. | 491 nil |
512 | |
513 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table) | |
514 mail-mode-abbrev-table)) | |
515 (set-syntax-table mail-mode-syntax-table)) | |
516 ;; This is not a mail abbrev, and we should not expand it. | 492 ;; This is not a mail abbrev, and we should not expand it. |
517 ;; This kludge stops expand-abbrev from doing anything. | 493 ;; This kludge stops expand-abbrev from doing anything. |
518 (setq abbrev-start-location (point-max) | 494 (setq abbrev-start-location (point-max) |
519 abbrev-start-location-buffer (current-buffer)))) | 495 abbrev-start-location-buffer (current-buffer)))) |
520 )) | 496 )) |