| 1 |
;;; dot.emacs --- sample init file for MU-CITE -*-mode: emacs-lisp;-*- |
| 2 |
|
| 3 |
;; for Wanderlust, MH-E, etc. |
| 4 |
(add-hook 'mail-citation-hook 'mu-cite-original) |
| 5 |
;; for Gnus |
| 6 |
(setq message-cite-function 'mu-cite-original) |
| 7 |
;; for Mew |
| 8 |
(add-hook 'mew-cite-hook |
| 9 |
(lambda () |
| 10 |
(mu-cite-original) |
| 11 |
(exchange-point-and-mark) ;; for highlighting |
| 12 |
)) |
| 13 |
(setq mew-summary-reply-with-citation-position 'body) |
| 14 |
|
| 15 |
;; for citation with "> " instead of "name> " |
| 16 |
(setq mu-cite-prefix-format '("> ")) |
| 17 |
(setq mu-cite-cited-prefix-regexp nil) |
| 18 |
|
| 19 |
;; for citation header with date and from, e.g. |
| 20 |
;; On Mon, 05 Oct 2020 17:03:31 +0900, |
| 21 |
;; Full Name <[email protected]> wrote: |
| 22 |
(setq mu-cite-top-format '("On " date ",\n" from " wrote:\n")) |
| 23 |
;; On October 5, 2020, Full Name wrote: |
| 24 |
;; On September 24, 2020, user (at example.net) wrote: |
| 25 |
(setq mu-cite-top-format '("On " my-us-date ", " my-full-name-or-address " wrote:\n")) |
| 26 |
;; On October 5, 2020, at 5:03 p.m., Full Name wrote: |
| 27 |
;; On September 24, 2020, at 12:27 a.m., user (at example.net) wrote: |
| 28 |
(setq mu-cite-top-format '("On " my-us-date-at-time ", " my-full-name-or-address " wrote:\n")) |
| 29 |
;; On 2020-10-05 at 17:03 +0900, [mailing-list:12345], Full Name wrote: |
| 30 |
;; On 2020-09-24 at 00:27 +0900, user (at example.net) wrote: |
| 31 |
(setq mu-cite-top-format '("On " my-iso-date-at-time ", " my-list-label my-full-name-or-address " wrote:\n")) |
| 32 |
|
| 33 |
;; for my-* methods |
| 34 |
(add-hook 'mu-cite-instantiation-hook 'my-mu-cite-set-methods) |
| 35 |
(defun my-mu-cite-set-methods () |
| 36 |
(add-to-list |
| 37 |
'mu-cite-methods-alist |
| 38 |
(cons |
| 39 |
'my-us-date ;; e.g. "October 5, 2020" |
| 40 |
(lambda () |
| 41 |
(let ((dt (mu-cite-get-value 'date)) |
| 42 |
pdt y m d) |
| 43 |
(when dt |
| 44 |
(setq pdt (timezone-parse-date dt)) |
| 45 |
(setq y (string-to-number (aref pdt 0))) |
| 46 |
(setq m (string-to-number (aref pdt 1))) |
| 47 |
(setq d (string-to-number (aref pdt 2)))) |
| 48 |
(if (and dt (> y 0) (> m 0) (< m 13) (> d 0)) |
| 49 |
(format "%s %d, %d" |
| 50 |
(aref ["January" "February" "March" "April" "May" |
| 51 |
"June" "July" "August" "September" "October" |
| 52 |
"November" "December"] (1- m)) d y) |
| 53 |
(or dt "one day")))))) |
| 54 |
(add-to-list |
| 55 |
'mu-cite-methods-alist |
| 56 |
(cons |
| 57 |
'my-us-date-at-time ;; e.g. "October 5, 2020, at 5:03 p.m." |
| 58 |
(lambda () |
| 59 |
(let ((dt (mu-cite-get-value 'date)) |
| 60 |
pdt y m d time hour min ampm zone) |
| 61 |
(when dt |
| 62 |
(setq pdt (timezone-parse-date dt)) |
| 63 |
(setq y (string-to-number (aref pdt 0))) |
| 64 |
(setq m (string-to-number (aref pdt 1))) |
| 65 |
(setq d (string-to-number (aref pdt 2))) |
| 66 |
(setq time (aref pdt 3)) |
| 67 |
;;; (setq zone (or (aref pdt 4) "")) |
| 68 |
;;; (when (string= zone (format-time-string "%z" (current-time))) ;; omit current timezone |
| 69 |
;;; (setq zone "")) |
| 70 |
(when (string-match "^\\([0-9][0-9]?\\):\\([0-9][0-9]?\\)" time) |
| 71 |
(setq hour (string-to-number (match-string 1 time))) |
| 72 |
(setq min (string-to-number (match-string 2 time))) |
| 73 |
(setq ampm "") |
| 74 |
(if (< hour 12) |
| 75 |
(setq ampm " a.m.") |
| 76 |
(when (< hour 24) |
| 77 |
(setq ampm " p.m.") |
| 78 |
(setq hour (- hour 12)))) |
| 79 |
(when (= hour 0) |
| 80 |
(setq hour 12)) |
| 81 |
(setq time (format "%d:%02d%s%s" hour min ampm |
| 82 |
(if (> (length zone) 0) (concat " " zone) ""))))) |
| 83 |
(if (and dt (> y 0) (> m 0) (< m 13) (> d 0) (> (length time) 1)) |
| 84 |
(format "%s %d, %d, at %s" |
| 85 |
(aref ["January" "February" "March" "April" "May" |
| 86 |
"June" "July" "August" "September" "October" |
| 87 |
"November" "December"] (1- m)) d y time) |
| 88 |
(or dt "one day")))))) |
| 89 |
(add-to-list |
| 90 |
'mu-cite-methods-alist |
| 91 |
(cons |
| 92 |
'my-iso-date-at-time ;; e.g. "2020-10-05 at 17:03 +0900" |
| 93 |
(lambda () |
| 94 |
(let ((dt (mu-cite-get-value 'date)) |
| 95 |
pdt y m d time zone) |
| 96 |
(when dt |
| 97 |
(setq pdt (timezone-parse-date dt)) |
| 98 |
(setq y (string-to-number (aref pdt 0))) |
| 99 |
(setq m (string-to-number (aref pdt 1))) |
| 100 |
(setq d (string-to-number (aref pdt 2))) |
| 101 |
(setq time (aref pdt 3)) |
| 102 |
(setq zone (or (aref pdt 4) "")) |
| 103 |
;;; (when (string= zone (format-time-string "%z" (current-time))) ;; omit current timezone |
| 104 |
;;; (setq zone "")) |
| 105 |
(when (string-match "^\\([0-9][0-9]?\\):\\([0-9][0-9]?\\)" time) |
| 106 |
(setq time (format "%02d:%02d" |
| 107 |
(string-to-number (match-string 1 time)) |
| 108 |
(string-to-number (match-string 2 time)))))) |
| 109 |
(if (and dt (> y 0) (> m 0) (< m 13) (> d 0) (> (length time) 1)) |
| 110 |
(format "%d-%02d-%02d at %s%s" y m d time |
| 111 |
(if (> (length zone) 0) (concat " " zone) "")) |
| 112 |
(or dt "one day")))))) |
| 113 |
(add-to-list |
| 114 |
'mu-cite-methods-alist |
| 115 |
(cons |
| 116 |
'my-list-label ;; e.g. "[mailing-list:12345], " |
| 117 |
(lambda () |
| 118 |
(let ((subj (mu-cite-get-value 'subject)) |
| 119 |
ml-name ml-count) |
| 120 |
(if (and subj |
| 121 |
(or (string-match "^\\[[a-zA-Z0-9._-]+[ :,] ?[0-9]+\\]" subj) |
| 122 |
(string-match "^([a-zA-Z0-9._-]+[ :,] ?[0-9]+)" subj))) |
| 123 |
(concat (match-string 0 subj) ", ") |
| 124 |
(setq ml-name (mu-cite-get-field-value "X-ML-Info")) |
| 125 |
(if (and ml-name (string-match ".*help=" ml-name)) |
| 126 |
(setq ml-name (replace-match "" nil t ml-name)) |
| 127 |
(setq ml-name nil)) |
| 128 |
(if (and ml-name (string-match "-ctl@" ml-name)) |
| 129 |
(setq ml-name (replace-match "@" nil t ml-name)) |
| 130 |
(setq ml-name nil)) |
| 131 |
(when (null ml-name) |
| 132 |
(setq ml-name (mu-cite-get-field-value "List-Post"))) |
| 133 |
(if (and ml-name (string-match ".*mailto:" ml-name)) |
| 134 |
(setq ml-name (replace-match "" nil t ml-name)) |
| 135 |
(setq ml-name nil)) |
| 136 |
(if (and ml-name (string-match "@.*" ml-name)) |
| 137 |
(setq ml-name (replace-match "" nil t ml-name)) |
| 138 |
(setq ml-name nil)) |
| 139 |
(when (null ml-name) |
| 140 |
(setq ml-name (mu-cite-get-value 'ml-name))) |
| 141 |
(when (and ml-name (> (length ml-name) 30)) ;; avoid long name |
| 142 |
(setq ml-name nil)) |
| 143 |
(setq ml-count (mu-cite-get-value 'ml-count)) |
| 144 |
(and ml-name ml-count (concat "[" ml-name ":" ml-count "], ")) ;; ml-name and ml-count |
| 145 |
;;; (and ml-name (concat "[" ml-name (if ml-count ":") ml-count "], ")) ;; allow without ml-count |
| 146 |
))))) |
| 147 |
(add-to-list |
| 148 |
'mu-cite-methods-alist |
| 149 |
(cons |
| 150 |
'my-full-name-or-address ;; e.g. "Full Name" or "user (at example.net)" |
| 151 |
(lambda () |
| 152 |
(let ((name (mu-cite-get-value 'full-name)) |
| 153 |
adr) |
| 154 |
(when (and name (string-match "[ \t]+via[ \t].*" name)) ;; remove " via ..." |
| 155 |
(setq name (replace-match "" nil t name))) |
| 156 |
(when (and name (> (length name) 30)) ;; avoid long name |
| 157 |
(setq name nil)) |
| 158 |
;;; (when (and name (string-match "[^\0-\577]" name)) ;; avoid CJK, accept Latin |
| 159 |
;;; (setq name nil)) |
| 160 |
;;; (when (and name (string-match "[^\0-\177]" name)) ;; avoid non-ASCII |
| 161 |
;;; (setq name nil)) |
| 162 |
(when (null name) ;; fallback to 'address |
| 163 |
(setq adr (mu-cite-get-value 'address)) |
| 164 |
(when (and adr (string-match "@" adr)) |
| 165 |
(setq name (concat (replace-match " (at " nil t adr) ")")))) |
| 166 |
(when (null name) ;; fallback to 'from |
| 167 |
(setq name (mu-cite-get-value 'from))) |
| 168 |
(when name |
| 169 |
(while (string-match "@" name) |
| 170 |
(setq name (replace-match "[at]" nil t name)))) |
| 171 |
(or name "someone")))))) |
| 172 |
|
| 173 |
;;; dot.emacs ends here |