Mercurial > emacs
comparison lisp/mail/mailabbrev.el @ 627:59b674ceaf31
*** empty log message ***
author | Roland McGrath <roland@gnu.org> |
---|---|
date | Sun, 03 May 1992 21:16:09 +0000 |
parents | 615cdef1368d |
children | 505130d1ddf8 |
comparison
equal
deleted
inserted
replaced
626:ff8773516db2 | 627:59b674ceaf31 |
---|---|
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 5-apr-92 by roland@gnu.ai.mit.edu. | 4 ;;; Modified: 5 apr 92, Roland McGrath <roland@gnu.ai.mit.edu> |
5 ;;; Last change 22-apr-92. jwz | |
5 | 6 |
6 ;;; This file is part of GNU Emacs. | 7 ;;; This file is part of GNU Emacs. |
7 | 8 |
8 ;;; GNU Emacs is free software; you can redistribute it and/or modify | 9 ;;; GNU Emacs is free software; you can redistribute it and/or modify |
9 ;;; it under the terms of the GNU General Public License as published by | 10 ;;; it under the terms of the GNU General Public License as published by |
64 ;;; (This is bogus because mail-delivery programs want commas, not spaces, | 65 ;;; (This is bogus because mail-delivery programs want commas, not spaces, |
65 ;;; but that's what the file format is, so we have to live with it.) | 66 ;;; but that's what the file format is, so we have to live with it.) |
66 ;;; | 67 ;;; |
67 ;;; If you like, you can call the function define-mail-alias to define your | 68 ;;; If you like, you can call the function define-mail-alias to define your |
68 ;;; mail-aliases instead of using a .mailrc file. When you call it in this | 69 ;;; mail-aliases instead of using a .mailrc file. When you call it in this |
69 ;;; way, addresses are seperated by commas. | 70 ;;; way, addresses are separated by commas. |
70 ;;; | 71 ;;; |
71 ;;; CAVEAT: This works on most Sun systems; I have been told that some versions | 72 ;;; CAVEAT: This works on most Sun systems; I have been told that some versions |
72 ;;; of /bin/mail do not understand double-quotes in the .mailrc file. So you | 73 ;;; of /bin/mail do not understand double-quotes in the .mailrc file. So you |
73 ;;; should make sure your version does before including verbose addresses like | 74 ;;; should make sure your version does before including verbose addresses like |
74 ;;; this. One solution to this, if you are on a system whose /bin/mail doesn't | 75 ;;; this. One solution to this, if you are on a system whose /bin/mail doesn't |
104 ;;; type SPC at the end of the abbrev before moving away) then you can do | 105 ;;; type SPC at the end of the abbrev before moving away) then you can do |
105 ;;; | 106 ;;; |
106 ;;; (define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line) | 107 ;;; (define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line) |
107 ;;; (define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer) | 108 ;;; (define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer) |
108 ;;; | 109 ;;; |
109 ;;; If you want multiple addresses seperated by a string other than ", " then | 110 ;;; If you want multiple addresses separated by a string other than ", " then |
110 ;;; you can set the variable mail-alias-seperator-string to it. This has to | 111 ;;; you can set the variable mail-alias-separator-string to it. This has to |
111 ;;; be a comma bracketed by whitespace if you want any kind of reasonable | 112 ;;; be a comma bracketed by whitespace if you want any kind of reasonable |
112 ;;; behaviour. | 113 ;;; behaviour. |
113 ;;; | 114 ;;; |
114 ;;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and | 115 ;;; Thanks to Harald Hanche-Olsen, Michael Ernst, David Loeffler, and |
115 ;;; Noah Friedman for suggestions and bug reports. | 116 ;;; Noah Friedman for suggestions and bug reports. |
117 ;;; | |
118 ;;; INSTALLATION | |
119 ;;; | |
120 ;;; If you are using Emacs 18, you shouldn't have to do anything at all to | |
121 ;;; install this code other than load this file. You might want to do this | |
122 ;;; to have this code loaded only when needed: | |
123 ;;; | |
124 ;;; (setq mail-setup-hook '(lambda () (require 'mail-abbrevs))) | |
125 ;;; | |
126 ;;; Simply loading this file will redefine and overload the required | |
127 ;;; functions. | |
128 ;;; | |
129 ;;; If you want to install this code more permanently (instead of loading | |
130 ;;; it as a patch) you need to do the following: | |
131 ;;; | |
132 ;;; - Remove the entire file mailalias.el; | |
133 ;;; - Remove the definition of mail-aliases from sendmail.el; | |
134 ;;; - Add a call to mail-aliases-setup to the front of the function | |
135 ;;; mail-setup in the file sendmail.el; | |
136 ;;; - Remove the call to expand-mail-aliases from the function | |
137 ;;; sendmail-send-it in the file sendmail.el; | |
138 ;;; - Remove the autoload of expand-mail-aliases from the file sendmail.el; | |
139 ;;; - Remove the autoload of build-mail-aliases from the file sendmail.el; | |
140 ;;; - Add an autoload of define-mail-alias to loaddefs.el. | |
116 | 141 |
117 (require 'sendmail) | 142 (require 'sendmail) |
118 | 143 |
119 (defvar mail-abbrev-mailrc-file nil | 144 (defvar mail-abbrev-mailrc-file nil |
120 "Name of file with mail aliases. If nil, ~/.mailrc is used.") | 145 "Name of file with mail aliases. If nil, ~/.mailrc is used.") |
211 mail-aliases) | 236 mail-aliases) |
212 (if buffer (kill-buffer buffer)) | 237 (if buffer (kill-buffer buffer)) |
213 (set-buffer obuf))) | 238 (set-buffer obuf))) |
214 (message "Parsing %s... done" file)) | 239 (message "Parsing %s... done" file)) |
215 | 240 |
216 (defvar mail-alias-seperator-string ", " | 241 (defvar mail-alias-separator-string ", " |
217 "*A string inserted between addresses in multi-address mail aliases. | 242 "*A string inserted between addresses in multi-address mail aliases. |
218 This has to contain a comma, so \", \" is a reasonable value. You might | 243 This has to contain a comma, so \", \" is a reasonable value. You might |
219 also want something like \",\\n \" to get each address on its own line.") | 244 also want something like \",\\n \" to get each address on its own line.") |
220 | 245 |
221 ;; define-mail-alias sets this flag, which causes mail-resolve-all-aliases | 246 ;; define-mail-alias sets this flag, which causes mail-resolve-all-aliases |
226 ;; stuff parsed from the .mailrc file. | 251 ;; stuff parsed from the .mailrc file. |
227 ;; | 252 ;; |
228 ;;;###autoload | 253 ;;;###autoload |
229 (defun define-mail-alias (name definition &optional from-mailrc-file) | 254 (defun define-mail-alias (name definition &optional from-mailrc-file) |
230 "Define NAME as a mail-alias that translates to DEFINITION. | 255 "Define NAME as a mail-alias that translates to DEFINITION. |
231 If DEFINITION contains multiple addresses, seperate them with commas." | 256 If DEFINITION contains multiple addresses, separate them with commas." |
232 ;; When this is called from build-mail-aliases, the third argument is | 257 ;; When this is called from build-mail-aliases, the third argument is |
233 ;; true, and we do some evil space->comma hacking like /bin/mail does. | 258 ;; true, and we do some evil space->comma hacking like /bin/mail does. |
234 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") | 259 (interactive "sDefine mail alias: \nsDefine %s as mail alias for: ") |
235 ;; Read the defaults first, if we have not done so. | 260 ;; Read the defaults first, if we have not done so. |
236 (if (vectorp mail-aliases) | 261 (if (vectorp mail-aliases) |
249 (L (length definition)) | 274 (L (length definition)) |
250 end) | 275 end) |
251 (while start | 276 (while start |
252 ;; If we're reading from the mailrc file, then addresses are delimited | 277 ;; If we're reading from the mailrc file, then addresses are delimited |
253 ;; by spaces, and addresses with embedded spaces must be surrounded by | 278 ;; by spaces, and addresses with embedded spaces must be surrounded by |
254 ;; double-quotes. Otherwise, addresses are seperated by commas. | 279 ;; double-quotes. Otherwise, addresses are separated by commas. |
255 (if from-mailrc-file | 280 (if from-mailrc-file |
256 (if (eq ?\" (aref definition start)) | 281 (if (eq ?\" (aref definition start)) |
257 (setq start (1+ start) | 282 (setq start (1+ start) |
258 end (string-match "\"[ \t,]*" definition start)) | 283 end (string-match "\"[ \t,]*" definition start)) |
259 (setq end (string-match "[ \t,]+" definition start))) | 284 (setq end (string-match "[ \t,]+" definition start))) |
262 (setq start (and end | 287 (setq start (and end |
263 (/= (match-end 0) L) | 288 (/= (match-end 0) L) |
264 (match-end 0)))) | 289 (match-end 0)))) |
265 (setq definition (mapconcat (function identity) | 290 (setq definition (mapconcat (function identity) |
266 (nreverse result) | 291 (nreverse result) |
267 mail-alias-seperator-string))) | 292 mail-alias-separator-string))) |
268 (setq mail-abbrev-aliases-need-to-be-resolved t) | 293 (setq mail-abbrev-aliases-need-to-be-resolved t) |
269 (setq name (downcase name)) | 294 (setq name (downcase name)) |
270 ;; use an abbrev table instead of an alist for mail-aliases. | 295 ;; use an abbrev table instead of an alist for mail-aliases. |
271 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed. | 296 (let ((abbrevs-changed abbrevs-changed)) ; protect this from being changed. |
272 (define-abbrev mail-aliases name definition 'mail-abbrev-expand-hook))) | 297 (define-abbrev mail-aliases name definition 'mail-abbrev-expand-hook))) |
296 (mapconcat (function (lambda (x) | 321 (mapconcat (function (lambda (x) |
297 (or (mail-resolve-all-aliases-1 | 322 (or (mail-resolve-all-aliases-1 |
298 (intern-soft x mail-aliases)) | 323 (intern-soft x mail-aliases)) |
299 x))) | 324 x))) |
300 (nreverse result) | 325 (nreverse result) |
301 mail-alias-seperator-string)) | 326 mail-alias-separator-string)) |
302 (set sym definition)))) | 327 (set sym definition)))) |
303 (symbol-value sym)) | 328 (symbol-value sym)) |
304 | 329 |
305 | 330 |
306 (defun mail-abbrev-expand-hook-v19 () | 331 (defun mail-abbrev-expand-hook () |
307 "For use as the fourth arg to define-abbrev. | 332 "For use as the fourth arg to define-abbrev. |
308 After expanding a mail-abbrev, if fill-mode is on and we're past the | 333 After expanding a mail-abbrev, if fill-mode is on and we're past the |
309 fill-column, break the line at the previous comma, and indent the next | 334 fill-column, break the line at the previous comma, and indent the next |
310 line." | 335 line." |
311 (save-excursion | 336 (save-excursion |
312 (let ((p (point)) | 337 (let ((p (point)) |
313 bol comma fp) | 338 bol comma fp) |
319 (search-backward "," bol t)) | 344 (search-backward "," bol t)) |
320 (setq comma (point)) | 345 (setq comma (point)) |
321 (forward-char 1) ; Now we are just past the comma. | 346 (forward-char 1) ; Now we are just past the comma. |
322 (insert "\n") | 347 (insert "\n") |
323 (delete-horizontal-space) | 348 (delete-horizontal-space) |
324 (setq p (point)) | 349 (setq p (point)) |
325 (indent-relative) | 350 (indent-relative) |
326 (setq fp (buffer-substring p (point))) | 351 (setq fp (buffer-substring p (point))) |
327 ;; Go to the end of the new line. | 352 ;; Go to the end of the new line. |
328 (end-of-line) | 353 (end-of-line) |
329 (if (> (current-column) fill-column) | 354 (if (> (current-column) fill-column) |
331 (let ((fill-prefix (or fp "\t"))) | 356 (let ((fill-prefix (or fp "\t"))) |
332 (do-auto-fill))) | 357 (do-auto-fill))) |
333 ;; Resume the search. | 358 ;; Resume the search. |
334 (goto-char comma) | 359 (goto-char comma) |
335 )))) | 360 )))) |
336 | |
337 | 361 |
338 ;;; Syntax tables and abbrev-expansion | 362 ;;; Syntax tables and abbrev-expansion |
339 | 363 |
340 (defvar mail-abbrev-mode-regexp "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\):" | 364 (defvar mail-abbrev-mode-regexp "^\\(Resent-\\)?\\(To\\|From\\|CC\\|BCC\\):" |
341 "*Regexp to select mail-headers in which mail-aliases should be expanded. | 365 "*Regexp to select mail-headers in which mail-aliases should be expanded. |
348 (defvar mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table) | 372 (defvar mail-mode-syntax-table (copy-syntax-table text-mode-syntax-table) |
349 "The syntax table which is used in send-mail mode message bodies.") | 373 "The syntax table which is used in send-mail mode message bodies.") |
350 | 374 |
351 (defvar mail-mode-header-syntax-table | 375 (defvar mail-mode-header-syntax-table |
352 (let ((tab (copy-syntax-table text-mode-syntax-table))) | 376 (let ((tab (copy-syntax-table text-mode-syntax-table))) |
353 ;; This makes the caracters "@%!._-" be considered symbol-consituents | 377 ;; This makes the characters "@%!._-" be considered symbol-consituents |
354 ;; but not word-constituents, so forward-sexp will move you over an | 378 ;; but not word-constituents, so forward-sexp will move you over an |
355 ;; entire address, but forward-word will only move you over a sequence | 379 ;; entire address, but forward-word will only move you over a sequence |
356 ;; of alphanumerics. (Clearly the right thing.) | 380 ;; of alphanumerics. (Clearly the right thing.) |
357 (modify-syntax-entry ?@ "_" tab) | 381 (modify-syntax-entry ?@ "_" tab) |
358 (modify-syntax-entry ?% "_" tab) | 382 (modify-syntax-entry ?% "_" tab) |
360 (modify-syntax-entry ?. "_" tab) | 384 (modify-syntax-entry ?. "_" tab) |
361 (modify-syntax-entry ?_ "_" tab) | 385 (modify-syntax-entry ?_ "_" tab) |
362 (modify-syntax-entry ?- "_" tab) | 386 (modify-syntax-entry ?- "_" tab) |
363 (modify-syntax-entry ?< "(>" tab) | 387 (modify-syntax-entry ?< "(>" tab) |
364 (modify-syntax-entry ?> ")<" tab) | 388 (modify-syntax-entry ?> ")<" tab) |
365 ;; I hate this more than you can possibly imagine. | |
366 ;; Do this if you want to have aliases with hyphens in them. This causes | |
367 ;; hyphens to be considered word-syntax, so forward-word will not stop at | |
368 ;; hyphens. | |
369 (modify-syntax-entry ?- "w" tab) | |
370 tab) | 389 tab) |
371 "The syntax table used in send-mail mode when in a mail-address header. | 390 "The syntax table used in send-mail mode when in a mail-address header. |
372 mail-mode-syntax-table is used when the cursor is in the message body or in | 391 mail-mode-syntax-table is used when the cursor is in the message body or in |
373 non-address headers.") | 392 non-address headers.") |
374 | 393 |
408 nil 0) | 427 nil 0) |
409 (point)))))) | 428 (point)))))) |
410 | 429 |
411 (defvar mail-mode-abbrev-table) ; quiet the compiler | 430 (defvar mail-mode-abbrev-table) ; quiet the compiler |
412 | 431 |
413 ;; If INSERT is non-nil, self-insert it instead of doing expand-abbrev. | 432 (defun sendmail-pre-abbrev-expand-hook () |
414 (defun sendmail-pre-abbrev-expand-hook (&optional insert) | |
415 (if mail-abbrev-aliases-need-to-be-resolved | 433 (if mail-abbrev-aliases-need-to-be-resolved |
416 (mail-resolve-all-aliases)) | 434 (mail-resolve-all-aliases)) |
417 (let ((in-header (mail-abbrev-in-expansion-header-p))) | 435 (if (and mail-aliases (not (eq mail-aliases t))) |
418 (if in-header | 436 (if (not (mail-abbrev-in-expansion-header-p)) |
437 ;; | |
438 ;; If we're not in a mail header in which mail aliases should | |
439 ;; be expanded, then use the normal mail-mode abbrev table (if any) | |
440 ;; and the normal mail-mode syntax table. | |
441 ;; | |
419 (progn | 442 (progn |
420 (if (or (null mail-aliases) (eq mail-aliases t)) | 443 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table) |
421 (if insert | 444 mail-mode-abbrev-table)) |
422 (self-insert-command insert)) | 445 (set-syntax-table mail-mode-syntax-table)) |
423 ;; | 446 ;; |
424 ;; We are in a To: (or CC:, or whatever) header, and | 447 ;; Otherwise, we are in a To: (or CC:, or whatever) header, and |
425 ;; should use word-abbrevs to expand mail aliases. | 448 ;; should use word-abbrevs to expand mail aliases. |
426 ;; - First, install mail-aliases as the word-abbrev table. | 449 ;; - First, install the mail-aliases as the word-abbrev table. |
427 ;; - Then install the mail-abbrev-syntax-table, which | 450 ;; - Then install the mail-abbrev-syntax-table, which temporarily |
428 ;; temporarily marks all of the | 451 ;; marks all of the non-alphanumeric-atom-characters (the "_" |
429 ;; non-alphanumeric-atom-characters (the "_" syntax | 452 ;; syntax ones) as being normal word-syntax. We do this because |
430 ;; ones) as being normal word-syntax. We do this | 453 ;; the C code for expand-abbrev only works on words, and we want |
431 ;; because the C code for expand-abbrev only works on | 454 ;; these characters to be considered words for the purpose of |
432 ;; words, and we want these characters to be considered | 455 ;; abbrev expansion. |
433 ;; words for the purpose of abbrev expansion. | 456 ;; - Then we call expand-abbrev again, recursively, to do the abbrev |
434 ;; - Then we call expand-abbrev again, recursively, to do | 457 ;; expansion with the above syntax table. |
435 ;; the abbrev expansion with the above syntax table. | 458 ;; - Then we do a trick which tells the expand-abbrev frame which |
436 ;; - Then we do a trick which tells the expand-abbrev | 459 ;; invoked us to not continue (and thus not expand twice.) |
437 ;; frame which invoked us to not continue (and thus not | 460 ;; - Then we set the syntax table to mail-mode-header-syntax-table, |
438 ;; expand twice.) | 461 ;; which doesn't have anything to do with abbrev expansion, but |
439 ;; - Then we set the syntax table to | 462 ;; is just for the user's convenience (see its doc string.) |
440 ;; mail-mode-header-syntax-table, which doesn't have | 463 ;; |
441 ;; anything to do with abbrev expansion, but is just for | 464 (setq local-abbrev-table mail-aliases) |
442 ;; the user's convenience (see its doc string.) | 465 ;; If the character just typed was non-alpha-symbol-syntax, then don't |
443 ;; | 466 ;; expand the abbrev now (that is, don't expand when the user types -.) |
444 (setq local-abbrev-table mail-aliases) | 467 (or (= (char-syntax last-command-char) ?_) |
468 (let ((pre-abbrev-expand-hook nil)) ; that's us; don't loop | |
445 (set-syntax-table mail-abbrev-syntax-table) | 469 (set-syntax-table mail-abbrev-syntax-table) |
446 (if insert | 470 (expand-abbrev))) |
447 (self-insert-command insert) | 471 (setq abbrev-start-location (point) ; this is the trick |
448 ;; If the character just typed was non-alpha-symbol-syntax, | 472 abbrev-start-location-buffer (current-buffer)) |
449 ;; then don't expand the abbrev now (that is, don't expand when | 473 ;; and do this just because. |
450 ;; the user types -.) | 474 (set-syntax-table mail-mode-header-syntax-table) |
451 (or (= (char-syntax last-command-char) ?_) | 475 ))) |
452 (let ((pre-abbrev-expand-hook nil)) ; that's us; don't loop | |
453 (expand-abbrev))) | |
454 (setq abbrev-start-location (point) ; this is the trick | |
455 abbrev-start-location-buffer (current-buffer)))) | |
456 ;; and do this just because. | |
457 (set-syntax-table mail-mode-header-syntax-table)) | |
458 ;; | |
459 ;; If we're not in a mail header in which mail aliases should | |
460 ;; be expanded, then use the normal mail-mode abbrev table (if any) | |
461 ;; and the normal mail-mode syntax table. | |
462 ;; | |
463 (setq local-abbrev-table (and (boundp 'mail-mode-abbrev-table) | |
464 mail-mode-abbrev-table)) | |
465 (set-syntax-table mail-mode-syntax-table) | |
466 (if insert | |
467 (self-insert-command insert))))) | |
468 | 476 |
469 ;;; utilities | 477 ;;; utilities |
470 | 478 |
471 (defun merge-mail-aliases (file) | 479 (defun merge-mail-aliases (file) |
472 "Merge mail aliases from the given file with existing ones." | 480 "Merge mail aliases from the given file with existing ones." |
503 | 511 |
504 (defun abbrev-hacking-next-line (&optional arg) | 512 (defun abbrev-hacking-next-line (&optional arg) |
505 "Just like `next-line' (\\[next-line]) but expands abbrevs when at \ | 513 "Just like `next-line' (\\[next-line]) but expands abbrevs when at \ |
506 end of line." | 514 end of line." |
507 (interactive "p") | 515 (interactive "p") |
508 (if (looking-at "[ \t]*\n") (expand-abbrev)) | 516 (if (looking-at "[ \t]*\n") (sendmail-pre-abbrev-expand-hook)) |
509 (next-line arg)) | 517 (next-line arg)) |
510 | 518 |
511 (defun abbrev-hacking-end-of-buffer (&optional arg) | 519 (defun abbrev-hacking-end-of-buffer (&optional arg) |
512 "Just like `end-of-buffer' (\\[end-of-buffer]) but expands abbrevs when at \ | 520 "Just like `end-of-buffer' (\\[end-of-buffer]) but expands abbrevs when at \ |
513 end of line." | 521 end of line." |
514 (interactive "P") | 522 (interactive "P") |
515 (if (looking-at "[ \t]*\n") (expand-abbrev)) | 523 (if (looking-at "[ \t]*\n") (sendmail-pre-abbrev-expand-hook)) |
516 (end-of-buffer arg)) | 524 (end-of-buffer arg)) |
517 | 525 |
518 (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias) | 526 (define-key mail-mode-map "\C-c\C-a" 'mail-interactive-insert-alias) |
519 | 527 |
520 ;;(define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line) | 528 ;;(define-key mail-mode-map "\C-n" 'abbrev-hacking-next-line) |
521 ;;(define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer) | 529 ;;(define-key mail-mode-map "\M->" 'abbrev-hacking-end-of-buffer) |
522 | 530 |
523 | |
524 ;;; Patching it in: | |
525 ;;; Remove the entire file mailalias.el | |
526 ;;; Remove the definition of mail-aliases from sendmail.el | |
527 ;;; Add a call to mail-aliases-setup to mail-setup in sendmail.el | |
528 ;;; Remove the call to expand-mail-aliases from sendmail-send-it in sendmail.el | |
529 ;;; Remove the autoload of expand-mail-aliases from sendmail.el | |
530 ;;; Remove the autoload of build-mail-aliases from sendmail.el | |
531 ;;; Add an autoload of define-mail-alias | |
532 | |
533 (provide 'mail-abbrevs) | 531 (provide 'mail-abbrevs) |
534 | 532 |
535 | 533 |
536 ;;; V18 compatibility | 534 ;;; V18 compatibility |
537 ;;; these defuns and defvars aren't inside the cond in deference to the | 535 ;;; |
538 ;;; intense brokenness of the v18 byte-compiler. | 536 ;;; All of the Emacs18 stuff is isolated down here so that it will be |
537 ;;; easy to delete once v18 finally bites the dust. | |
538 ;;; | |
539 ;;; These defuns and defvars aren't inside the cond in deference to | |
540 ;;; the intense brokenness of the v18 byte-compiler. | |
539 | 541 |
540 (defun sendmail-v18-self-insert-command (arg) | 542 (defun sendmail-v18-self-insert-command (arg) |
541 "Just like self-insert-command, but runs sendmail-pre-abbrev-expand-hook." | 543 "Just like self-insert-command, but runs sendmail-pre-abbrev-expand-hook." |
542 (interactive "p") | 544 (interactive "p") |
543 (sendmail-pre-abbrev-expand-hook arg)) | 545 (if (not (= (char-syntax last-command-char) ?w)) |
546 (progn | |
547 (sendmail-pre-abbrev-expand-hook) | |
548 ;; Unhack expand-abbrev, so it will work right next time around. | |
549 (setq abbrev-start-location nil))) | |
550 (let ((abbrev-mode nil)) | |
551 (self-insert-command arg))) | |
544 | 552 |
545 (defvar mail-abbrevs-v18-map-munged nil) | 553 (defvar mail-abbrevs-v18-map-munged nil) |
546 | 554 |
547 (defun mail-abbrevs-v18-munge-map () | 555 (defun mail-abbrevs-v18-munge-map () |
548 ;; If mail-mode-map is a sparse-keymap, convert it to a non-sparse one. | 556 ;; For every key that is bound to self-insert-command in global-map, |
549 ;; If a given key would be bound to self-insert-command in mail-mode (that | 557 ;; bind that key to sendmail-self-insert-command in mail-mode-map. |
550 ;; is, it is bound to it in mail-mode-map or in global-map) then bind it | 558 ;; We used to do this by making the mail-mode-map be a non-sparse map, |
551 ;; to sendmail-self-insert-command in mail-mode-map. | 559 ;; but that made the esc-map be shared in such a way that making a |
552 (let* ((sparse-p (consp mail-mode-map)) | 560 ;; local meta binding in the mail-mode-map made a *global* binding |
553 (map (make-keymap)) | 561 ;; instead. Yucko. |
554 (L (length map)) | 562 (let ((global-map (current-global-map)) |
555 (i 0)) | 563 (i 0)) |
556 (while (< i L) | 564 (while (< i 128) |
557 (let ((old (or (if sparse-p | 565 (if (eq 'self-insert-command (or (cdr (assq i mail-mode-map)) |
558 (cdr (assq i mail-mode-map)) | 566 (aref global-map i))) |
559 (aref mail-mode-map i)) | 567 (define-key mail-mode-map (char-to-string i) |
560 (aref global-map i)))) | 568 'sendmail-v18-self-insert-command)) |
561 (aset map i (if (eq old 'self-insert-command) | 569 (setq i (1+ i)))) |
562 'sendmail-v18-self-insert-command | |
563 old))) | |
564 (setq i (1+ i))) | |
565 (setq mail-mode-map map)) | |
566 (setq mail-abbrevs-v18-map-munged t)) | 570 (setq mail-abbrevs-v18-map-munged t)) |
567 | 571 |
568 (defun mail-aliases-v18-setup () | 572 (defun mail-aliases-setup-v18 () |
569 "Put this on `mail-setup-hook' to use mail-abbrevs." | 573 "Put this on `mail-setup-hook' to use mail-abbrevs." |
570 (if (and (not (vectorp mail-aliases)) | 574 (if (and (not (vectorp mail-aliases)) |
571 (file-exists-p (mail-abbrev-mailrc-file))) | 575 (file-exists-p (mail-abbrev-mailrc-file))) |
572 (build-mail-aliases)) | 576 (build-mail-aliases)) |
573 (or mail-abbrevs-v18-map-munged (mail-abbrevs-v18-munge-map)) | 577 (or mail-abbrevs-v18-map-munged (mail-abbrevs-v18-munge-map)) |
574 (use-local-map mail-mode-map) | 578 (use-local-map mail-mode-map) |
575 (abbrev-mode 1)) | 579 (abbrev-mode 1)) |
576 | 580 |
577 | 581 |
578 (defun mail-abbrev-expand-hook-v18 () | |
579 (let ((auto-fill-function auto-fill-hook)) ; new name | |
580 (mail-abbrev-expand-hook-v19))) | |
581 | |
582 | |
583 (cond ((or (string-match "^18\\." emacs-version) | 582 (cond ((or (string-match "^18\\." emacs-version) |
584 (and (boundp 'epoch::version) epoch::version)) | 583 (and (boundp 'epoch::version) epoch::version)) |
584 ;; | |
585 ;; v19 (and this code) uses a new name for this function. | |
585 (or (fboundp 'buffer-disable-undo) | 586 (or (fboundp 'buffer-disable-undo) |
586 (fset 'buffer-disable-undo 'buffer-flush-undo)) | 587 (fset 'buffer-disable-undo 'buffer-flush-undo)) |
588 ;; | |
589 ;; v19 (and this code) uses a new name for auto-fill-hook (-function). | |
590 ;; Encapsulate the function that uses it to bind the new name. | |
587 (or (fboundp 'mail-abbrev-expand-hook-v19) | 591 (or (fboundp 'mail-abbrev-expand-hook-v19) |
588 (fset 'mail-abbrev-expand-hook-v19 | 592 (fset 'mail-abbrev-expand-hook-v19 |
589 (symbol-function 'mail-abbrev-expand-hook))) | 593 (symbol-function 'mail-abbrev-expand-hook))) |
590 (fset 'mail-abbrev-expand-hook 'mail-abbrev-expand-hook-v18) | 594 (fset 'mail-abbrev-expand-hook |
595 (function (lambda () | |
596 (let ((auto-fill-function auto-fill-hook)) | |
597 (mail-abbrev-expand-hook-v19))))) | |
598 ;; | |
599 ;; Turn off the broken v18 code (that is still called from sendmail.el) | |
591 (fset 'expand-mail-aliases | 600 (fset 'expand-mail-aliases |
592 '(lambda (&rest args) "Obsoleted by mail-abbrevs. Does nothing." | 601 (function (lambda (&rest args) |
593 nil)) | 602 "Obsoleted by mail-abbrevs. Does nothing." |
603 nil))) | |
604 ;; | |
605 ;; Encapsulate mail-setup to do the necessary buffer initializations. | |
606 (or (fboundp 'mail-setup-v18) | |
607 (fset 'mail-setup-v18 (symbol-function 'mail-setup))) | |
608 (fset 'mail-setup | |
609 (function (lambda (&rest args) | |
610 (mail-aliases-setup-v18) | |
611 (apply 'mail-setup-v18 args)))) | |
594 ) | 612 ) |
613 | |
595 (t ; v19 | 614 (t ; v19 |
596 (fmakunbound 'expand-mail-aliases))) | 615 (fmakunbound 'expand-mail-aliases))) |