-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost.el
1439 lines (1274 loc) · 50.5 KB
/
post.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
; $Id: post.el,v 1.10 2008/02/24 23:49:23 rreid Exp $
;; post.el --- Use (X?)Emacs(client) as an external editor for mail and news.
;;; Authors: Eric Kidd <[email protected]>,
;;; Dave Pearson <[email protected]>,
;;; Rob Reid <[email protected]>,
;;; Roland Rosenfeld <[email protected]>
;; This is free software distributed under the GPL, yadda, yadda, yadda.
;; It has no warranty. See the GNU General Public License for more
;; information. Send us your feature requests and patches, and we'll try
;; to integrate everything.
;;; Maintainers: Rob Reid <[email protected]> and
;;; Philip J. Hollenback <[email protected]>
;;; Keywords: mail
;;; Commentary:
;; This is a major mode for use with mutt (http://www.mutt.org/), slrn, or most
;; email and newsreaders that allow you to use an external editor.
;;
;; Installation:
;;
;; Add the following line to the .emacs(.el) file in your home directory:
;;
;; (load "/your/local/path/to/this/file/post")
;;
;; Note that you can omit the ".el" from the file name when calling load.
;;
;; If you want to make it available to all your users, type \C-h v
;; load-path RET, pick an appropriate directory for post.el, and modify
;; your sitewide default.el to (require 'post).
;;
;; You may find the latest version of this mode at
;; http://www.cv.nrao.edu/~rreid/software/email/ or possibly
;; http://sourceforge.net/projects/post-mode/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; BUGS:
;;
;; Rob: I predict that some buffers (*Original*<2>, *Composing*<2>?)
;; will be left behind if you edit more than one message at a time.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Thanks
;;;
;;; Dave Pearson: Code, feature ideas, Mutt experience. Many thanks!
;;; Louis Theran: Encouragement to make Mutt mode work like Emacs MUAs.
;;; Ronald: Enlightening gripes about what Emacs should do, but doesn't.
;;; Robert Napier: Bug reports about font-lock mode, fancy wrapping.
;;; Kevin Rodgers: Answered RR's question on gnu.emacs.help on
;;; overwriting server-process-filter's annoying message at startup.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Revision History
;;;
;;; $Log: post.el,v $
;;; Revision 1.10 2008/02/24 23:49:23 rreid
;;; *** empty log message ***
;;;
;;; Revision 1.9 2008/02/24 23:46:23 rreid
;;; I really hate the way RCS/VC mucks around with the version number and log.
;;; It's not as dwim as it thinks it is.
;;;
;;; Revision 1.8 2008/02/24 23:43:46 rreid
;;; Updated email address.
;;;
;;; Revision 2.402 2008/02/24 23:31:19 rreid
;;; Emacs 22 finally fixed (how-many) to return an int instead of a string,
;;; i.e. 13 instead of '13 occurrences'. A few people noticed that the change
;;; broke my workaround, but Erik Mugele submitted the winning patch that works
;;; for all emacs versions (I hope).
;;;
;;; This, and the below, are real entries, with real version numbers. Some of
;;; the above are fake commits to get the version number back in sync.
;;;
;;; Revision 2.401 2004/07/23 16:27:29 rreid
;;; Fixed post-delete-quoted-signatures to not remove sneaky things like quoted
;;; double dash arrows. Thanks go to Felix Klee for a clear bug report.
;;;
;;; Revision 2.4 2002/04/22 22:04:29 reid
;;; Tweaked post-emoticon-pattern yet again. Made cl mandatory for all
;;; versions of emacs. (Thanks to Eric Dorland and Mike Schiraldi for bug
;;; reports.) Fixed post-unquote-region. (Thanks to Mike Schiraldi for the
;;; bug report.)
;;;
;;; Revision 2.3 2002/04/21 20:13:55 reid
;;; Improved post-emoticon-pattern.
;;;
;;; Revision 2.2 2002/04/20 04:12:54 reid
;;; Improved post-emoticon-pattern.
;;;
;;; Revision 2.1 2002/04/20 03:17:48 reid
;;; - A major (but not total) synchronization with Dave Pearson's post-mode.
;;; header-set-followup-to and header-set-organization should work now.
;;; - Syntax highlighting now works for quoted email addresses and URLs.
;;; - *bold* words are now highlighted.
;;; - Emoticons can now be highlighted, and the default regexp,
;;; post-emoticon-pattern, might be too enthusiastic for your taste. In case
;;; you're curious, I verified that gnus' smiley-ems.el works with post, but I
;;; decided that it wasn't ideal.
;;; - post-url-text-pattern changed to post-url-pattern and made more enthusiastic.
;;;
;;; revision 1.95 2002/04/10 00:06:26 reid
;;; Fixed the regexp in post-kill-signature to not delete everything between
;;; mutt's standard forwarding lines. post-kill-signature is called indirectly
;;; by many functions.
;;;
;;; Revision 1.9 2002/04/04 22:24:31 reid
;;; Applied a patch (not quite verbatim) from The Anarcat
;;; <[email protected]> to make the entity separating siglets in
;;; `post-variable-signature-source' a regexp, `post-signature-sep-regexp'. The
;;; default works either either the old post file format or strfiled (fortune)
;;; files.
;;;;
;;; Changed default `post-random-signature-command' to `fortune
;;; ~/.mutt/sigs.fortune'.
;;;
;;; `post-random-signature-command' should now NOT supply a fixed sig portion!
;;;
;;; (post-el-random-signature) supplied by The Anarcat to do random sig
;;; selection purely within Emacs Lisp.
;;;
;;; Revision 1.8 2002/02/06 22:24:31 eric
;;; clean up
;;;
;;; Revision 1.7.2 2002/02/06 22:17:01 eric
;;; tweak regexps, make font-lock-comment-face be post-signature-text-face
;;;
;;; Revision 1.7.1 2002/02/06 21:58:58 eric
;;; tweak regexp, change some types to regexp
;;;
;;; Revision 1.7.0 2002/02/06 21:36:56 eric
;;; hilight signatures, urls and emails
;;;
;;; Revision 1.6.3.10 1999/10/11 00:29:41 roland
;;; Corrected color quoting again: Now allows ">" in the middle of
;;; a line which is quoted twice.
;;;
;;; Revision 1.6.3.9 1999/10/08 10:43:18 roland
;;; Add third level of quoting faces.
;;; Allow super-cite name prefixes before quote signs.
;;;
;;; Revision 1.6.3.8 1999/10/08 08:39:00 roland
;;; post-font-lock-keywords now detects lines with only "> "in it
;;; correctly (merged following line into it before).
;;;
;;; Revision 1.6.3.7 1999/10/04 10:07:48 roland
;;; Add post-quote-region and post-unquote-region commands to quote and
;;; unquote a region (one level).
;;;
;;; Revision 1.6.3.6 1999/09/03 23:13:55 reid
;;; Valeriy E. Ushakov <[email protected]> pointed out that (GNU) Emacs <20 has
;;; fewer (optional) arguments to (read-string) than what I was using to
;;; inherit the input method. I didn't find a way off the top of my head
;;; to redefine (read-string) without causing an infinite loop, so I have
;;; substituted a macro (string-read prompt) which does the right thing,
;;; so please use it instead of read-string.
;;;
;;; Revision 1.6.3.5 1999/08/29 19:58:49 reid
;;; Changed default post-mail-message to handle hostnames with digits.
;;; Thanks to Brian D. Winters <[email protected]>.
;;;
;;; Revision 1.6.3.4 1999/03/20 03:02:05 reid
;;; Made post compatible with emacs as far back as 19.28.1, probably
;;; farther.
;;;
;;; Revision 1.6.3.3 1999/03/16 03:14:07 reid
;;; Cleaned up post-select-signature-select-sig-from-file code.
;;;
;;; Revision 1.6.3.2 1999/03/16 03:05:12 reid
;;; Fixed alist updating.
;;;
;;; Revision 1.6.3.1 1999/03/13 02:23:48 reid
;;; Added defface to the list of things that get defined if customize
;;; hasn't already done it. Thanks to Melissa Binde for the bug report.
;;;
;;; Modified post-body-says-attach to use a regexp,
;;; post-attachment-regexp, so that something like "\(attach\|anbringen\)"
;;; can be used by bilingual people like Roland.
;;;
;;; Revision 1.6.2.1 1999/03/12 10:16:11 roland
;;; Added missing () to post-insert-to-auto-mode-alist-on-load.
;;;
;;; Revision 1.6.2 1999/03/11 15:51 Dave Pearson
;;; header-position-on-value fixed to return (point), and
;;; defcustom macro provided for Emacs 19 users.
;;;
;;; Revision 1.6.1.2 1999/03/06 11:24:43 roland
;;; Added post-insert-to-auto-mode-alist-on-load.
;;;
;;; Revision 1.6.1.1 1999/03/06 11:02:27 roland
;;; Customized renaming of buffer.
;;; Removed different handling for mail, news, news-reply.
;;; Fixed problems with easy-menu under XEmacs.
;;;
;;; Revision 1.6.0 1999/03/04 18:04 Rob Reid
;;; Returned post-signature-pattern to using "--" instead of "-- "
;;; because some senders have broken MTAs (as Eric reminded me) and
;;; some users don't use procmail to compensate. This time all of the
;;; functions dealing with signatures have been smartened up to avoid
;;; false matches. Unfortunately that means they don't use
;;; post-signature-pattern in its raw form.
;;;
;;; Added post-backup-original so that Dave's post-copy-original can
;;; be used.
;;;
;;; Kevin Rodgers explained how to put this in .emacs to fix the
;;; server-process-filter's annoying message problem:
;;;
;;; Revision 1.1 1999/03/04 18:02:30 reid
;;; Initial revision
;;;
;;; %%%%%%%%%%%% Put in .emacs %%%%%%%%%%%
;;;
;;; ;;; Email
;;; (server-start)
;;; (load "/home/reid/.mutt/post")
;;; (defadvice server-process-filter (after post-mode-message first activate)
;;; "If the buffer is in post mode, overwrite the server-edit
;;; message with a post-save-current-buffer-and-exit message."
;;; (if (eq major-mode 'post-mode)
;;; (message
;;; (substitute-command-keys "Type \\[describe-mode] for help composing; \\[post-save-current-buffer-and-exit] when done."))))
;;; ; This is also needed to see the magic message. Set to a higher
;;; ; number if you have a faster computer or read slower than me.
;;; '(font-lock-verbose 1000)
;;; ; (setq server-temp-file-regexp "mutt-")
;;; (add-hook 'server-switch-hook
;;; (function (lambda()
;;; (cond ((string-match "Post" mode-name)
;;; (post-goto-body))))))
;;;
;;; %%%%%%%%% We now return to our regular commentary %%%%%%%%%
;;;
;;; Eric Kidd asked that the name of Headers mode be changed so that
;;; it doesn't conflict with mutt-mode's Headers, so I changed it to
;;; just Header (no s).
;;;
;;; Revision 1.5? 1999/02/27 17:30 Rob Reid
;;; I had a go at combining Dave Pearson's post mode with Eric Kidd's
;;; Mutt mode. Since Dave Pearson's post mode explicitly handles news as
;;; well as email, and this should be useful for more than just mutt,
;;; I'm calling it post mode. I also added functions for picking
;;; random signatures, selecting a signature from a file, and
;;; intelligently (IMHO) prompting the user for an attachment when
;;; necessary. Changed mutt-save-buffer-and-exit to work better with
;;; emacsclient, and some of the key bindings. post-signature-pattern
;;; now defaults to use "-- " instead of "--", and I have far less
;;; trouble this way (I use procmail to clean up braindead "--"s.). I
;;; don't know why Eric warned against trailing whitespace.
;;;
;;; Revision 1.4 1998/04/11 00:05:46 emk
;;; Fixed font-lock bug. Also made mutt-mode a little more careful about
;;; saving various bits of Emacs state when moving around the buffer.
;;;
;;; Revision 1.3 1998/03/25 00:37:36 emk
;;; Added support for menus and font-lock mode, plus a few bug fixes.
;;;
;;; Revision 1.2 1998/03/24 13:19:46 emk
;;; Major overhaul--more commands, a minor mode for header editing, and other
;;; desirable features. Attaching files seems to be broken, though.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Required Packages
(require 'cl)
(require 'derived)
(require 'easymenu)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Customization Support
;;;
;;; Set up our customizable features. You can edit these (and lots of other
;;; fun stuff) by typing M-x customize RET. The Post preferences can be
;;; found under the [Applications] [Mail] category.
;; Make post mode a bit more compatible with older (i.e. <20) versions of emacs.
;;; Code:
(eval-and-compile
;; Dumb down read-string if necessary.
;; The number of optional arguments for read-string seems to increase
;; sharply with (emacs-version). Since old versions of emacs are a large
;; source of bug reports it might be worth writing (or looking for)
;; (bug-report [email protected]) which emails me the result of
;; (emacs-version) along with a user supplied description of the problem.
;; GNU Emacs 19.28.1 only has INITIAL-STRING as an optional argument.
;; 19.34.1 has (read-string PROMPT &optional INITIAL-INPUT HISTORY). 20.2.1
;; has (read-string PROMPT &optional INITIAL-INPUT HISTORY DEFAULT-VALUE
;; INHERIT-INPUT-METHOD).
;; Since I haven't found a way of redefining read-string without causing an
;; infinite loop, please use (string-read prompt).
(if (< (string-to-number (substring (emacs-version)
(string-match "[0-9]+\.[0-9]"
(emacs-version) 5))) 20)
(defmacro string-read (prompt) `(read-string (, prompt)))
(defmacro string-read (prompt)
`(read-string (, prompt) nil nil nil t)))
;; XEmacs gnuserv uses slightly different functions than the GNU Emacs
;; server, and some people are still wasting time and CPU cycles by starting
;; up a new emacs each time.
(fset 'post-finish (cond ((fboundp 'server-edit)
'server-edit)
((fboundp 'gnuserv-kill-buffer-function)
'gnuserv-kill-buffer-function)
(t
'save-buffers-kill-emacs)))
;; (cond ((fboundp 'server-edit)
;; (fset 'post-finish 'server-edit))
;; ((fboundp 'gnuserv-kill-buffer-function)
;; (fset 'post-finish 'gnuserv-kill-buffer-function))
;; (t
;; (fset 'post-finish 'save-buffers-kill-emacs)))
;; If customize isn't available just use defvar instead.
(unless (fboundp 'defgroup)
(defmacro defgroup (&rest rest) nil)
(defmacro defcustom (symbol init docstring &rest rest)
; The "extra" braces and whitespace are for emacs < 19.29.
`(defvar (, symbol) (, init) (, docstring)))
(defmacro defface (&rest args) nil))
(unless (fboundp 'buffer-substring-no-properties)
(fset 'buffer-substring-no-properties 'buffer-substring)))
(defgroup post nil
"Composing e-mail messages with Post.
Emacs can run as an external editor for Mutt, the spiffy Unix mail reader
du jour, or slrn, the spiffy Unix news reader du jour. You can get
Mutt from http://www.mutt.org/."
:group 'mail)
(defcustom post-uses-fill-mode t
"*Specifies whether Post should automatically wrap lines.
Set this to t to enable line wrapping, and nil to disable line
wrapping. Note that if a paragraph gets messed up (the line wrapper
is very primitive), you can type \\[fill-paragraph] to rewrap the paragraph."
:type 'boolean
:group 'post)
(defcustom post-mail-message "mutt-[a-z0-9]+-[0-9]+-[0-9]+.*\\'"
"*Regular expression which matches your mailer's temporary files."
:type 'string
:group 'post)
(defcustom post-news-posting "\\.\\(followup\\|letter\\|article\\)$"
"*Regular expression which matches your news reader's composition files."
:type 'string
:group 'post)
(defcustom post-backup-original nil
"*Controls whether a pristine backup of the original is kept for reference."
:type 'boolean
:group 'post)
(defcustom post-signature-pattern "\\(--\\|Cheers,\\|\\)"
"*Pattern signifying the beginning of signatures.
It should not contain trailing whitespace unless you know what you're doing."
:type 'regexp
:group 'post)
(defcustom post-signature-sep-regexp "^\\(%\\|^L\\|--\\)?\n"
"*Regular expression delimiting signatures in the signature file.
This allows the use of classic fortune files as signature files.
This should normally contain a newline."
:type 'regexp
:group 'post)
(defcustom post-signature-source-is-file t
"*Toggles the signature source type between file and directory."
:type 'boolean
:group 'post)
(defcustom post-variable-signature-source "~/.mutt/sigs.fortune"
"*Location of the variable part of your signature.
Post uses this to locate signatures. It can be either a directory
with one item per file or a file with items separated by blank lines."
:type 'string
:group 'post)
(defcustom post-fixed-signature-source "~/.fixedsig"
"*File with the fixed part of your signature."
:type 'string
:group 'post)
(defcustom post-signature-directory "~/.sigs/"
"*The directory that contains your collection of signature files."
:type 'string
:group 'post)
(defcustom post-signature-wildcard "sig*"
"*Wildcard for finding signature files in your signature directory."
:type 'string
:group 'post)
(defcustom post-random-signature-command "fortune ~/.mutt/sigs.fortune"
"*Command to run to get a random signature.
Examples are available at http://astro.utoronto.ca/~reid/mutt/"
:type 'string
:group 'post)
(defcustom post-kill-quoted-sig t
"Specifies whether `post-mode' should automatically kill quoted signatures."
:type 'boolean
:group 'post)
(defcustom post-jump-header t
"Specifies wheather `post-mode' should jump to the body."
:type 'boolean
:group 'post)
(defcustom post-force-pwd-to-home t
"Specifies whether `post-mode' should cd to your home directory."
:type 'boolean
:group 'post)
(defcustom post-email-address (concat (user-login-name) "@" mail-host-address)
"*Your email address."
:type 'string
:group 'post)
(defcustom post-should-prompt-for-attachment 'Smart
"*Controls whether an attachment will be prompted for before saving
the message and exiting. 'Smart' will prompt only if the body
contains post-attachment-regexp."
:type '(choice (const Never)
(const Smart)
(const Always))
:group 'post)
(defcustom post-attachment-regexp "attach"
"*This is what post looks for in the body if
post-should-prompt-for-attachment is 'Smart'."
:type 'regexp
:group 'post)
(defcustom post-news-poster-regexp "^On .*<.*>.*wrote:$"
"Regular expression used to locate the attribution line of a news posting."
:type 'regexp
:group 'post)
(defcustom post-rename-buffer t
"Specify whether `post-mode' should rename the buffer to *Composing*."
:type 'boolean
:group 'post)
(defcustom post-insert-to-auto-mode-alist-on-load t
"Automatically insert `post-mode' with `post-mail-message' to `auto-mode-alist'."
:type 'boolean
:group 'post)
(defcustom post-mode-hook nil
"List of hooks to be executed on entry to `post-mode'."
:group 'post)
(defcustom post-quote-start "> "
"Pattern which is added (or removed) at the beginning of the line by
comment-region"
:group 'post)
(defcustom post-email-address-pattern
"[A-Za-z0-9_][-A-Za-z0-9._]*@[-A-Za-z0-9._]*[A-Za-z0-9]"
"Pattern to detect email addresses."
:type 'regexp
:group 'post)
(defcustom post-url-pattern
'("\\<\\(\\(https?\\|news\\|mailto\\|ftp\\|gopher\\):\\|\\(www\\|ftp\\)\\.\\)[-~A-Za-z0-9._/%$+?#]+[A-Za-z0-9/#]" "<URL:[^ ]+>")
"Pattern to detect URL addresses."
:type '(repeat regexp)
:group 'post)
(defcustom post-bold-pattern '("\\*\\w+\\*")
"*List of regular expressions that define bold text."
:type '(repeat regexp)
:group 'post)
(defcustom post-underline-pattern '("_\\w+_")
"*List of regular expressions that define underlined text."
:type '(repeat regexp)
:group 'post)
(defcustom post-emoticon-pattern '("[0O(<{}]?[;:8B|][.,]?[-+^*o0O][{<>/\|]?[][)>(<|/\P][)>]?"
"\\s [(<]?[][)>(<|/\][}<>|]?[-+^*oO0][,.]?[:8][0O>]?"
"\\s [;:][][P)\/(]" "\\s [][)(P\/][:;]"
"<[Gg]>" "<[BbSs][Gg]>")
"*List of regular expressions that define a emoticon."
:type '(repeat regexp)
:group 'post)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Customizable Faces
;;; If you find a more attractive color scheme for dark backgrounds, please
;;; email it to [email protected].
(defgroup post-faces nil
"Typefaces used for composing messages with Post."
:group 'post
:group 'faces)
(defface post-header-keyword-face
'((((class color)
(background light))
(:foreground "Navy" :bold t))
(((class color)
(background dark))
(:foreground "LightBlue" :bold t))
(t
(:bold t)))
"Face used for displaying keywords (e.g. \"From:\") in header."
:group 'post-faces)
(defface post-header-value-face
'((((class color)
(background light))
(:foreground "MidnightBlue"))
(((class color)
(background dark))
(:foreground "LightSteelBlue")))
"Face used for displaying the values of header."
:group 'post-faces)
(defface post-quoted-text-face
'((((class color)
(background light))
(:foreground "Sienna" :italic t))
(((class color)
(background dark))
(:foreground "Wheat" :italic t))
(t
(:bold t :italic t)))
"Face used for displaying text which has been quoted (e.g. \">foo\")."
:group 'post-faces)
(defface post-double-quoted-text-face
'((((class color)
(background light))
(:foreground "Firebrick" :italic t))
(((class color)
(background dark))
(:foreground "Tan" :italic t))
(t
(:italic t)))
"Face used for text which has been quoted twice (e.g. \">>foo\")."
:group 'post-faces)
(defface post-multiply-quoted-text-face
'((((class color)
(background light))
(:foreground "goldenrod" :italic t))
(((class color)
(background dark))
(:foreground "tan3" :italic t))
(t
(:italic t)))
"Face used for text which has been quoted more than twice (e.g. \">>>foo\")."
:group 'post-faces)
(defface post-signature-text-face
'((((class color)
(background light))
(:foreground "red3"))
(((class color)
(background dark))
(:foreground "red1"))
(t
(:bold t)))
"Face used for text that is part of a signature"
:group 'post-faces)
(defface post-email-address-text-face
'((((class color)
(background light))
(:foreground "green3"))
(((class color)
(background dark))
(:foreground "green1"))
(t
(:italic t)))
"Face used for email addresses"
:group 'post-faces)
(defface post-url-face
'((((class color)
(background light))
(:foreground "green3" :bold t))
(((class color)
(background dark))
(:foreground "green1" :bold t))
(t
(:italic t)))
"Face used for URL addresses"
:group 'post-faces)
(defface post-emoticon-face
'((((class color)
(background light))
(:foreground "black" :background "yellow" :bold t))
(((class color)
(background dark))
(:foreground "black" :background "yellow" :bold t))
(t
(:bold t)))
"Face used for text matched by post-emoticon-pattern."
:group 'post-faces)
(defface post-bold-face
'((((class color)
(background light))
(:bold t))
(((class color)
(background dark))
(:bold t))
(t
(:bold t)))
"Face used for text matching post-bold-pattern."
:group 'post-faces)
(defface post-underline-face
'((((class color)
(background light))
(:underline t))
(((class color)
(background dark))
(:underline t))
(t
(:underline t)))
"Face used for text matching post-underline-pattern."
:group 'post-faces)
; Note: some faces are added later!
(defvar post-font-lock-keywords
`(("^\\([A-Z][-A-Za-z0-9.]+:\\)\\(.*\\)$"
(1 'post-header-keyword-face)
(2 'post-header-value-face))
("^[ \t\f]*\\(>[ \t\f]*\\)\\([-a-zA-Z]*>[ \t\f]*\\)\\([-a-zA-Z]*>.*\\)$"
(1 'post-quoted-text-face)
(2 'post-double-quoted-text-face)
(3 'post-multiply-quoted-text-face))
("^[ \t\f]*\\(>[ \t\f]*\\)\\([-a-zA-Z]*>.*\\)$"
(1 'post-quoted-text-face)
(2 'post-double-quoted-text-face))
("^[ \t\f]*\\(>[ \t\f]*[^ \t\f\n>].*\\)$"
(1 'post-quoted-text-face))
("^[ \t\f]*\\(>[ \t\f]*\\)$"
(1 'post-quoted-text-face))
(,post-email-address-pattern
(0 'post-email-address-text-face)))
"Highlighting rules for message mode.")
;;; Declare global mode variables.
(defconst post-font-lock-syntactic-keywords
`((,(concat "^" post-signature-pattern "[ \t\f]*$") 0 '(11))))
(defun post-font-lock-syntactic-face-function (state)
"Function for font locking syntactic faces.
Argument STATE ."
post-signature-text-face)
(defvar post-buf nil
"Name of the composing buffer.")
(defvar post-select-signature-mode-map nil
"Local keymap for the select-signature buffer.")
(defvar post-select-signature-last-buffer nil
"Pointer to the calling buffer.")
(defvar post-select-signature-last-point nil
"Where we were in the calling buffer.")
(defvar post-has-attachment nil
"Whether the message has an attachment.")
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;; Interactive Commands
(defun post-save-current-buffer-and-exit ()
"Save the current buffer and exit Emacs."
(interactive)
;; Should the user be prompted for an attachment?
(cond (post-has-attachment)
((equal post-should-prompt-for-attachment 'Never))
((or (equal post-should-prompt-for-attachment 'Always)
(post-body-says-attach-p))
(post-prompt-for-attachment)))
(basic-save-buffer)
(if post-backup-original
(kill-buffer "*Original*"))
(post-finish)
;; Added by Rob Reid 10/13/1998 to prevent accumulating *Composing* buffers
;; when using (emacs|gnu)client. Helped by Eric Marsden's Eliza example in
;; http://www.ssc.com/lg/issue29/marsden.html
; (kill-buffer post-buf)
)
(defun post-goto-body ()
"Go to the beginning of the message body."
(interactive)
(goto-char (point-min))
;; If the message has header, slide downward.
(and header-mode (save-match-data (re-search-forward "^$" nil t))
(next-line 1)))
(defun post-goto-signature ()
"Go to the beginning of the message signature."
(interactive)
(goto-char (point-max))
(and (save-match-data
(re-search-backward (concat "^" post-signature-pattern
"[ \t\f]*$")
nil t))))
(defun post-delete-quoted-signatures ()
"Delete quoted signatures from buffer."
(interactive)
(goto-char (point-min))
(flush-lines (concat "^\\([ \t\f]*>[ \t\f>]*\\)"
post-signature-pattern
"[ \t\f]*\\(\n\\1.*\\)+")))
(defun post-kill-signature ()
"Kill the signature from the buffer.
Returns the point value for where the signature was or, if there isn't a
signature, the point value of the end of the buffer"
(interactive)
(save-excursion
(goto-char (point-min))
; The .=*+|#@!~$%&()_- is to compensate for people who put ASCII art on the
; same line as the sigdashes, and the $ at the end prevents this from deleting
; everything between mutt's standard forwarding lines.
(cond ((search-forward-regexp (concat "^" post-signature-pattern
"[ \t\f.=*+|#@!~$%&()_-]*$") nil t)
(beginning-of-line)
(kill-region (point) (point-max)))
(t
(goto-char (point-max))))
(point)))
(defun post-delete-old-citations ()
"Delete citations more than one level deep from buffer."
(interactive)
(goto-char (point-min))
(flush-lines "^[ \t\f]*>[ \t\f]*>[ \t\f>]*"))
;;; Functions for messing with the body
(defun post-make-region-bold (start end)
"Apply mutt's nroff style bold to a region of text.
Argument START start of region.
Argument END end of region."
(interactive "r")
(while (< start end)
(goto-char start)
(insert (buffer-substring-no-properties start (1+ start)))
(insert (char-to-string 8))
(setq start (+ start 3))
(setq end (+ end 2))))
(defun post-make-region-underlined (start end)
"Apply mutt's nroff style underline to a region of text.
Argument START start of region.
Argument END end of region."
(interactive "r")
(while (< start end)
(goto-char start)
(insert "_")
(insert (char-to-string 8))
(setq start (+ start 3))
(setq end (+ end 2))))
(defun post-quote-region (beg end)
"Quote a region using the `post-quote-start' variable.
Argument BEG Beginning of region to be quoted.
Argument END End of region to be quoted."
(interactive "r")
(comment-region beg end))
(defun post-unquote-region (beg end)
"Un-quote a region one level using the `post-quote-start' variable.
Argument BEG Beginning of region to be quoted.
Argument END End of region to be quoted."
(interactive "r")
(uncomment-region beg end))
; From Dave Pearson, July 15, 2000
(defun* split-quoted-paragraph (&optional (quote-string "> "))
"Split a quoted paragraph at point, keeping the quote."
(interactive)
(if (save-excursion
(beginning-of-line)
(looking-at (regexp-quote quote-string)))
(progn
(let ((spaces (- (point)
(save-excursion
(beginning-of-line)
(point))
(length quote-string))))
(save-excursion
(insert (format "\n\n%s%s" quote-string (make-string spaces ? ))))))
(error "Can't see a quoted paragraph here")))
(defun post-random-signature ()
"Randomize the signature.
Set it to whatever `post-random-signature-command' spits out followed by the
content of `post-fixed-signature-source', if available, or a nasty reminder if
it is not."
(interactive)
(save-excursion
(goto-char (post-kill-signature))
(insert "-- \n")
(shell-command post-random-signature-command t)
(goto-char (point-max))
(if (file-readable-p post-fixed-signature-source)
(insert-file-contents post-fixed-signature-source)
(insert "I really need a `post-fixed-signature-source'!\n"))))
(defun post-el-random-signature ()
"Choose a random signature from `post-variable-signature-source'.
the signatures in `post-variable-signature-source' must be separated by
`post-signature-sep-regexp'."
(interactive)
(let ((sig nil))
(save-excursion
(set-buffer (generate-new-buffer "*Post-Select-Signature*"))
(insert-file post-variable-signature-source)
(beginning-of-buffer)
;; we have 2 lists of marks since seperators are of arbitrary lenght
(let ((marks-st (list (point-min)))
(marks-end (list))
(count 0)) ;nth counts from zero and random is [0,N)
(while (search-forward-regexp post-signature-sep-regexp nil "a")
(setq marks-st (cons (match-end 0) marks-st)
marks-end (cons (match-beginning 0) marks-end)
count (1+ count)))
(setq marks-end (cons (point-max) marks-end))
(let ((r (random (1+ count))))
(setq sig (buffer-substring-no-properties
(nth r marks-st) (nth r marks-end))))
(kill-buffer (current-buffer)))
(goto-char (post-kill-signature))
(insert-string "-- \n")
(insert sig)
(if (file-readable-p post-fixed-signature-source)
(insert-file-contents post-fixed-signature-source)
(insert "I really need a `post-fixed-signature-source'!\n")))))
(defun post-select-signature-from-file ()
"*Interactively select a signature from `post-variable-signature-source'."
(interactive)
(setq post-select-signature-last-buffer (current-buffer))
(setq post-select-signature-last-point (point))
(pop-to-buffer "*Post-Select-Signature*")
(insert-file post-variable-signature-source)
(use-local-map post-select-signature-mode-map))
(defun post-select-signature-select-sig-from-file ()
"*Chooses the signature the cursor is in from `post-variable-signature-source'."
(interactive)
;; These 2 lines select whatever siglet the cursor is sitting in,
;; making it nifty to C-s "word" then C-m (or whatever this is
;; bound to).
(let ((sig-start (point))
(sig-end (point)))
(cond ((setq sig-start (search-backward-regexp post-signature-sep-regexp
nil "a"))
(forward-line 1)
(setq sig-start (point))))
(if (search-forward-regexp post-signature-sep-regexp nil "a")
(setq sig-end (match-beginning 0))
(setq sig-end (point-max)))
(let ((sig (buffer-substring-no-properties sig-start sig-end)))
(switch-to-buffer post-select-signature-last-buffer)
(goto-char (post-kill-signature))
(insert-string "-- \n")
(insert sig))
(if (file-readable-p post-fixed-signature-source)
(insert-file-contents post-fixed-signature-source))
(post-select-signature-quit)))
(defun post-select-signature-from-dir ()
"Select a new signature for an email/post in the current buffer."
(interactive)
(setq post-select-signature-last-buffer (current-buffer))
(setq post-select-signature-last-point (point))
(pop-to-buffer "*Post-Select-Signature*")
(list-directory (concat post-signature-directory
post-signature-wildcard) t)
(pop-to-buffer "*Directory*")
(next-line 1)
(copy-to-buffer "*Post-Select-Signature*" (point) (point-max))
(kill-buffer "*Directory*")
(pop-to-buffer "*Post-Select-Signature*")
(use-local-map post-select-signature-mode-map)
(toggle-read-only t))
(defun post-select-signature-select-sig-from-dir ()
"Set the signature in the calling buffer to the one under the cursor."
(interactive)
(let ((sig-start nil)
(sig-to-load nil))
(end-of-line)
(search-backward " ")
(forward-char)
(setq sig-start (point))
(end-of-line)
(setq sig-to-load (buffer-substring-no-properties sig-start (point)))
(switch-to-buffer post-select-signature-last-buffer)
(goto-char (post-kill-signature))
(insert-string "-- \n")
(insert-file (concat post-signature-directory sig-to-load))
(message "Signature set to %s%s" post-signature-directory sig-to-load)
(post-select-signature-quit)))
(defun post-select-signature-quit ()
"Kill the *Post-Select-Signature* frame."
(interactive)
(kill-buffer "*Post-Select-Signature*")
(switch-to-buffer post-select-signature-last-buffer)
(goto-char post-select-signature-last-point)
(delete-other-windows))
(defun post-attach-file ()
"Prompt for an attachment."
(interactive)
(let ((file (read-file-name "Attach file: " nil nil t nil))
(description (string-read "Description: ")))
(header-attach-file file description)))
;;; Non-interactive functions
(defun post-prompt-for-attachment ()
"Prompt for an attachment."
(if (y-or-n-p "Do you want to attach anything? ")
(post-attach-file)))
(defun post-references-p ()
"Is there a References header in this buffer?"
(save-excursion
(goto-char (point-min))
(looking-at "^References: ")))
(defun post-body-says-attach-p ()
"Check if attach appears in the body."
(post-goto-body)
;; Aargh it's annoying that how-many returns a string,
;; "13 occurences" instead of a number, 13.
;; As of Emacs 22 how-many returns an integer number. Consideration
;; must be taken for both newer and older versions.
(let ((total-attach (how-many post-attachment-regexp)))
(if (string= (type-of total-attach) 'string)
(setq total-attach (string-to-number (how-many post-attachment-regexp))))
;; And this mess is just to catch the unlikely false alarm of
;; "attach" being in the signature, but not in the body.
(if (> total-attach 0)
(progn (post-goto-signature)
(if (string= (type-of (how-many post-attachment-regexp)) 'string)
(> total-attach (string-to-number (how-many
post-attachment-regexp)))
(> total-attach (how-many
post-attachment-regexp)))))))
(defun post-ask-for-address-with-default (header)
"Prompt for an email address, showing default.
Argument HEADER the header type."
(let ((default (if (= (length (post-get-header-value header)) 0)
post-email-address
(post-get-header-value header))))
(read-string (concat header ": ") default)))
; From [email protected]. RR hasn't tested it.
(defun post-get-header-value (header)
"Get the value of a specific mail HEADER."
(save-excursion
(let ((value "")
(start-of-value nil))
(setf (point) (point-min))
(when (post-find-header-line header)