Initial Commit
[packages] / xemacs-packages / auctex / style / cleveref.el
1 ;;; cleveref.el --- Style hook for the `cleveref.sty' package.
2
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
4
5 ;; Author: Matthew Leach <matthew@mattleach.net>
6 ;; Maintainer: auctex-devel@gnu.org
7 ;; Created: 13/10/2014
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 (defun TeX-arg-cleveref-multiple-labels (optional &optional prompt definition)
29   "Prompt for a series of labels completing with known labels.
30 If OPTIONAL is non-nil, insert the resulting value as an optional
31 argument, otherwise as a mandatory one.  Use PROMPT as the prompt
32 string.  If DEFINITION is non-nil, add each chosen label to the
33 list of defined labels."
34   (let* ((labels (TeX-completing-read-multiple
35                   (TeX-argument-prompt optional prompt "Keys")
36                   (LaTeX-label-list)))
37          (labels-string (mapconcat 'identity labels ",")))
38     (when definition
39       (apply 'LaTeX-add-labels labels))
40     (TeX-argument-insert labels-string optional optional)))
41
42 (TeX-add-style-hook
43  "cleveref"
44  (lambda ()
45    (TeX-add-symbols
46     '("cref" TeX-arg-cleveref-multiple-labels)
47     '("Cref" TeX-arg-cleveref-multiple-labels)
48     '("crefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
49     '("Crefrange" (TeX-arg-label "key (first)") (TeX-arg-label "Key (last)"))
50     '("cpageref" TeX-arg-cleveref-multiple-labels)
51     '("Cpageref" TeX-arg-cleveref-multiple-labels)
52     '("cpagerefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
53     '("Cpagerefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
54     '("cref*" TeX-arg-cleveref-multiple-labels)
55     '("Cref*" TeX-arg-cleveref-multiple-labels)
56     '("crefrange*" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
57     '("Crefrange*" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
58     '("namecref" TeX-arg-label)
59     '("nameCref" TeX-arg-label)
60     '("lnamecref" TeX-arg-label)
61     '("namecrefs" TeX-arg-label)
62     '("nameCrefs" TeX-arg-label)
63     '("lnamecrefs" TeX-arg-label)
64     '("labelcref" TeX-arg-cleveref-multiple-labels)
65     '("labelcpageref" TeX-arg-cleveref-multiple-labels))
66
67    ;; These macros aren't used particularly often during the course of
68    ;; normal referencing.
69    (TeX-declare-expert-macros
70     "cleveref"
71     "namecref" "nameCref" "lnamecref" "namecrefs" "nameCrefs"
72     "lnamecrefs" "labelcref" "labelcpageref")
73
74    ;; Fontification
75    (when (and (fboundp 'font-latex-add-keywords)
76               (fboundp 'font-latex-set-syntactic-keywords)
77               (eq TeX-install-font-lock 'font-latex-setup))
78      (font-latex-add-keywords '(("cref" "*{")
79                                 ("Cref" "*{")
80                                 ("crefrange" "*{{")
81                                 ("Crefrange" "*{{")
82                                 ("cpageref" "{")
83                                 ("Cpageref" "{")
84                                 ("cpagerefrange" "{{")
85                                 ("Cpagerefrange" "{{")
86                                 ("namecref" "{")
87                                 ("nameCref" "{")
88                                 ("lnamecref" "{")
89                                 ("namecrefs" "{")
90                                 ("nameCrefs" "{")
91                                 ("lnamecrefs" "{")
92                                 ("labelcref" "{")
93                                 ("labelcpageref" "{"))
94                               'reference)
95      ;; For syntactic fontification, e.g. verbatim constructs.
96      (font-latex-set-syntactic-keywords)))
97  LaTeX-dialect)
98
99 (defvar LaTeX-cleveref-package-options
100   '("capitalise" "nameinlink" "noabbrev" "poorman")
101     "Package options for the cleveref package.")
102
103 ;;; cleveref.el ends here.