1 ;;; letter.el - Special code for letter style.
3 ;; Copyright (C) 1993, 2012, 2013 Free Software Foundation, Inc.
5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
6 ;; Maintainer: auctex-devel@gnu.org
9 ;; This file is part of AUCTeX.
11 ;; AUCTeX is free software; you can redistribute it and/or modify it
12 ;; under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 3, or (at your option)
16 ;; AUCTeX is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ;; General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
23 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
28 (defvar LaTeX-letter-class-options
29 '("a4paper" "a5paper" "b5paper" "letterpaper" "legalpaper" "executivepaper"
30 "landscape" "10pt" "11pt" "12pt" "oneside" "twoside" "draft" "final"
32 "Package options for the letter class.")
34 ;; You may want to define this in tex-site.el to contain your
35 ;; organizations address.
36 (defvar LaTeX-letter-sender-address ""
37 "Initial value when prompting for a sender address in the letter style.")
42 (LaTeX-add-environments
43 '("letter" LaTeX-env-recipient))
44 (LaTeX-add-pagestyles "headings" "firstpage")
45 (setq LaTeX-default-document-environment "letter")
48 '("address" "Sender address: ")
49 '("signature" "Signature: ")
50 '("opening" "Opening: ")
51 '("closing" "Closing: ")
71 (when (and (featurep 'font-latex)
72 (eq TeX-install-font-lock 'font-latex-setup))
73 (font-latex-add-keywords '(("name" "{")
86 (defun LaTeX-env-recipient (environment)
87 "Insert ENVIRONMENT and prompt for recipient and address."
88 (let ((sender (read-string "Sender: " (user-full-name)))
89 (sender-address (read-string "Sender address: "
90 LaTeX-letter-sender-address))
91 (recipient (read-string "Recipient: "))
92 (address (read-string "Recipient address: "))
93 (signature (read-string "Signature: "))
94 (opening (read-string "Opening: "))
95 (closing (read-string "Closing: "))
96 (date (read-string "Date: " (LaTeX-today))))
98 (insert TeX-esc "name" TeX-grop sender TeX-grcl)
100 (if (not (zerop (length sender-address)))
102 (setq LaTeX-letter-sender-address sender-address)
103 (insert TeX-esc "address" TeX-grop sender-address TeX-grcl)
104 (newline-and-indent)))
105 (if (not (zerop (length signature)))
107 (insert TeX-esc "signature" TeX-grop signature TeX-grcl)
108 (newline-and-indent)))
109 (if (not (zerop (length date)))
111 (insert TeX-esc "renewcommand" TeX-grop TeX-esc "today" TeX-grcl
112 TeX-grop date TeX-grcl)
113 (newline-and-indent)))
116 (let ((indentation (current-column)))
117 (LaTeX-insert-environment
119 (concat TeX-grop recipient
120 (if (not (zerop (length address)))
122 (if (not (zerop (length recipient)))
123 (concat " " TeX-esc TeX-esc " "))
126 (save-excursion ; Fix indentation of address
127 (if (search-backward TeX-grcl nil 'move)
128 (let ((addr-end (point-marker)))
129 (if (search-backward TeX-grop nil 'move)
130 (let ((addr-column (current-column)))
131 (while (search-forward
132 (concat TeX-esc TeX-esc)
133 (marker-position addr-end) 'move)
136 (indent-to addr-column))))))))
138 (indent-to indentation))
139 (insert TeX-esc "opening"
141 (if (zerop (length opening))
146 (indent-relative-maybe)
148 (insert "\n" TeX-esc "closing"
150 (if (zerop (length closing))
154 (indent-relative-maybe))))
156 (defun LaTeX-today nil
157 "Return a string representing todays date according to flavor."
159 (let ((ctime-string (current-time-string))
160 (month-alist '(("Jan". "01")
173 "^\\S-+\\s-+\\(\\S-+\\)\\s-+\\(\\S-+\\)\\s-+\\S-+\\s-+\\(\\S-+\\)"
175 (let ((year (substring ctime-string (match-beginning 3) (match-end 3)))
176 (month (substring ctime-string (match-beginning 1) (match-end 1)))
177 (day (substring ctime-string (match-beginning 2) (match-end 2))))
178 (if (assoc month month-alist)
180 (setq month (cdr (assoc month month-alist)))
181 (if (> 2 (length day))
182 (setq day (concat "0" day)))))
183 (format "%s-%s-%s" year month day))))
185 ;;; letter.el ends here