-
Notifications
You must be signed in to change notification settings - Fork 23
/
spacecraft-mode.el
756 lines (616 loc) · 20 KB
/
spacecraft-mode.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
(defun smart-period-or-smart-space ()
"double space adds a period!"
(interactive)
(if
(looking-back "[A-Za-z0-9] ")
(smart-period)
(smart-space)
))
(defun smart-space ()
"Insert space and then clean up whitespace."
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
;; (if (org-at-heading-p)
;; (insert-normal-space-in-org-heading)
(unless
(or
(let ((case-fold-search nil)
(looking-back "\\bi\.e[[:punct:][:punct:]]*[ ]*") ; don't add extra spaces to ie.
)
(looking-back "\\bvs.[ ]*") ; don't add extra spaces to vs.
(looking-back "\\be\.\g[[:punct:]]*[ ]*") ; don't add extra spaces to eg.
(looking-back "^[[:punct:]]*[ ]*") ; don't expand previous lines - brilliant!
(looking-back ">") ; don't expand days of the week inside timestamps
(looking-back "][\n\t ]*") ; don't expand past closing square brackets ]
))
(smart-expand))
(insert "\ ")
(just-one-space)
)
;; this is probably convuluted logic to invert the behavior of the SPC key when in org-heading
(defun insert-smart-space-in-org-heading ()
"Insert space and then clean up whitespace."
(interactive)
(unless
(or
(looking-back "\\bvs.[ ]*") ; don't add extra spaces to vs.
(looking-back "\\bi\.e[[:punct:][:punct:]]*[ ]*") ; don't add extra spaces to ie.
(looking-back "\\be\.\g[[:punct:][:punct:]]*[ ]*") ; don't add extra spaces to eg.
(looking-back "^[[:punct:][:punct:]]*[ ]*") ; don't expand previous lines---brilliant!
(looking-back ">") ; don't expand days of the week inside timestamps
(looking-back "][\n\t ]*") ; don't expand past closing square brackets ]
)
(smart-expand))
(insert "\ ")
(just-one-space))
(define-key org-mode-map (kbd "<SPC>") 'smart-space)
;; (define-key orgalist-mode-map (kbd "<SPC>") 'smart-period-or-smart-space)
(global-set-key (kbd "M-SPC") 'insert-space)
(define-key org-mode-map (kbd "<M-SPC>") 'insert-space)
;; (define-key orgalist-mode-map (kbd "<M-SPC>") 'insert-space)
(defun my/fix-space ()
"Delete all spaces and tabs around point, leaving one space except at the beginning of a line and before a punctuation mark."
(interactive)
(just-one-space)
(when (and (or
(looking-back "^[[:space:]]+")
(looking-back "-[[:space:]]+")
(looking-at "[.,:;!?»)-]")
(looking-back"( ")
(looking-at " )")
)
(not (looking-back "^-[[:space:]]+"))
(not (looking-back " - "))
)
(delete-horizontal-space)))
(defun insert-space ()
(interactive)
(if (org-at-heading-p)
(insert-smart-space-in-org-heading)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(insert " ")
))
(defun insert-normal-space-in-org-heading ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(insert " ")
)
;; this is probably convuluted logic to invert the behavior of the SPC key when in org-heading
(defun insert-period ()
"Inserts a fuckin' period!"
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(insert ".")
)
(defun insert-comma ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(insert ",")
)
(defun insert-exclamation-point ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(insert "!")
)
(defun insert-colon ()
"Insert a goodamn colon!"
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(insert ":")
)
(defun insert-question-mark ()
"Insert a freaking question mark!!"
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(insert "?")
)
(defun kill-clause ()
(interactive)
(smart-expand)
(when (or (looking-at ",")
(looking-at ";")
(looking-at ":"))
(org-delete-char 1))
(when (or (looking-back ",")
(looking-back ";")
(looking-back ":"))
(org-delete-backward-char 1))
(when (looking-back " ")
(left-char 1))
(if
(let ((sm (string-match "*+\s" (thing-at-point 'line)))) (and sm (= sm 0)))
(kill-line)
(let ((old-point (point))
(kill-punct (my/beginning-of-sentence-p)))
;; Stop at a period followed by a space, or the end of the line
(when (re-search-forward "--\\|[][,;:?!…\"”()}\\.]+\\|$" nil t)
(kill-region old-point
(if kill-punct
(match-end 0)
(match-beginning 0)))))
(my/fix-space)
(save-excursion
(when (my/beginning-of-sentence-p)
(capitalize-unless-org-heading)))
(cond
((looking-back "\\, \\, ")
(new-org-delete-backward-char 2)
(my/fix-space)
t)
((looking-back "!\\. ")
(new-org-delete-backward-char 2)
(my/fix-space)
t)
((looking-back ":: ")
(new-org-delete-backward-char 2)
(my/fix-space)
t))
(when
(looking-back "[[:punct:]]")
(progn
(forward-char 1)
(my/fix-space)
(backward-char 1)))
;; fix a bug that leaves this: " ?"
(when (looking-back " \\?")
(left-char 1)
(new-org-delete-backward-char 1)
(right-char 1))
;; fix a bug that leaves this: " , "
(when (looking-back " , ")
(left-char 2)
(my/fix-space)
(right-char 2))
;; fix a bug that leaves this: ":, "
(when (looking-back ":, ")
(left-char 1)
(delete-backward-char 1)
(right-char 1))
;; fix a bug that leaves this: ",."
(when (looking-back "\\,\\. ")
(left-char 2)
(delete-backward-char 1)
(right-char 2)
)
;; fix a bug that leaves this: ", . "
(when (looking-back "\\, \\. ")
(left-char 2)
(delete-backward-char 2)
(right-char 2)
)
;; fix a bug that leaves this: " ; "
(when
(looking-back " [[:punct:]] ")
(left-char 2)
(delete-backward-char 1)
(right-char 2)
)
(when
(and
(looking-back "----")
(looking-at "-"))
(delete-backward-char 4)
(delete-char 1)
(insert-space))
;; leave the cursor before the comma or period, not after it
(when
(looking-back "[[:punct:]] ")
(left-char 2))
(when
(looking-back "[[:punct:]]")
(left-char 1))
;; fix a bug that leaves this: ".,"
(when
(looking-at "\\.\\,")
(delete-forward-char 1)
)
;; works!!
;; fix a bug that leaves this: ":."
(when
(looking-at ":\\.")
(delete-forward-char 1)
)
;; works!!
;; a more general solution, haven't tested it yet:
;; (when
;; (looking-at "[[:punct:]]\\.")
;; (delete-forward-char 1) )
;; when on a punctuation mark with a space before it, delete the space
(when
(and
(looking-at "[[:punct:]]")
(looking-back " ")
)
(delete-backward-char 1))
)
(when
(or
(looking-at ":\\,")
(looking-at ";\\,")
(looking-at "\\,\\,")
(looking-at "\\.\\.")
(looking-at "\\,;")
(looking-at "\\,:")
(looking-at "\\?\\?")
)
(right-char 1)
(delete-char 1)
(left-char 1)
)
;; Add this near the end of the function, before the final right parenthesis
(when (looking-at ",")
(when (looking-back ", ")
(delete-backward-char 2)
(insert ", "))))
(defvar *smart-punctuation-marks*
".,;:!?-")
(setq *smart-punctuation-exceptions*
(list "?!" ".." "..." "............................................." "---" ";;" "!!" "!!!" "??" "???" "! :" ". :" ") ; "))
(defun smart-punctuation (new-punct &optional not-so-smart)
(smart-expand)
(save-restriction
(when (and (eql major-mode 'org-mode)
(org-at-heading-p))
(save-excursion
(org-beginning-of-line)
(let ((heading-text (fifth (org-heading-components))))
(when heading-text
(search-forward heading-text)
(narrow-to-region (match-beginning 0) (match-end 0))))))
(cl-flet ((go-back (regexp)
(re-search-backward regexp nil t)
(ignore-errors ; might signal `end-of-buffer'
(forward-char (length (match-string 0))))))
(if not-so-smart
(let ((old-point (point)))
(go-back "[^ \t]")
(insert new-punct)
(goto-char old-point)
(forward-char (length new-punct)))
(let ((old-point (point)))
(go-back (format "[^ \t%s]\\|\\`" *smart-punctuation-marks*))
(let ((was-after-space (and (< (point) old-point)
(find ? (buffer-substring (point) old-point)))))
(re-search-forward (format "\\([ \t]*\\)\\([%s]*\\)"
*smart-punctuation-marks*)
nil t)
(let* ((old-punct (match-string 2))
(was-after-punct (>= old-point (point))))
(replace-match "" nil t nil 1)
(replace-match (or (when (and was-after-punct
(not (string= old-punct "")))
(let ((potential-new-punct (concat old-punct new-punct)))
(find-if (lambda (exception)
(search potential-new-punct exception))
*smart-punctuation-exceptions*)))
new-punct)
nil t nil 2)
(if was-after-space
(my/fix-space)
(when (looking-at "[ \t]*\\<")
(save-excursion (my/fix-space))))))))))
(when (and (eql major-mode 'org-mode)
(org-at-heading-p))
))
(defun smart-period ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(unless
(or
(looking-back "\\bvs.[ ]*") ; Don't add extra periods to vs.
(looking-back "\\bi\.e[[:punct:]]*[ ]*") ; don't add extra periods to ie.
(looking-back "\\be\.\g[[:punct:]]*[ ]*") ; don't add extra periods to eg.
)
(smart-punctuation "."))
(save-excursion
(unless
(or
(looking-at "[ ]*$")
(looking-at "\][[:punct:]]*[ ]*$")
(looking-at "[[:punct:]]*[ ]*$")
(looking-at "\"[[:punct:]]*[ ]*$")
(looking-at "\)[ ]*$")
(looking-at "\)")
) ; or
(capitalize-unless-org-heading)
) ; unless
) ; save excursion
;; if two periods or two commas in a row, delete the second one
(when
(or
(and
(looking-at "\\.")
(looking-back "\\.")
)
(and
(looking-at ",")
(looking-back ",")
))
(delete-char 1)
)
)
(define-key org-mode-map (kbd ".") 'smart-period)
(defun smart-comma ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(smart-punctuation ",")
(unless
(or
(looking-at "\]*[[:punct:]]*[ ]*$")
(looking-at "[[:punct:]]*[ ]*$")
(looking-at "[ ]*I\\b") ; never downcase the word "I"
(looking-at "[ ]*I\'") ; never downcase the word "I'
(looking-at "[[:punct:]]*[ ]*\"") ; beginning of a quote
)
(save-excursion (downcase-word 1)))
(when
;; if two periods or two commas in a row, delete the second one
(or
(and
(looking-at "\\.")
(looking-back "\\.")
)
(and
(looking-at ",")
(looking-back ",")
))
(delete-char 1)
)
)
(define-key org-mode-map (kbd ",") 'comma-or-smart-comma)
;; (define-key orgalist-mode-map (kbd ",") 'comma-or-smart-comma)
(defun smart-question-mark ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(smart-punctuation "?")
(save-excursion
(unless
(or
(looking-at "[ ]*$")
(looking-at "\][[:punct:]]*[ ]*$")
(looking-at "[[:punct:]]*[ ]*$")
(looking-at "\"[[:punct:]]*[ ]*$")
(looking-at "\)[ ]*$")
(looking-at "\)")
) ; or
(capitalize-unless-org-heading)
) ; unless
) ; save excursion
) ; defun
;; works!!
(define-key org-mode-map (kbd "?") 'smart-question-mark)
;; (define-key orgalist-mode-map (kbd "?") 'smart-question-mark)
(defun smart-exclamation-point ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(smart-punctuation "!")
(save-excursion
(unless (looking-at "[ ]*$")
(capitalize-unless-org-heading))
))
(define-key org-mode-map (kbd "!") 'smart-exclamation-point)
;; (define-key orgalist-mode-map (kbd "!") 'smart-exclamation-point)
(defun smart-semicolon ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(smart-punctuation ";")
(unless
(or
(looking-at "[[:punct:]]*[ ]*$")
(looking-at "[ ]*I\\b") ; never downcase the word "I"
(looking-at "[ ]*I\'") ; never downcase the word "I'
(looking-at "[[:punct:]]*[ ]*\"") ; beginning of a quote
)
(save-excursion (downcase-word 1))))
(define-key org-mode-map (kbd ";") 'smart-semicolon)
;; (define-key orgalist-mode-map (kbd ";") 'smart-semicolon)
(defun smart-colon ()
(interactive)
(cond (mark-active
(progn (delete-region (mark) (point)))))
(smart-punctuation ":")
(unless
(or
(looking-at "[[:punct:]]*[ ]*$")
(looking-at "[ ]*I\\b") ; never downcase the word "I"
(looking-at "[ ]*I\'") ; never downcase the word "I'
(looking-at "[[:punct:]]*[ ]*\"") ; beginning of a quote
)
;; (save-excursion (downcase-word 1))
))
(define-key org-mode-map (kbd ":") 'colon-or-smart-colon)
(define-key org-mode-map (kbd ",") 'comma-or-smart-comma)
;; (define-key orgalist-mode-map (kbd ":") 'smart-colon)
(defun comma-or-smart-comma ()
(interactive)
(if
(or
(bolp)
(org-at-heading-p)
(looking-at " \"")
)
(insert ",")
(smart-comma))
)
(defun line-starts-with-hash-p ()
(save-excursion
(beginning-of-line)
(looking-at-p "#")))
(defun colon-or-smart-colon ()
(interactive)
(if (or (bolp)
(org-at-heading-p)
(line-starts-with-hash-p))
(insert ":")
(smart-colon)))
(defun backward-kill-word-correctly ()
"Kill word."
(interactive)
(if (re-search-backward "\\>\\W*[[:punct:]]+\\W*\\=" nil t)
(kill-region (match-end 0) (match-beginning 0))
(backward-kill-word 1))
(my/fix-space)
;; I added this ↓↓↓ #######################
(when (and
(not (looking-back "---")) ; I added this
(not (looking-back "^"))) ; I added this
;; I added this ↑↑↑ #######################
(smart-space)
)
(my/fix-space
))
(defun my/delete-backward ()
"When there is an active region, delete it and then fix up the whitespace"
(interactive)
(if (use-region-p)
(delete-region (region-beginning) (region-end))
(delete-backward-char 1))
(save-excursion
(when (or (looking-at "[[:space:]]")
(looking-back "[[:space:]]"))
(unless (looking-back "\\w ")
(my/fix-space)))))
(defcustom capitalize-after-deleting-single-char nil
"Determines whether capitalization should occur after deleting a single character.")
(defun my/delete-backward-and-capitalize ()
"When there is an active region, delete it and then fix up the whitespace"
(interactive)
(when (looking-back "^[*]+ ")
(kill-line 0)
(insert " ") ; this line is super hacky I put it here because when I tried to use "unless", the rest of the function, and then this at the end, it didn't work; however, this does produce the behavior I desire
)
(let ((capitalize capitalize-after-deleting-single-char))
(if (use-region-p)
(progn
(delete-region (region-beginning) (region-end))
(setf capitalize t))
(new-org-delete-backward-char 1))
(save-excursion
(when (or (looking-at "[[:space:]]")
(looking-back "[[:space:]]"))
;; unless there's already exactly one space between words, since I need to be able to delete backward past spaces
(unless (and
(looking-back "\\w ")
(looking-at "\\w")
)
(my/fix-space))))
(when (and capitalize (my/beginning-of-sentence-p))
(save-excursion
(capitalize-unless-org-heading))))
(when
(or
(and
(looking-at "\\.")
(looking-back "\\.")
)
(and
(looking-at ",")
(looking-back ",")
))
(delete-char 1)
)
)
(defun backward-kill-word-correctly-and-capitalize ()
"Backward kill word correctly. Then check to see if the point is at the beginning of the sentence. If yes, then kill-word-correctly and endless/capitalize to capitalize the first letter of the word that becomes the first word in the sentence. Otherwise simply kill-word-correctly."
(interactive)
(call-interactively 'backward-kill-word-correctly)
(let ((fix-capitalization (my/beginning-of-sentence-p)))
(when fix-capitalization
(save-excursion (capitalize-unless-org-heading)))))
(defadvice capitalize-word (after capitalize-word-advice activate)
"After capitalizing the new first word in a sentence, downcase the next word which is no longer starting the sentence."
(unless
(or
(looking-at "[ ]*\"") ; if looking at a quote? Might not work
(looking-at "[[:punct:]]*[ ]*I\\b") ; never downcase the word "I"
(looking-at "[[:punct:]]*[ ]*I'") ; never downcase words like I'm, I'd
(looking-at "[[:punct:]]*[ ]*\"*I'") ; never downcase words like I'm, I'd
(looking-at "[ ]*I\'") ; never downcase the word "I'
(looking-at "[[:punct:]]*[ ]*\"I\\b") ; never downcase the word "I"
(looking-at "[[:punct:]]*[ ]*OK\\b") ; never downcase the word "OK"
;; (looking-at "\\") ; how do you search for a literal backslash?
(looking-at (sentence-end))
(looking-at "[[:punct:]]*[ ]*$") ; don't downcase past line break
(looking-at "[[:punct:]]*[ ]*\"$") ; don't downcase past quotation then line break
(looking-at "[[:punct:]]*[ ]*)$") ; don't downcase past a right paren then line break
(looking-at "[[:punct:]]*[ ]*\")$") ; don't downcase past a quotation then a right paren then a line break
(looking-at "[[:punct:]]*[ ]*http") ; never capitalize http
(looking-at "\"[[:punct:]]*[ ]*$") ; a quotation mark followed by "zero or more whitespace then end of line?"
(looking-at "\)[ ]*$") ; a right paren followed by "zero or more" whitespace, then end of line
(looking-at ")[ ]*$") ; a right paren followed by "zero or more" whitespace, then end of line
(looking-at ")$") ; a right paren followed by "zero or more" whitespace, then end of line
(looking-at "[ ]*-*[ ]*$") ; dashes at the end of a line
(looking-at (user-full-name))
)
(save-excursion
(downcase-word 1))))
(defun capitalize-unless-org-heading ()
(interactive)
(when capitalist-mode
(unless
(or
(looking-at "[[:punct:]]*[\n\t ]*\\*")
(let ((case-fold-search nil))
(looking-at "[ ]*[\n\t ]*[[:punct:]]*[\n\t ]*[A-Z]")
(looking-at "[A-Z].*"))
(looking-at "[\n\t ]*[[:punct:]]*[\n\t ]*#\\+")
(looking-at "[\n\t ]*[[:punct:]]*[\n\t ]*\(")
(looking-at "[\n\t ]*[[:punct:]]*[\n\t ]*<")
(looking-at "[\n\t ]*[[:punct:]]*[\n\t ]*file:")
(looking-at "[\n\t ]*\\[fn")
(looking-at "[\n\t ]*)$")
(looking-at "[\n\t ]*\"$")
(looking-at "\"[\n\t ]*$")
(looking-at "[[:punct:]]*[ ]*http")
(looking-at "[[:punct:]]*[ ]*\")$"); don't capitalize past
(looking-at "[ ]*I\'")
(looking-at
(concat
"\\("
(reduce (lambda (a b) (concat a "\\|" b))
auto-capitalize-words)
"\\)")))
(capitalize-word 1))))
(defun downcase-save-excursion ()
(interactive)
(unless
(or
(looking-at "[[:punct:]]*[ ]*$")
(looking-at "[ ]*I\\b") ; never downcase the word "I"
(looking-at "[[:punct:]]*[ ]*[[:punct:]]*I'") ; never downcase I'm I've etc.
(looking-at "[[:punct:]]*[ ]*$") ; zero or more whitespaces followed by zero or more punctuation followed by zero or more whitespaces followed by a line break
(looking-at "\"[[:punct:]]*[ ]*$") ; a quotation mark followed by "zero or more whitespace then end of line?"
(looking-at "\)[ ]*$") ; a quotation mark followed by "zero or more whitespace then end of line?"
(looking-at (sentence-end)) ; quotation mark followed by "zero or more whitespace then end of line?"
(looking-at (user-full-name))
)
(save-excursion
(downcase-word 1))
))
(defun smart-expand ()
(interactive)
(unless
(or
(looking-back "\)\n*")
(looking-back "[[:punct:]]*\)[ ]*[[:punct:]]*[\n\t ]*[[:punct:]]*>*")
(looking-back ":t[ ]*")
(looking-back "][\n\t ]*[[:punct:]]*[\n\t ]*") ; don't expand past closing square brackets ]
(looking-back ">[\n\t ]*[[:punct:]]*[\n\t ]*") ; don't expand past closing email addresses]
;; (looking-back "\\\w") ; for some reason this matches all words, not just ones that start with a backslash
)
(expand-abbrev)
)
)