auctex-diffs
[Top][All Lists]
Advanced

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

[AUCTeX-diffs] GNU AUCTeX branch, master, updated. 66be6d74537e899b93512


From: Mosè Giordano
Subject: [AUCTeX-diffs] GNU AUCTeX branch, master, updated. 66be6d74537e899b9351289940c3da98ee85f769
Date: Thu, 20 Feb 2014 23:20:11 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
       via  66be6d74537e899b9351289940c3da98ee85f769 (commit)
      from  2ebedb8cdc94cca0b941a6173c9825d2a1bfe465 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 66be6d74537e899b9351289940c3da98ee85f769
Author: Mosè Giordano <address@hidden>
Date:   Fri Feb 21 00:17:12 2014 +0100

    Prompt for packages inside LaTeX-env-document.
    
    * latex.el (LaTeX-arg-usepackage-read-packages-with-options): New
    function.  Now options are requested only if at least one package
    has been provided.
    (LaTeX-arg-usepackage-insert): New function.
    (LaTeX-arg-usepackage): Use
    `LaTeX-arg-usepackage-read-packages-with-options' and
    `LaTeX-arg-usepackage-insert'.
    (LaTeX-insert-usepackages): New function.
    (LaTeX-env-document): Use it.
    
    * doc/auctex.texi (Environments): Document new behavior of
    `LaTeX-env-document'.
    
    * doc/changes.texi: Mention it.

diff --git a/ChangeLog b/ChangeLog
index d3e3c55..ba2dcc0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,20 @@
+2014-02-21  Mosè Giordano  <address@hidden>
+
+       * latex.el (LaTeX-arg-usepackage-read-packages-with-options): New
+       function.  Now options are requested only if at least one package
+       has been provided.
+       (LaTeX-arg-usepackage-insert): New function.
+       (LaTeX-arg-usepackage): Use
+       `LaTeX-arg-usepackage-read-packages-with-options' and
+       `LaTeX-arg-usepackage-insert'.
+       (LaTeX-insert-usepackages): New function.
+       (LaTeX-env-document): Use it.
+
+       * doc/auctex.texi (Environments): Document new behavior of
+       `LaTeX-env-document'.
+
+       * doc/changes.texi: Mention it.
+
 2014-02-20  Mosè Giordano  <address@hidden>
 
        * tex.el (TeX-command-extra-options): New customizable variable.
diff --git a/doc/auctex.texi b/doc/auctex.texi
index a6f193f..eb070e7 100644
--- a/doc/auctex.texi
+++ b/doc/auctex.texi
@@ -827,6 +827,9 @@ specific document.  This is achieved by examining your
 @samp{\documentclass} command, and consulting a precompiled list of
 environments available in a large number of styles.
 
+Most of these are described further in the following sections, and you
+may easily specify more.  @xref{Customizing Environments}.
+
 You insert an environment with @kbd{C-c C-e}, and select an environment
 type.  Depending on the environment, @AUCTeX{} may ask more questions
 about the optional parts of the selected environment type.  With
@@ -864,10 +867,11 @@ to @code{frame}, in @file{letter.el} to @code{letter}, 
and in
 @end defvar
 
 If the document is empty, or the cursor is placed at the top of the
-document, @AUCTeX{} will default to insert a `document' environment.
-
-Most of these are described further in the following sections, and you
-may easily specify more.  @xref{Customizing Environments}.
+document, @AUCTeX{} will default to insert a @samp{document} environment
+prompting also for the insertion of @samp{\documentclass} and
address@hidden macros.  You will be prompted for a new package until
+you enter nothing.  If you do not want to insert any @samp{\usepackage}
+at all, just press @key{RET} at the first @samp{Packages} prompt.
 
 @AUCTeX{} distinguishes normal and expert environments.  By default, it
 will offer completion only for normal environments.  This behavior is
diff --git a/doc/changes.texi b/doc/changes.texi
index 6a4b55c..79e4df5 100644
--- a/doc/changes.texi
+++ b/doc/changes.texi
@@ -94,6 +94,10 @@ per file basis using the @code{TeX-command-extra-options} 
option.
 @ifclear rawfile
 @xref{Processor Options}, for details.
 @end ifclear
+
address@hidden
+Now @kbd{C-c C-e document @key{RET}}, in an empty document, prompts for
address@hidden macros in addition to @samp{\documentclass}.
 @end itemize
 
 @heading News since 11.87
diff --git a/latex.el b/latex.el
index b2dad4a..9ecceeb 100644
--- a/latex.el
+++ b/latex.el
@@ -771,7 +771,9 @@ To insert a hook here, you must insert it in the appropiate 
style file.")
 
 (defun LaTeX-env-document (&optional ignore)
   "Create new LaTeX document.
-Also inserts a \\documentclass macro if there's none already
+Also inserts a \\documentclass macro if there's none already and
+prompts for the insertion of \\usepackage macros.
+
 The compatibility argument IGNORE is ignored."
   ;; just assume a single valid \\documentclass, i.e., one not in a
   ;; commented line
@@ -787,6 +789,9 @@ The compatibility argument IGNORE is ignored."
       (TeX-insert-macro "documentclass")
       (LaTeX-newline)
       (LaTeX-newline)
+      ;; Add a newline only if some `\usepackage' has been inserted.
+      (if (LaTeX-insert-usepackages)
+         (LaTeX-newline))
       (LaTeX-newline)
       (end-of-line 0)))
   (LaTeX-insert-environment "document")
