auctex / style / babel.el

;;; babel.el --- AUCTeX style for `babel.sty'

;; Copyright (C) 2005 Free Software Foundation, Inc.

;; Author: Ralf Angeli <>
;; Maintainer:
;; Created: 2005-05-29
;; Keywords: tex

;; This file is part of AUCTeX.

;; AUCTeX is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.

;; AUCTeX is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with AUCTeX; see the file COPYING.  If not, write to the Free
;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
;; 02110-1301, USA.

;;; Commentary:

;; This file adds support for `babel.sty'.

;;; Code:

(defvar LaTeX-babel-language-list
  '("acadian" "afrikaans" "american" "austrian""bahasa" "basque" "brazil"
    "brazilian" "breton" "british" "bulgarian" "canadian" "canadien"
    "catalan" "croatian" "czech" "danish" "dutch" "english" "esperanto"
    "estonian" "finnish" "francais" "frenchb" "french" "galician"
    "german" "germanb" "greek" "polutonikogreek" "hebrew" "hungarian"
    "icelandic" "irish" "italian" "latin" "lowersorbian" "magyar"
    "naustrian" "ngerman" "norsk" "samin" "nynorsk" "polish" "portuges"
    "portuguese" "romanian" "russian" "scottish" "serbian" "slovak"
    "slovene" "spanish" "swedish" "turkish" "ukrainian" "uppersorbian"
    "welsh" "UKenglish" "USenglish")
  "List of languages supported by the babel LaTeX package.")

(if (fboundp 'defvaralias)
    (defvaralias 'LaTeX-babel-package-options 'LaTeX-babel-language-list)
  (defvar LaTeX-babel-package-options LaTeX-babel-language-list
    "Package options for the babel package."))

(defun LaTeX-babel-active-languages ()
  "Return a list of languages used in the document."
  (let (active-languages)
    (dolist (elt LaTeX-babel-language-list)
      (when (member elt TeX-active-styles)
	(add-to-list 'active-languages (list elt))))

(defun TeX-arg-babel-lang (optional &optional prompt)
  "Prompt for a language with completion and insert it as an argument."
   (completing-read "Language: " (LaTeX-babel-active-languages)) nil))

(defun LaTeX-env-babel-lang (env)
  "Prompt for a language and insert it as an argument of ENV."
   env (format "{%s}" (completing-read "Language: "

 (lambda ()
   ;; New symbols
    '("selectlanguage" TeX-arg-babel-lang)
    '("foreignlanguage" TeX-arg-babel-lang t)
    '("iflanguage" TeX-arg-babel-lang t nil)
    '("useshorthands" t)
    '("defineshorthand" t nil)
    '("aliasshorthand" t nil)
    '("languageshorthands" TeX-arg-babel-lang)
    '("shorthandon" t)
    '("shorthandoff" t)
    '("languageattribute" TeX-arg-babel-lang t))
   ;; New environments
    '("otherlanguage" LaTeX-env-babel-lang)
    '("otherlanguage*" LaTeX-env-babel-lang)
    '("hyphenrules" LaTeX-env-babel-lang))
   ;; Fontification
   (when (and (featurep 'font-latex)
	      (eq TeX-install-font-lock 'font-latex-setup))
     (mapcar (lambda (keyword)
	       (add-to-list 'font-latex-match-function-keywords-local keyword))
	       ;; "foreignlanguage" ; Enable once we support proper
	       ;; "iflanguage"      ; highlighting of multiple arguments.
     (add-to-list 'font-latex-match-variable-keywords-local "defineshorthand")
     (add-to-list 'font-latex-match-variable-keywords-local "aliasshorthand")
     (add-to-list 'font-latex-match-variable-keywords-local "languageattribute")
     ;; Tell font-lock about the update.
     (setq font-lock-set-defaults nil)

;;; babel.el ends here