"Fossies" - the Fresh Open Source Software Archive

Member "auctex-12.3/style/dinbrief.el" (18 Oct 2020, 9323 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 "dinbrief.el": 12.2_vs_12.3.

    1 ;;; dinbrief.el --- Special code for LaTeX-Style dinbrief.
    2 
    3 ;; Copyright (C) 1994, 2013, 2014, 2018, 2020 Free Software Foundation, Inc.
    4 
    5 ;; Author: Werner Fink <werner@suse.de>
    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 ;;; dinbrief.el - Special code for LaTeX class dinbrief.
   27 
   28 ;;; Commentary:
   29 
   30 ;; LaTeX Class: dinbrief.cls
   31 
   32 ;;; Code:
   33 
   34 (require 'tex)
   35 
   36 (TeX-add-style-hook
   37  "dinbrief"
   38  (lambda ()
   39    (add-hook 'LaTeX-document-style-hook
   40          'LaTeX-dinbrief-style)
   41    (LaTeX-add-environments
   42     '("letter" LaTeX-dinbrief-env-recipient)
   43     "dinquote")
   44    (TeX-add-symbols
   45     '("address" "Absender")
   46     '("postremark" "Postvermerk")
   47     '("date" "Datum")
   48     '("subject" "Betreff")
   49     '("handling" "Behandlungsvermerk")
   50     '("cc" "Verteiler")
   51     '("place" "Heutiger Ort")
   52     "makelabels"
   53     "nowindowrules"
   54     "windowrules"
   55     "nowindowtics"
   56     "windowtics"
   57     "disabledraftstandard"
   58     "enabledraftstandard"
   59     "centeraddress"
   60     "normaladdress"
   61     '("encl" "Anlagen: ")
   62     '("backaddress" "Retouradresse")
   63     '("signature" "Unterschrift")
   64     '("opening" "Anrede")
   65     '("closing" "Schluss")))
   66  LaTeX-dialect)
   67 
   68 (defmacro LaTeX-dinbrief-insert (&rest args)
   69   "Insert text ignoring active markers."
   70   `(progn (if mark-active (deactivate-mark))
   71      (insert ,@args)))
   72 
   73 (defun LaTeX-dinbrief-style ()
   74   "Insert some useful packages for writing german letters."
   75   (let ((func (if (fboundp 'indent-relative-first-indent-point)
   76           'indent-relative-first-indent-point
   77         'indent-relative-maybe)))
   78     (save-excursion
   79       (goto-char (point-min)) ; insert before \begin{document}
   80       (if (re-search-forward ".begin.document." (point-max) t)
   81           (beginning-of-line 1))
   82       (open-line 2)
   83       (funcall func)
   84       (LaTeX-dinbrief-insert TeX-esc "usepackage"
   85                  LaTeX-optop "latin1,utf8" LaTeX-optcl
   86                  TeX-grop "inputenc" TeX-grcl)
   87       (newline-and-indent)
   88       (LaTeX-dinbrief-insert TeX-esc "usepackage"
   89                  LaTeX-optop "T1" LaTeX-optcl
   90                  TeX-grop "fontenc" TeX-grcl)
   91       (funcall func)
   92       (LaTeX-dinbrief-insert TeX-esc "usepackage"
   93                  TeX-grop "ngerman" TeX-grcl))
   94     (TeX-run-style-hooks "inputenc" "fontenc" "ngerman")))
   95 
   96 (defun LaTeX-dinbrief-env-recipient (environment)
   97   "Insert ENVIRONMENT and prompt for recipient and address."
   98   (let ((sender (LaTeX-dinbrief-sender))
   99     (recipient (TeX-read-string "Empfänger: "))
  100     (address (LaTeX-dinbrief-recipient))
  101     (date (TeX-read-string "Datum: " (LaTeX-dinbrief-today)))
  102     (postremark (TeX-read-string "Postvermerk: "))
  103     (fenster (TeX-read-string "Fenster (ja/nein): "))
  104     (vermerk (TeX-read-string "Behandlungsvermerk: "))
  105     (verteil (TeX-read-string "Verteiler: "))
  106     (betreff (TeX-read-string "Betreff: "))
  107     (opening (TeX-read-string "Anrede: "))
  108     (closing (TeX-read-string "Schluss: "))
  109     (signature (TeX-read-string "Unterschrift: "))
  110     (anlage (TeX-read-string "Anlagen: "))
  111     (func (if (fboundp 'indent-relative-first-indent-point)
  112           'indent-relative-first-indent-point
  113         'indent-relative-maybe)))
  114     (if (string= fenster "ja")
  115     (progn
  116       (LaTeX-dinbrief-insert TeX-esc "enabledraftstandard")
  117       (newline-and-indent)
  118       (LaTeX-dinbrief-insert TeX-esc "centeraddress")
  119       (newline-and-indent)
  120       (LaTeX-dinbrief-insert TeX-esc "nowindowrules")
  121       (newline-and-indent)
  122       (LaTeX-dinbrief-insert TeX-esc "windowtics")
  123       (newline-and-indent)
  124       (let ((retouradr (TeX-read-string "Retouradresse: " sender)))
  125         (newline-and-indent)
  126         (if (not (zerop (length retouradr)))
  127         (progn
  128           (if mark-active (deactivate-mark))
  129           (LaTeX-dinbrief-insert TeX-esc "backaddress" TeX-grop retouradr TeX-grcl)
  130           (newline-and-indent)))))
  131       (LaTeX-dinbrief-insert TeX-esc "enabledraftstandard")
  132       (newline-and-indent)
  133       (LaTeX-dinbrief-insert TeX-esc "centeraddress")
  134       (newline-and-indent)
  135       (LaTeX-dinbrief-insert TeX-esc "nowindowrules")
  136       (newline-and-indent)
  137       (LaTeX-dinbrief-insert TeX-esc "windowtics"))
  138     (newline-and-indent)
  139     (if (not (zerop (length signature)))
  140     (progn
  141       (LaTeX-dinbrief-insert TeX-esc "signature" TeX-grop signature TeX-grcl)
  142       (newline-and-indent)))
  143     (if (not (zerop (length date)))
  144     (progn
  145       (LaTeX-dinbrief-insert TeX-esc "date" TeX-grop date TeX-grcl)
  146       (newline-and-indent)))
  147     (newline-and-indent)
  148 
  149     (let ((indentation (current-column)))
  150       (LaTeX-insert-environment
  151        environment
  152        (concat TeX-grop recipient
  153            (if (not (zerop (length address)))
  154            (concat
  155             (if (not (zerop (length recipient)))
  156             (concat " " TeX-esc TeX-esc " "))
  157             address))
  158            TeX-grcl))
  159       (save-excursion           ; Fix indentation of address
  160     (if (search-backward TeX-grcl nil 'move)
  161         (let ((addr-end (point-marker)))
  162           (if (search-backward TeX-grop nil 'move)
  163           (let ((addr-column (current-column)))
  164             (while (search-forward
  165                 (concat TeX-esc TeX-esc)
  166                 (marker-position addr-end) 'move)
  167               (progn
  168             (newline)
  169             (indent-to addr-column))))))))
  170       (LaTeX-dinbrief-insert "\n")
  171       (indent-to indentation))
  172     (if (not (zerop (length postremark)))
  173     (progn
  174       (LaTeX-dinbrief-insert TeX-esc "postremark" TeX-grop postremark TeX-grcl)
  175       (newline-and-indent)))
  176     (if (not (zerop (length betreff)))
  177     (progn
  178       (LaTeX-dinbrief-insert TeX-esc "subject" TeX-grop)
  179       (LaTeX-dinbrief-insert betreff TeX-grcl)
  180       (newline-and-indent)))
  181     (if (not (zerop (length vermerk)))
  182     (progn
  183       (LaTeX-dinbrief-insert TeX-esc "handling" TeX-grop vermerk TeX-grcl)
  184       (newline-and-indent)))
  185     (if (not (zerop (length verteil)))
  186     (progn
  187       (LaTeX-dinbrief-insert TeX-esc "cc" TeX-grop verteil TeX-grcl)
  188       (newline-and-indent)))
  189     (if (not (zerop (length anlage)))
  190     (progn
  191       (LaTeX-dinbrief-insert TeX-esc "encl" TeX-grop anlage TeX-grcl)
  192       (newline-and-indent)))
  193     (LaTeX-dinbrief-insert TeX-esc "opening"
  194                TeX-grop
  195                (if (zerop (length opening))
  196                    (concat TeX-esc " ")
  197                  opening)
  198                TeX-grcl "\n")
  199 
  200     (funcall func)
  201     (save-excursion
  202       (LaTeX-dinbrief-insert "\n" TeX-esc "closing"
  203                  TeX-grop
  204                  (if (zerop (length closing))
  205                  (concat TeX-esc " ")
  206                    closing)
  207                  TeX-grcl "\n")
  208       (funcall func))))
  209 
  210 (defun LaTeX-dinbrief-sender ()
  211   "Read and write the senders address."
  212   (interactive)
  213   (let ((name (TeX-read-string "Absender: " (user-full-name)))
  214     (str  (TeX-read-string "Meine Strasse:  "))
  215     (ort  (TeX-read-string "Mein Wohnort:  ")))
  216     (if (not (zerop (length name)))
  217     (progn
  218       (goto-char (point-min)) ; insert before \end{document}
  219       (if (re-search-forward ".end.document." (point-max) t)
  220           (beginning-of-line 1))
  221       (forward-line -1)
  222       (LaTeX-dinbrief-insert TeX-esc "address" TeX-grop name)
  223       (if (not (zerop (length str)))
  224           (progn
  225         (LaTeX-dinbrief-insert " " TeX-esc TeX-esc)
  226         (newline-and-indent)
  227         (LaTeX-dinbrief-insert str)))
  228       (if (not (zerop (length ort)))
  229           (progn
  230         (LaTeX-dinbrief-insert " " TeX-esc "par")
  231         (newline-and-indent)
  232         (LaTeX-dinbrief-insert ort)))
  233       (LaTeX-dinbrief-insert TeX-grcl)
  234       (newline-and-indent)
  235       (concat name ", " str ", " ort)))))
  236 
  237 (defun LaTeX-dinbrief-recipient ()
  238   "Read and return the recipient address."
  239   (interactive)
  240   (let ((str  (TeX-read-string "Wohnhaft in Strasse:  "))
  241     (ort  (TeX-read-string "Aus der Ortschaft:  ")))
  242     (if (not (zerop (length str)))
  243     (if (not (zerop (length ort)))
  244         (concat str " " TeX-esc TeX-esc " " ort)
  245       str)
  246       (if (not (zerop (length ort)))
  247       ort))))
  248 
  249 (defun LaTeX-dinbrief-today ()
  250   "Return a string representing todays date according to flavor."
  251   (interactive)
  252    (let ((ctime-string (current-time-string))
  253     (month-alist '(("Jan" . "Januar")
  254                ("Feb" . "Februar")
  255                ("Mar" . "M\\\"arz")
  256                ("Apr" . "April")
  257                ("May" . "Mai")
  258                ("Jun" . "Juni")
  259                ("Jul" . "Juli")
  260                ("Aug" . "August")
  261                ("Sep" . "September")
  262                ("Oct" . "Oktober")
  263                ("Nov" . "November")
  264                ("Dec" . "Dezember"))))
  265     (string-match
  266      "^\\S-+\\s-+\\(\\S-+\\)\\s-+\\(\\S-+\\)\\s-+\\S-+\\s-+\\(\\S-+\\)"
  267      ctime-string)
  268     (let ((year (substring ctime-string (match-beginning 3) (match-end 3)))
  269       (month (substring ctime-string (match-beginning 1) (match-end 1)))
  270       (day (substring ctime-string (match-beginning 2) (match-end 2)))
  271       (place (TeX-read-string "Heutiger Ort: ")))
  272       (if (assoc month month-alist)
  273       (progn
  274         (setq month (cdr (assoc month month-alist)))
  275         (if (> 2 (length day))
  276         (setq day (concat "0" day)))))
  277       (format "%s, den %s. %s %s" place day month year))))
  278 
  279 ;;; dinbrief.el ends here