auctex-diffs
[Top][All Lists]
Advanced

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

[AUCTeX-diffs] [elpa] externals/auctex 40ba5b6 37/67: Improve handling o


From: Tassilo Horn
Subject: [AUCTeX-diffs] [elpa] externals/auctex 40ba5b6 37/67: Improve handling of `TeX-insert-macro-default-style' in styles
Date: Fri, 8 Feb 2019 11:40:36 -0500 (EST)

branch: externals/auctex
commit 40ba5b6ca1623bc270d14eaeb5a9f6a197a3ced2
Author: Arash Esbati <address@hidden>
Commit: Arash Esbati <address@hidden>

    Improve handling of `TeX-insert-macro-default-style' in styles
    
    * latex.el (LaTeX-check-insert-macro-default-style): Add new
    macro.  This macro is intended for more complex functions in style
    files querying multiple optional and mandatory arguments and
    obeying the values of `TeX-insert-macro-default-style' and
    `current-prefix-arg'.
    
    * tex.el (TeX-parse-arguments): Add a comment about the new macro.
    
    * style/bicaption.el (LaTeX-arg-bicaption-bicaption):
    * style/caption.el (LaTeX-arg-caption-captionbox):
    * style/color.el (TeX-arg-color, TeX-arg-color-fcolorbox):
    * style/floatrow.el (LaTeX-floatrow-arg-floatbox):
    * style/xcolor.el (TeX-arg-xcolor-definecolor)
    (TeX-arg-xcolor-definecolorset, TeX-arg-xcolor)
    (TeX-arg-xcolor-fcolorbox): Use
    `LaTeX-check-insert-macro-default-style'.
---
 latex.el           |  20 +++++
 style/bicaption.el |  30 +++++---
 style/caption.el   |  31 ++++----
 style/color.el     | 218 ++++++++++++++++++++++++++++-------------------------
 style/floatrow.el  |  45 ++++++-----
 style/xcolor.el    |  64 ++++++++++------
 tex.el             |   3 +
 7 files changed, 243 insertions(+), 168 deletions(-)

diff --git a/latex.el b/latex.el
index b1d2901..3b8cc5c 100644
--- a/latex.el
+++ b/latex.el
@@ -6620,6 +6620,26 @@ function would return non-nil and `(match-string 1)' 
would return
                      (1+ any-col)
                    beg-col))))))))
 
