[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 223/299: Prompt for packages inside LaTeX-env-document.
From: |
Stefan Monnier |
Subject: |
[elpa] 223/299: Prompt for packages inside LaTeX-env-document. |
Date: |
Sun, 02 Nov 2014 03:11:35 +0000 |
monnier pushed a commit to branch externals/auctex
in repository elpa.
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.
---
ChangeLog | 17 +++++++++
doc/auctex.texi | 12 ++++--
doc/changes.texi | 4 ++
latex.el | 106 +++++++++++++++++++++++++++++++++++++-----------------
4 files changed, 102 insertions(+), 37 deletions(-)
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/")
- [elpa] 221/299: Add an english style., (continued)
- [elpa] 221/299: Add an english style., Stefan Monnier, 2014/11/01
- [elpa] 220/299: Convert TeX-auto-add-type to a macro., Stefan Monnier, 2014/11/01
- [elpa] 222/299: New variable to pass options to the TeX processor., Stefan Monnier, 2014/11/01
- [elpa] 224/299: Fix selection of default environment in LaTeX-environment., Stefan Monnier, 2014/11/01
- [elpa] 225/299: Fix minor documentation bug., Stefan Monnier, 2014/11/01
- [elpa] 229/299: Advice instead of fset + redefine., Stefan Monnier, 2014/11/01
- [elpa] 228/299: Squash a byte-compiler warning., Stefan Monnier, 2014/11/01
- [elpa] 226/299: Improve defaults for filling., Stefan Monnier, 2014/11/01
- [elpa] 230/299: Fix bug causing endless package queries., Stefan Monnier, 2014/11/01
- [elpa] 232/299: Fix some FIXMEs., Stefan Monnier, 2014/11/01
- [elpa] 223/299: Prompt for packages inside LaTeX-env-document.,
Stefan Monnier <=
- [elpa] 233/299: Prevent an infinite loop in TeX-command-expand., Stefan Monnier, 2014/11/01
- [elpa] 227/299: Fix missing quote., Stefan Monnier, 2014/11/01
- [elpa] 235/299: Enable TeX-PDF-mode by default., Stefan Monnier, 2014/11/01
- [elpa] 236/299: Add new style/exercise.el., Stefan Monnier, 2014/11/01
- [elpa] 231/299: Make TeX-completing-read-multiple return nil on empty input., Stefan Monnier, 2014/11/01
- [elpa] 239/299: Silence assignment to free variable warnings., Stefan Monnier, 2014/11/01
- [elpa] 240/299: Fix ChangeLog node for texinfo., Stefan Monnier, 2014/11/01
- [elpa] 242/299: Add another exception to error parsing., Stefan Monnier, 2014/11/01
- [elpa] 241/299: Resolve conflicts, Stefan Monnier, 2014/11/01
- [elpa] 243/299: Fix fontification of optional argument to verbatim environments., Stefan Monnier, 2014/11/01