@@ -1874,9 +1879,12 @@ OPTIONAL and IGNORE are ignored."
 
 To insert a hook here, you must insert it in the appropiate style file.")
 
-(defun LaTeX-arg-usepackage (optional)
-  "Insert arguments to usepackage.
-OPTIONAL is ignored."
+(defun LaTeX-arg-usepackage-read-packages-with-options ()
+  "Read the packages and the options for the usepackage macro.
+
+If at least one package is provided, this function returns a cons
+cell, whose CAR is the list of packages and the CDR is the string
+of the options, nil otherwise."
   (let* ((TeX-file-extensions '("sty"))
         (crm-separator ",")
         packages var options)
@@ -1891,37 +1899,69 @@ OPTIONAL is ignored."
                                 'texinputs 'global t t))))))
     (setq packages (TeX-completing-read-multiple
                    "Packages: " TeX-global-input-files))
-    ;; Clean up hook before use.
+    ;; Clean up hook before use in `LaTeX-arg-usepackage-insert'.
     (setq LaTeX-after-usepackage-hook nil)
     (mapc 'TeX-run-style-hooks packages)
-    (setq var (if (= 1 (length packages))
-                 (intern (format "LaTeX-%s-package-options" (car packages)))
-               ;; Something like `\usepackage[options]{pkg1,pkg2,pkg3,...}' is
-               ;; allowed (provided that pkg1, pkg2, pkg3, ... accept same
-               ;; options).  When there is more than one package, set `var' to
-               ;; a dummy value so next `if' enters else form.
-               t))
-    (if (or (and (boundp var)
-                (listp (symbol-value var)))
-           (fboundp var))
-       (if (functionp var)
-           (setq options (funcall var))
-         (when (symbol-value var)
-           (setq options
-                 (mapconcat 'identity
-                            (TeX-completing-read-multiple
-                             "Options: " (mapcar 'list (symbol-value var)))
-                            ","))))
-      (setq options (read-string "Options: ")))
-    (unless (zerop (length options))
-      (let ((opts (LaTeX-listify-package-options options)))
-       (mapc (lambda (elt)
-               (TeX-add-to-alist 'LaTeX-provided-package-options
-                                 (list (cons elt opts))))
-             packages))
-      (insert LaTeX-optop options LaTeX-optcl))
-    (insert TeX-grop (mapconcat 'identity packages ",") TeX-grcl)
-    (run-hooks 'LaTeX-after-usepackage-hook)))
+    ;; Prompt for options only if at least one package has been supplied, 
return
+    ;; nil otherwise.
+    (unless (equal packages '(""))
+      (setq var (if (= 1 (length packages))
+                   (intern (format "LaTeX-%s-package-options" (car packages)))
+                 ;; Something like `\usepackage[options]{pkg1,pkg2,pkg3,...}' 
is
+                 ;; allowed (provided that pkg1, pkg2, pkg3, ... accept same
+                 ;; options).  When there is more than one package, set `var' 
to
+                 ;; a dummy value so next `if' enters else form.
+                 t))
+      (if (or (and (boundp var)
+                  (listp (symbol-value var)))
+             (fboundp var))
+         (if (functionp var)
+             (setq options (funcall var))
+           (when (symbol-value var)
+             (setq options
+                   (mapconcat 'identity
+                              (TeX-completing-read-multiple
+                               "Options: " (mapcar 'list (symbol-value var)))
+                              ","))))
+       (setq options (read-string "Options: ")))
+      (cons packages options))))
+
+(defun LaTeX-arg-usepackage-insert (packages options)
+  "Actually insert arguments to usepackage."
+  (unless (zerop (length options))
+    (let ((opts (LaTeX-listify-package-options options)))
+      (mapc (lambda (elt)
+             (TeX-add-to-alist 'LaTeX-provided-package-options
+                               (list (cons elt opts))))
+           packages))
+    (insert LaTeX-optop options LaTeX-optcl))
+  (insert TeX-grop (mapconcat 'identity packages ",") TeX-grcl)
+  (run-hooks 'LaTeX-after-usepackage-hook))
+
+(defun LaTeX-arg-usepackage (optional)
+  "Insert arguments to usepackage.
+OPTIONAL is ignored."
+  (let* ((packages-options (LaTeX-arg-usepackage-read-packages-with-options))
+        (packages (car packages-options))
+        (options (cdr packages-options)))
+    (LaTeX-arg-usepackage-insert packages options)))
+
+(defun LaTeX-insert-usepackages ()
+  "Prompt for the insertion of usepackage macros until empty
+input is reached.
+
+Return t if at least one \\usepackage has been inserted, nil
+otherwise."
+  (let (packages-options packages options (inserted nil))
+    (while (setq packages-options
+                (LaTeX-arg-usepackage-read-packages-with-options))
+      (setq packages (car packages-options))
+      (setq options (cdr packages-options))
+      (insert TeX-esc "usepackage")
+      (LaTeX-arg-usepackage-insert packages options)
+      (LaTeX-newline)
+      (setq inserted t))
+    inserted))
 
 (defcustom LaTeX-search-files-type-alist
   '((texinputs "${TEXINPUTS.latex}" ("tex/generic/" "tex/latex/")

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog        |   17 +++++++++
 doc/auctex.texi  |   12 ++++--
 doc/changes.texi |    4 ++
 latex.el         |  106 +++++++++++++++++++++++++++++++++++++-----------------
 4 files changed, 102 insertions(+), 37 deletions(-)


hooks/post-receive
-- 
GNU AUCTeX



reply via email to

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