"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/letter.el" (18 Oct 2020, 5882 Bytes) of package /linux/misc/auctex-12.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Lisp source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "letter.el": 12.2_vs_12.3.

    1 ;;; letter.el - Special code for letter style.
    2 
    3 ;; Copyright (C) 1993, 2012, 2013, 2014, 2018, 2020 Free Software Foundation, Inc.
    4 
    5 ;; Author: Per Abrahamsen <abraham@dina.kvl.dk>
    6 ;; Maintainer: auctex-devel@gnu.org
    7 ;; Keywords: tex
    8 
    9 ;; This file is part of AUCTeX.
   10 
   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)
   14 ;; any later version.
   15 
   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.
   20 
   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
   24 ;; 02110-1301, USA.
   25 
   26 ;;; Code:
   27 
   28 ;; Silence the compiler:
   29 (declare-function font-latex-add-keywords
   30           "font-latex"
   31           (keywords class))
   32 
   33 (defvar LaTeX-letter-class-options
   34   '("a4paper" "a5paper" "b5paper" "letterpaper" "legalpaper" "executivepaper"
   35     "landscape" "10pt" "11pt" "12pt" "oneside" "twoside" "draft" "final"
   36     "leqno" "fleqn")
   37   "Package options for the letter class.")
   38 
   39 ;; You may want to define this in tex-site.el to contain your
   40 ;; organizations address.
   41 (defvar LaTeX-letter-sender-address ""
   42   "Initial value when prompting for a sender address in the letter style.")
   43 
   44 (TeX-add-style-hook
   45  "letter"
   46  (lambda ()
   47    (LaTeX-add-environments
   48     '("letter" LaTeX-env-recipient))
   49    (LaTeX-add-pagestyles "headings" "firstpage")
   50    (setq LaTeX-default-document-environment "letter")
   51    (TeX-add-symbols
   52     '("name" "Sender")
   53     '("address" "Sender address")
   54     '("signature" "Signature")
   55     '("opening" "Opening")
   56     '("closing" "Closing")
   57     "location"
   58     "telephone"
   59     "makelabels"
   60     "stopbreaks"
   61     "startbreaks"
   62     "cc"
   63     "encl"
   64     "ps"
   65     "stopletter"
   66     "returnaddress"
   67     "startlabels"
   68     "mlabel"
   69     "descriptionlabel"
   70     "ccname"
   71     "enclname"
   72     "pagename"
   73     "headtoname")
   74 
   75    ;; Fontification
   76    (when (and (featurep 'font-latex)
   77           (eq TeX-install-font-lock 'font-latex-setup))
   78      (font-latex-add-keywords '(("name" "{")
   79                 ("address" "{")
   80                 ("signature" "{")
   81                 ("opening" "{")
   82                 ("closing" "{")
   83                 ("location" "{")
   84                 ("telephone" "{")
   85                 ("cc" "{")
   86                 ("encl" "{")
   87                 ("ps" "{"))
   88                   'function)))
   89  LaTeX-dialect)
   90 
   91 (defun LaTeX-env-recipient (environment)
   92   "Insert ENVIRONMENT and prompt for recipient and address."
   93   (let ((sender (TeX-read-string "Sender: " (user-full-name)))
   94     (sender-address (TeX-read-string "Sender address: "
   95                      LaTeX-letter-sender-address))
   96     (recipient (TeX-read-string "Recipient: "))
   97     (address (TeX-read-string "Recipient address: "))
   98     (signature (TeX-read-string "Signature: "))
   99     (opening (TeX-read-string "Opening: "))
  100     (closing (TeX-read-string "Closing: "))
  101     (date (TeX-read-string "Date: " (LaTeX-today)))
  102     (func (if (fboundp 'indent-relative-first-indent-point)
  103           'indent-relative-first-indent-point
  104         'indent-relative-maybe)))
  105 
  106     (insert TeX-esc "name" TeX-grop sender TeX-grcl)
  107     (newline-and-indent)
  108     (if (not (zerop (length sender-address)))
  109     (progn
  110       (setq LaTeX-letter-sender-address sender-address)
  111       (insert TeX-esc "address" TeX-grop sender-address TeX-grcl)
  112       (newline-and-indent)))
  113     (if (not (zerop (length signature)))
  114     (progn
  115       (insert TeX-esc "signature" TeX-grop signature TeX-grcl)
  116       (newline-and-indent)))
  117     (if (not (zerop (length date)))
  118     (progn
  119       (insert TeX-esc "renewcommand" TeX-grop TeX-esc "today" TeX-grcl
  120           TeX-grop date TeX-grcl)
  121       (newline-and-indent)))
  122     (newline-and-indent)
  123 
  124     (let ((indentation (current-column)))
  125       (LaTeX-insert-environment
  126        environment
  127        (concat TeX-grop recipient
  128            (if (not (zerop (length address)))
  129            (concat
  130             (if (not (zerop (length recipient)))
  131             (concat " " TeX-esc TeX-esc " "))
  132             address))
  133            TeX-grcl))
  134       (save-excursion           ; Fix indentation of address
  135     (if (search-backward TeX-grcl nil 'move)
  136         (let ((addr-end (point-marker)))
  137           (if (search-backward TeX-grop nil 'move)
  138           (let ((addr-column (current-column)))
  139             (while (search-forward
  140                 (concat TeX-esc TeX-esc)
  141                 (marker-position addr-end) 'move)
  142               (progn
  143             (newline)
  144             (indent-to addr-column))))))))
  145       (insert "\n")
  146       (indent-to indentation))
  147     (insert TeX-esc "opening"
  148         TeX-grop
  149         (if (zerop (length opening))
  150         (concat TeX-esc " ")
  151           opening)
  152         TeX-grcl "\n")
  153 
  154     (funcall func)
  155     (save-excursion
  156       (insert "\n" TeX-esc "closing"
  157           TeX-grop
  158           (if (zerop (length closing))
  159           (concat TeX-esc " ")
  160         closing)
  161           TeX-grcl "\n")
  162       (funcall func))))
  163 
  164 (defun LaTeX-today nil
  165   "Return a string representing todays date according to flavor."
  166   (interactive)
  167   (let ((ctime-string (current-time-string))
  168     (month-alist '(("Jan". "01")
  169                ("Feb" . "02")
  170                ("Mar" . "03")
  171                ("Apr" . "04")
  172                ("May" . "05")
  173                ("Jun" . "06")
  174                ("Jul" . "07")
  175                ("Aug" . "08")
  176                ("Sep" . "09")
  177                ("Oct" . "10")
  178                ("Nov" . "11")
  179                ("Dec" . "12"))))
  180     (string-match
  181      "^\\S-+\\s-+\\(\\S-+\\)\\s-+\\(\\S-+\\)\\s-+\\S-+\\s-+\\(\\S-+\\)"
  182      ctime-string)
  183     (let ((year (substring ctime-string (match-beginning 3) (match-end 3)))
  184       (month (substring ctime-string (match-beginning 1) (match-end 1)))
  185       (day (substring ctime-string (match-beginning 2) (match-end 2))))
  186       (if (assoc month month-alist)
  187       (progn
  188         (setq month (cdr (assoc month month-alist)))
  189         (if (> 2 (length day))
  190         (setq day (concat "0" day)))))
  191       (format "%s-%s-%s" year month day))))
  192 
  193 ;;; letter.el ends here