Mercurial > emacs
comparison lisp/mail/mail-extr.el @ 37148:aca2b7839d21
(mail-extr-delete-char, mail-extr-safe-move-sexp)
(mail-extr-skip-whitespace-forward, mail-extr-nuke-char-at)
(mail-extr-skip-whitespace-backward, mail-extr-undo-backslash-quoting):
Use `defsubst' rather than a macro to ease debugging.
(mail-extr-last): Remove (use `last' instead).
(mail-extract-address-components): Properly reset the syntax-table
after parsing an address. Use `last' rather than mail-extr-last.
Make sure the end marker stays at the very end.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Mon, 02 Apr 2001 22:49:38 +0000 |
parents | f597d85734d7 |
children | 413a99578997 |
comparison
equal
deleted
inserted
replaced
37147:4ba3b922976f | 37148:aca2b7839d21 |
---|---|
616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 616 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
617 ;; | 617 ;; |
618 ;; Utility functions and macros. | 618 ;; Utility functions and macros. |
619 ;; | 619 ;; |
620 | 620 |
621 (defmacro mail-extr-delete-char (n) | 621 (defsubst mail-extr-delete-char (n) |
622 ;; in v19, delete-char is compiled as a function call, but delete-region | 622 ;; in v19, delete-char is compiled as a function call, but delete-region |
623 ;; is byte-coded, so it's much much faster. | 623 ;; is byte-coded, so it's much much faster. |
624 (list 'delete-region '(point) (list '+ '(point) n))) | 624 (delete-region (point) (+ (point) n))) |
625 | 625 |
626 (defmacro mail-extr-skip-whitespace-forward () | 626 (defsubst mail-extr-skip-whitespace-forward () |
627 ;; v19 fn skip-syntax-forward is more tasteful, but not byte-coded. | 627 ;; v19 fn skip-syntax-forward is more tasteful, but not byte-coded. |
628 '(skip-chars-forward " \t\n\r\240")) | 628 (skip-chars-forward " \t\n\r\240")) |
629 | 629 |
630 (defmacro mail-extr-skip-whitespace-backward () | 630 (defsubst mail-extr-skip-whitespace-backward () |
631 ;; v19 fn skip-syntax-backward is more tasteful, but not byte-coded. | 631 ;; v19 fn skip-syntax-backward is more tasteful, but not byte-coded. |
632 '(skip-chars-backward " \t\n\r\240")) | 632 (skip-chars-backward " \t\n\r\240")) |
633 | 633 |
634 | 634 |
635 (defmacro mail-extr-undo-backslash-quoting (beg end) | 635 (defsubst mail-extr-undo-backslash-quoting (beg end) |
636 (`(save-excursion | 636 (save-excursion |
637 (save-restriction | 637 (save-restriction |
638 (narrow-to-region (, beg) (, end)) | 638 (narrow-to-region beg end) |
639 (goto-char (point-min)) | 639 (goto-char (point-min)) |
640 ;; undo \ quoting | 640 ;; undo \ quoting |
641 (while (search-forward "\\" nil t) | 641 (while (search-forward "\\" nil t) |
642 (mail-extr-delete-char -1) | 642 (mail-extr-delete-char -1) |
643 (or (eobp) | 643 (or (eobp) |
644 (forward-char 1)) | 644 (forward-char 1)))))) |
645 ))))) | 645 |
646 | 646 (defsubst mail-extr-nuke-char-at (pos) |
647 (defmacro mail-extr-nuke-char-at (pos) | 647 (save-excursion |
648 (` (save-excursion | 648 (goto-char pos) |
649 (goto-char (, pos)) | 649 (mail-extr-delete-char 1) |
650 (mail-extr-delete-char 1) | 650 (insert ?\ ))) |
651 (insert ?\ )))) | |
652 | 651 |
653 (put 'mail-extr-nuke-outside-range | 652 (put 'mail-extr-nuke-outside-range |
654 'edebug-form-spec '(symbolp &optional form form atom)) | 653 'edebug-form-spec '(symbolp &optional form form atom)) |
655 | 654 |
656 (defmacro mail-extr-nuke-outside-range (list-symbol | 655 (defmacro mail-extr-nuke-outside-range (list-symbol |
691 ;; coerces pos to a marker if non-nil. | 690 ;; coerces pos to a marker if non-nil. |
692 (if (or (markerp pos) (null pos)) | 691 (if (or (markerp pos) (null pos)) |
693 pos | 692 pos |
694 (copy-marker pos))) | 693 (copy-marker pos))) |
695 | 694 |
696 (defmacro mail-extr-last (list) | 695 (defsubst mail-extr-safe-move-sexp (arg) |
697 ;; Returns last element of LIST. | |
698 ;; Could be a subst. | |
699 (` (let ((list (, list))) | |
700 (while (not (null (cdr list))) | |
701 (setq list (cdr list))) | |
702 (car list)))) | |
703 | |
704 (defmacro mail-extr-safe-move-sexp (arg) | |
705 ;; Safely skip over one balanced sexp, if there is one. Return t if success. | 696 ;; Safely skip over one balanced sexp, if there is one. Return t if success. |
706 (` (condition-case error | 697 (condition-case error |
707 (progn | 698 (progn |
708 (goto-char (or (scan-sexps (point) (, arg)) (point))) | 699 (goto-char (or (scan-sexps (point) arg) (point))) |
709 t) | 700 t) |
710 (error | 701 (error |
711 ;; #### kludge kludge kludge kludge kludge kludge kludge !!! | 702 ;; #### kludge kludge kludge kludge kludge kludge kludge !!! |
712 (if (string-equal (nth 1 error) "Unbalanced parentheses") | 703 (if (string-equal (nth 1 error) "Unbalanced parentheses") |
713 nil | 704 nil |
714 (while t | 705 (while t |
715 (signal (car error) (cdr error)))))))) | 706 (signal (car error) (cdr error))))))) |
716 | 707 |
717 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | 708 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
718 ;; | 709 ;; |
719 ;; The main function to grind addresses | 710 ;; The main function to grind addresses |
720 ;; | 711 ;; |
733 or more recipients, separated by commas, and we return a list of | 724 or more recipients, separated by commas, and we return a list of |
734 the form ((FULL-NAME CANONICAL-ADDRESS) ...) with one element for | 725 the form ((FULL-NAME CANONICAL-ADDRESS) ...) with one element for |
735 each recipient. If ALL is nil, then if ADDRESS contains more than | 726 each recipient. If ALL is nil, then if ADDRESS contains more than |
736 one recipients, all but the first is ignored. | 727 one recipients, all but the first is ignored. |
737 | 728 |
738 ADDRESS may be a string or a buffer. If it is a buffer, the visible | 729 ADDRESS may be a string or a buffer. If it is a buffer, the visible |
739 (narrowed) portion of the buffer will be interpreted as the address. | 730 (narrowed) portion of the buffer will be interpreted as the address. |
740 (This feature exists so that the clever caller might be able to avoid | 731 (This feature exists so that the clever caller might be able to avoid |
741 consing a string.)" | 732 consing a string.)" |
742 (let ((canonicalization-buffer (get-buffer-create " *canonical address*")) | 733 (let ((canonicalization-buffer (get-buffer-create " *canonical address*")) |
743 (extraction-buffer (get-buffer-create " *extract address components*")) | 734 (extraction-buffer (get-buffer-create " *extract address components*")) |
744 value-list) | 735 value-list) |
745 | 736 |
746 (save-excursion | 737 (with-current-buffer (get-buffer-create extraction-buffer) |
747 (set-buffer extraction-buffer) | |
748 (fundamental-mode) | 738 (fundamental-mode) |
749 (buffer-disable-undo extraction-buffer) | 739 (buffer-disable-undo extraction-buffer) |
750 (set-syntax-table mail-extr-address-syntax-table) | 740 (set-syntax-table mail-extr-address-syntax-table) |
751 (widen) | 741 (widen) |
752 (erase-buffer) | 742 (erase-buffer) |
764 (t | 754 (t |
765 (error "Invalid address: %s" address))) | 755 (error "Invalid address: %s" address))) |
766 | 756 |
767 (set-text-properties (point-min) (point-max) nil) | 757 (set-text-properties (point-min) (point-max) nil) |
768 | 758 |
769 (save-excursion | 759 (with-current-buffer (get-buffer-create canonicalization-buffer) |
770 (set-buffer canonicalization-buffer) | |
771 (fundamental-mode) | 760 (fundamental-mode) |
772 (buffer-disable-undo canonicalization-buffer) | 761 (buffer-disable-undo canonicalization-buffer) |
773 (set-syntax-table mail-extr-address-syntax-table) | |
774 (setq case-fold-search nil)) | 762 (setq case-fold-search nil)) |
775 | 763 |
776 | 764 |
777 ;; Unfold multiple lines. | 765 ;; Unfold multiple lines. |
778 (goto-char (point-min)) | 766 (goto-char (point-min)) |
802 saved-%-pos saved-!-pos saved-@-pos | 790 saved-%-pos saved-!-pos saved-@-pos |
803 domain-pos \.-pos insert-point | 791 domain-pos \.-pos insert-point |
804 ;; mailbox-name-processed-flag | 792 ;; mailbox-name-processed-flag |
805 disable-initial-guessing-flag) ; dynamically set from -voodoo | 793 disable-initial-guessing-flag) ; dynamically set from -voodoo |
806 | 794 |
795 (set-syntax-table mail-extr-address-syntax-table) | |
807 (goto-char (point-min)) | 796 (goto-char (point-min)) |
808 | 797 |
809 ;; Insert extra space at beginning to allow later replacement with < | 798 ;; Insert extra space at beginning to allow later replacement with < |
810 ;; without having to move markers. | 799 ;; without having to move markers. |
811 (or (eq (following-char) ?\ ) | 800 (or (eq (following-char) ?\ ) |
866 (and >-pos | 855 (and >-pos |
867 ;; handle weird munged addresses | 856 ;; handle weird munged addresses |
868 ;; BUG FIX: This test was reversed. Thanks to the | 857 ;; BUG FIX: This test was reversed. Thanks to the |
869 ;; brilliant Rod Whitby <rwhitby@research.canon.oz.au> | 858 ;; brilliant Rod Whitby <rwhitby@research.canon.oz.au> |
870 ;; for discovering this! | 859 ;; for discovering this! |
871 (< (mail-extr-last <-pos) (car >-pos))))) | 860 (< (car (last <-pos)) (car >-pos))))) |
872 ;; The argument contains more than one address. | 861 ;; The argument contains more than one address. |
873 ;; Temporarily hide everything after this one. | 862 ;; Temporarily hide everything after this one. |
874 (setq end-of-address (copy-marker (1+ (point)))) | 863 (setq end-of-address (copy-marker (1+ (point)) t)) |
875 (narrow-to-region (point-min) (1+ (point))) | 864 (narrow-to-region (point-min) (1+ (point))) |
876 (mail-extr-delete-char 1) | 865 (delete-char 1) |
877 (setq char ?\() ; HAVE I NO SHAME?? | 866 (setq char ?\() ; HAVE I NO SHAME?? |
878 ) | 867 ) |
879 ;; record the position of various interesting chars, determine | 868 ;; record the position of various interesting chars, determine |
880 ;; legality later. | 869 ;; legality later. |
881 ((setq record-pos-symbol | 870 ((setq record-pos-symbol |
1143 (insert "%") | 1132 (insert "%") |
1144 (setq insert-point (point-max))) | 1133 (setq insert-point (point-max))) |
1145 (mail-extr-@-binds-tighter-than-! | 1134 (mail-extr-@-binds-tighter-than-! |
1146 (setq insert-point (point-max))) | 1135 (setq insert-point (point-max))) |
1147 (%-pos | 1136 (%-pos |
1148 (setq insert-point (mail-extr-last %-pos) | 1137 (setq insert-point (car (last %-pos)) |
1149 saved-%-pos (mapcar 'mail-extr-markerize %-pos) | 1138 saved-%-pos (mapcar 'mail-extr-markerize %-pos) |
1150 %-pos nil | 1139 %-pos nil |
1151 @-pos (mail-extr-markerize @-pos))) | 1140 @-pos (mail-extr-markerize @-pos))) |
1152 (@-pos | 1141 (@-pos |
1153 (setq insert-point @-pos) | 1142 (setq insert-point @-pos) |