auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-devel] [PATCH] Add cleveref style support.


From: Matthew Leach
Subject: [AUCTeX-devel] [PATCH] Add cleveref style support.
Date: Mon, 13 Oct 2014 18:18:51 +0100

* style/cleveref.el: New file.
---
Hello,

This patch adds a new style file for cleveref support.  I've included
support for the most used cleveref macros, a new argument function
that prompts the user for a series of labels and package options.

I notice that \cref and friends aren't highlighted as keywords by
font-lock.  Do I need to provide a hints to font-lock, such as is done
in style/babel.el?

Any comments welcome.

Matt

Changelog Entry:

2014-10-13  Matthew Leach  <address@hidden>

        * style/cleveref.el: New file.

 Makefile.in       |  2 +-
 style/cleveref.el | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 style/cleveref.el

diff --git a/Makefile.in b/Makefile.in
index efdc405..583b6e7 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -134,7 +134,7 @@ STYLESRC = style/prosper.el \
           style/acronym.el   style/xparse.el    style/fancyvrb.el \
           style/tabulary.el  style/fontspec.el  style/unicode-math.el \
           style/luacode.el   style/metalogo.el  style/english.el \
-          style/exercise.el  style/plext.el
+          style/exercise.el  style/plext.el     style/cleveref.el
 STYLEELC = $(STYLESRC:.el=.elc)
 
 CLEANFILES = $(AUCELC) $(STYLEELC) $(MULEELC)
diff --git a/style/cleveref.el b/style/cleveref.el
new file mode 100644
index 0000000..d9f74f1
--- /dev/null
+++ b/style/cleveref.el
@@ -0,0 +1,73 @@
+;;; cleveref.el --- Style hook for the `cleveref.sty' package.
+
+;; Copyright (C) 2014 Free Software Foundation, Inc.
+
+;; Author: Matthew Leach <address@hidden>
+;; Maintainer: address@hidden
+;; Created: 13/10/2014
+
+;; 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 3, 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
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; 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.
+
+;;; Code
+
+(defun TeX-arg-multiple-labels (optional &optional prompt definition)
+  "Prompt for a series of labels completing with known labels.
+If OPTIONAL is non-nil, insert the resulting value as an optional
+argument, otherwise as a mandatory one.  Use PROMPT as the prompt
+string.  If DEFINITION is non-nil, add each chosen label to the
+list of defined labels."
+  (let ((all-refs "")
+        (first-ref t))
+    (while
+        (progn
+          (let ((label (completing-read
+                        (concat (TeX-argument-prompt optional prompt "Key" 
(not first-ref))
+                                (unless first-ref " (\"\" to finish): "))
+                        (LaTeX-label-list))))
+            (unless (string-equal "" label)
+              (when definition
+                (LaTeX-add-labels label))
+              (setq all-refs
+                    (concat all-refs (unless first-ref ",") label))
+              (setq first-ref nil)
+              t))))
+    (TeX-argument-insert all-refs optional optional)))
+
+(TeX-add-style-hook
+ "cleveref"
+ (lambda ()
+   (TeX-add-symbols
+    '("cref" TeX-arg-multiple-labels)
+    '("Cref" TeX-arg-multiple-labels)
+    '("crefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
+    '("Crefrange" (TeX-arg-label "key (first)") (TeX-arg-label "Key (last)"))
+    '("cpageref" TeX-arg-multiple-labels)
+    '("Cpageref" TeX-arg-multiple-labels)
+    '("cpagerefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key 
(last)"))
+    '("Cpagerefrange" (TeX-arg-label "Key (first)") (TeX-arg-label "Key 
(last)"))
+    '("cref*" TeX-arg-multiple-labels)
+    '("Cref*" TeX-arg-multiple-labels)
+    '("crefrange*" (TeX-arg-label "Key (first)") (TeX-arg-label "Key (last)"))
+    '("Crefrange*" (TeX-arg-label "Key (first)") (TeX-arg-label "Key 
(last)"))))
+ LaTeX-dialect)
+
+(defvar LaTeX-cleveref-package-options
+  '("capitalise" "nameinlink" "noabbrev" "poorman")
+    "Package options for the cleveref package.")
+
+;;; cleveref.el ends here.
-- 
2.1.2




reply via email to

[Prev in Thread] Current Thread [Next in Thread]