emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] externals/auctex 8f7c399 30/36: Implement LaTeX-command-section.


From: Stefan Monnier
Subject: [elpa] externals/auctex 8f7c399 30/36: Implement LaTeX-command-section.
Date: Fri, 28 Nov 2014 17:25:51 +0000

branch: externals/auctex
commit 8f7c39979d8c317d51ee565d9d1efd0ad0ebb178
Author: Tassilo Horn <address@hidden>
Date:   Fri Nov 21 14:54:21 2014 +0100

    Implement LaTeX-command-section.
    
    * style/book.el ("book"): Set LaTeX-largest-level to part instead
    of chapter.
    
    * tex-buf.el (LaTeX-command-section-level): New variable.
    (LaTeX-command-section-level): New function.
    (LaTeX-command-section-change-level, LaTeX-command-section): New
    commands.
    
    * latex.el (LaTeX-mode-map): Bind C-c C-z to LaTeX-command-section
    and C-c M-z to LaTeX-command-section-change-level.
---
 ChangeLog     |   11 +++++++++
 latex.el      |    3 ++
 style/book.el |    4 +-
 tex-buf.el    |   66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 59a020f..eb00e61 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2014-11-21  Tassilo Horn  <address@hidden>
 
+       * style/book.el ("book"): Set LaTeX-largest-level to part instead
+       of chapter.
+
+       * tex-buf.el (LaTeX-command-section-level): New variable.
+       (LaTeX-command-section-level): New function.
+       (LaTeX-command-section-change-level, LaTeX-command-section): New
+       commands.
+
+       * latex.el (LaTeX-mode-map): Bind C-c C-z to LaTeX-command-section
+       and C-c M-z to LaTeX-command-section-change-level.
+
        * tex.el (TeX-evince-sync-view): Use line/col information from the
        TeX-region buffer if the View command is made on a region.
 
diff --git a/latex.el b/latex.el
index 9e33885..80d2761 100644
--- a/latex.el
+++ b/latex.el
@@ -5248,6 +5248,9 @@ environmens."
     (define-key map "\C-c\C-q\C-s" 'LaTeX-fill-section)
     (define-key map "\C-c\C-q\C-e" 'LaTeX-fill-environment)
 
+    (define-key map "\C-c\C-z" 'LaTeX-command-section)
+    (define-key map "\C-c\M-z" 'LaTeX-command-section-change-level)
+
     (define-key map "\C-c."    'LaTeX-mark-environment) ;*** Dubious
     (define-key map "\C-c*"    'LaTeX-mark-section) ;*** Dubious
 
diff --git a/style/book.el b/style/book.el
index cbc9813..c9571cb 100644
--- a/style/book.el
+++ b/style/book.el
@@ -11,8 +11,8 @@
 
 (TeX-add-style-hook
  "book"
- (lambda () 
-   (LaTeX-largest-level-set "chapter")
+ (lambda ()
+   (LaTeX-largest-level-set "part")
    (LaTeX-add-counters "part" "chapter" "section" "subsection" "subsubsection"
                       "paragraph" "subparagraph" "figure" "table")
    (LaTeX-add-pagestyles "headings" "myheadings"))
diff --git a/tex-buf.el b/tex-buf.el
index 27a4b5c..2623023 100644
--- a/tex-buf.el
+++ b/tex-buf.el
@@ -1525,6 +1525,72 @@ the directory."
   :group 'TeX-command
   :type 'string)
 
+(defvar LaTeX-command-section-level nil
+  "The section level used for `LaTeX-command-section'.
+Will be initialized to `LaTeX-largest-level' buffer-locally.")
+(make-variable-buffer-local 'LaTeX-command-section-level)
+
+(defun LaTeX-command-section-level ()
+  "Return the value of `LaTeX-command-section-level'.
+Initialize it to `LaTeX-largest-level' if needed."
+  (unless LaTeX-command-section-level
+    (setq LaTeX-command-section-level LaTeX-largest-level))
+  LaTeX-command-section-level)
+
+(defun LaTeX-command-section-change-level (arg)
+  "Change `LaTeX-command-section-level' by ARG.
+`LaTeX-command-section-level' is the sectioning level used to
+determine the current section by `LaTeX-command-section'.  The
+levels are defined by `LaTeX-section-list'."
+  (interactive "p")
+  (let ((old-level (car (rassoc (list (LaTeX-command-section-level))
+                               LaTeX-section-list))))
+    (setq LaTeX-command-section-level (+ LaTeX-command-section-level arg))
+    (cond
+     ((> LaTeX-command-section-level 6)
+      (setq LaTeX-command-section-level 6)
+      (message "Cannot shrink LaTeX-command-section-level below 
subparagraph."))
+     ((< LaTeX-command-section-level 0)
+      (setq LaTeX-command-section-level 0)
+      (message "Cannot enlarge LaTeX-command-section-level above part."))
+     (t (message "Changed level from %s to %s."
+                old-level (car (rassoc (list LaTeX-command-section-level)
+                                       LaTeX-section-list)))))))
+
+(defun LaTeX-command-section (&optional override-confirm)
+  "Run a command on the current section.
+
+What makes the current section is defined by
+`LaTeX-command-section-level' which can be enlarged or shrunken
+with `LaTeX-command-section-change-level'.
+
+Query the user for a command to run on the temporary file
+specified by the variable `TeX-region'.  The region file will be
+recreated from current section.
+
+If a prefix argument OVERRIDE-CONFIRM is given, confirmation will
+depend on it being positive instead of the entry in
+`TeX-command-list'."
+  (interactive "P")
+  (let* ((case-fold-search t)
+        (rx (concat "\\\\" (regexp-opt
+                            (mapcar
+                             (lambda (level)
+                               (car (rassoc (list level) LaTeX-section-list)))
+                             (let (r)
+                               (dotimes (i (1+ (LaTeX-command-section-level)))
+                                 (push i r))
+                               r)))
+                    "{"))
+        (TeX-command-region-begin (save-excursion
+                                    (re-search-backward rx nil t)
+                                    (point)))
+        (TeX-command-region-end (save-excursion
+                                  (re-search-forward rx nil t)
+                                  (forward-line 0)
+                                  (point))))
+    (TeX-command-region override-confirm)))
+
 ;;; Parsing
 
 ;;; - Global Parser Variables



reply via email to

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