+;; Utilities:
+
+(defmacro LaTeX-check-insert-macro-default-style (&rest body)
+  "Check for values of `TeX-insert-macro-default-style' and 
`current-prefix-arg'.
+This is a utility macro with code taken from
+`TeX-parse-arguments'.  It should be used inside more complex
+function within AUCTeX style files where optional and mandatory
+arguments are queried and inserted.  For examples, check the
+functions `TeX-arg-color' (style/color.el) or
+`LaTeX-arg-bicaption-bicaption' (style/bicaption.el)."
+  `(unless (if (eq TeX-insert-macro-default-style 'show-all-optional-args)
+              (equal current-prefix-arg '(4))
+            (or
+             (and (eq TeX-insert-macro-default-style 'show-optional-args)
+                  (equal current-prefix-arg '(4)))
+             (and (eq TeX-insert-macro-default-style 'mandatory-args-only)
+                  (null (equal current-prefix-arg '(4))))
+             last-optional-rejected))
+     ,@body))
+
 (provide 'latex)
 
 ;;; latex.el ends here
diff --git a/style/bicaption.el b/style/bicaption.el
index 47b139b..7bf4d1a 100644
--- a/style/bicaption.el
+++ b/style/bicaption.el
@@ -1,6 +1,6 @@
 ;;; bicaption.el --- AUCTeX style for `bicaption.sty' (v1.1-158)
 
-;; Copyright (C) 2016, 2017 Free Software Foundation, Inc.
+;; Copyright (C) 2016--2018 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <address@hidden>
 ;; Maintainer: address@hidden
@@ -34,6 +34,9 @@
 
 ;;; Code:
 
+(eval-when-compile
+  (require 'latex))
+
 (defvar LaTeX-bicaption-key-val-options
   '(("bi-lang" ("first" "second" "both"))
     ("bi-singlelinecheck" ("false" "no" "off" "0" "true" "yes" "on" "1"))
@@ -50,6 +53,9 @@ If CAP-BOX is non-nil, also query and include optional 
arguments
 for the box command.  If LABEL-INSIDE is non-nil, insert \label
 inside the first mandatory argument, otherwise after all
 arguments."
+  ;; icaption   [<list entry #1>]{<heading #1>}[<list entry #2>]{<heading #2>}
+  ;; icaptionbox[<list entry #1>]{<heading #1>}[<list entry #2>]{<heading #2>}
+  ;;              [<width>][<inner-pos>]{<contents>}
   (let* (;; isubcaption needs an environment, "minipage" will be
         ;; popular.  If so, check next higher environment to find out
         ;; where we are
@@ -100,15 +106,19 @@ arguments."
     (when cap-box
       (let* ((TeX-arg-opening-brace "[")
             (TeX-arg-closing-brace "]")
-            (width (completing-read (TeX-argument-prompt t nil "Width")
-                                    (mapcar (lambda (elt) (concat TeX-esc (car 
elt)))
-                                            (LaTeX-length-list))))
-            (inpos (if (and width (not (string-equal width "")))
-                       (completing-read (TeX-argument-prompt t nil "Inner 
position")
-                                        '("c" "l" "r" "s"))
-                     "")))
-       (TeX-argument-insert width t)
-       (TeX-argument-insert inpos t)))
+            (last-optional-rejected nil)
+            (width (LaTeX-check-insert-macro-default-style
+                    (completing-read (TeX-argument-prompt t nil "Width")
+                                     (mapcar (lambda (elt) (concat TeX-esc 
(car elt)))
+                                             (LaTeX-length-list)))))
+            (last-optional-rejected (and width (string= width "")))
+            (inpos (LaTeX-check-insert-macro-default-style
+                    (if (and width (not (string-equal width "")))
+                        (completing-read (TeX-argument-prompt t nil "Inner 
position")
+                                         '("c" "l" "r" "s"))
+                      ""))))
+       (and width (TeX-argument-insert width t))
+       (and inpos (TeX-argument-insert inpos t))))
     (LaTeX-fill-paragraph)
     ;; Insert label -- a new line is inserted only if label is there:
     (when (and (not label-inside) (not star)
diff --git a/style/caption.el b/style/caption.el
index f23e59d..0b2cac7 100644
--- a/style/caption.el
+++ b/style/caption.el
@@ -1,6 +1,6 @@
 ;;; caption.el --- AUCTeX style for `caption.sty' (v3.3-111)
 
-;; Copyright (C) 2015--2017 Free Software Foundation, Inc.
+;; Copyright (C) 2015--2018 Free Software Foundation, Inc.
 
 ;; Author: Arash Esbati <address@hidden>
 ;; Maintainer: address@hidden
@@ -35,7 +35,8 @@
 ;;; Code:
 
 (eval-when-compile
-  (require 'cl-lib))
+  (require 'cl-lib)
+  (require 'latex))
 
 ;; Needed for auto-parsing.
 (require 'tex)
@@ -176,10 +177,10 @@ in `caption'-completions."
              (when (and (string-equal key "labelformat")
                         (boundp 'LaTeX-subcaption-key-val-options))
                (cl-pushnew (list "subrefformat"
-                                 (TeX-delete-duplicate-strings (apply #'append 
(list val) val-match)))
+                                 (TeX-delete-duplicate-strings (apply #'append 
(list val) val-match)))
                            opts :test #'equal))
              (cl-pushnew (list key (TeX-delete-duplicate-strings (apply 
#'append (list val) val-match)))
-                         opts :test #'equal))
+                         opts :test #'equal))
          (cl-pushnew (list key (list val)) opts :test #'equal)))
       (setq LaTeX-caption-key-val-options-local (copy-alist opts))))
   ;; Support for environments defined with newfloat.sty: These
@@ -255,15 +256,19 @@ caption, insert only a caption."
     (insert TeX-grcl))
   (let* ((TeX-arg-opening-brace "[")
         (TeX-arg-closing-brace "]")
-        (width (completing-read (TeX-argument-prompt t nil "Width")
-                                (mapcar (lambda (elt) (concat TeX-esc (car 
elt)))
-                                        (LaTeX-length-list))))
-        (inpos (if (and width (not (string-equal width "")))
-                   (completing-read (TeX-argument-prompt t nil "Inner 
position")
-                                    '("c" "l" "r" "s"))
-                 "")))
-    (TeX-argument-insert width t)
-    (TeX-argument-insert inpos t))
+        (last-optional-rejected nil)
+        (width (LaTeX-check-insert-macro-default-style
+                (completing-read (TeX-argument-prompt t nil "Width")
+                                 (mapcar (lambda (elt) (concat TeX-esc (car 
elt)))
+                                         (LaTeX-length-list)))))
+        (last-optional-rejected (and width (string= width "")))
+        (inpos (LaTeX-check-insert-macro-default-style
+                (if (and width (not (string-equal width "")))
+                    (completing-read (TeX-argument-prompt t nil "Inner 
position")
+                                     '("c" "l" "r" "s"))
+                  ""))))
+    (and width (TeX-argument-insert width t))
+    (and inpos (TeX-argument-insert inpos t)))
   ;; Fill the paragraph before inserting {}.  We can use
   ;; `LaTeX-fill-paragraph' without messing up the code since
   ;;



reply via email to

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