[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-diffs] [elpa] externals/auctex 3e95554c27 19/60: Reduce code dup
From: |
Tassilo Horn |
Subject: |
[AUCTeX-diffs] [elpa] externals/auctex 3e95554c27 19/60: Reduce code duplication in style/sidecap.el |
Date: |
Fri, 8 Apr 2022 11:52:49 -0400 (EDT) |
branch: externals/auctex
commit 3e95554c2710ab962521eb452f7ccd7ceafe0512
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>
Reduce code duplication in style/sidecap.el
* style/sidecap.el (LaTeX-env-sidecap-float): Use
`LaTeX-env-figure' and don't duplicate the code from it.
("sidecap"): Run the style hook for 'ragged2e' depending on given
package option.
---
style/sidecap.el | 149 ++++++++++++++++++++++---------------------------------
1 file changed, 60 insertions(+), 89 deletions(-)
diff --git a/style/sidecap.el b/style/sidecap.el
index bcd019c964..ff175173e6 100644
--- a/style/sidecap.el
+++ b/style/sidecap.el
@@ -1,6 +1,6 @@
;;; sidecap.el --- AUCTeX style for `sidecap.sty' (v1.6f) -*-
lexical-binding: t; -*-
-;; Copyright (C) 2021 Free Software Foundation, Inc.
+;; Copyright (C) 2021, 2022 Free Software Foundation, Inc.
;; Author: Arash Esbati <arash@gnu.org>
;; Maintainer: auctex-devel@gnu.org
@@ -36,94 +36,58 @@
(defun LaTeX-env-sidecap-float (environment)
"Create ENVIRONMENT with \\caption and \\label commands.
-This function is a copy of `LaTeX-env-figure' and adjusted to
-read the first optional argument 'relwidth' provided by
-environments of the package sidecap."
- (let* ((relwidth (TeX-read-string
- (TeX-argument-prompt t nil "Relative caption width")))
- (float (and LaTeX-float ; LaTeX-float can be nil, i.e.
- ; do not prompt
- (TeX-read-string "(Optional) Float position: "
LaTeX-float)))
- (caption (TeX-read-string "Caption: "))
- (short-caption (when (>= (length caption)
LaTeX-short-caption-prompt-length)
- (TeX-read-string "(Optional) Short caption: ")))
- (center (y-or-n-p "Center? "))
- (active-mark (and (TeX-active-mark)
- (not (eq (mark) (point)))))
- start-marker end-marker)
- (when active-mark
- (if (< (mark) (point))
- (exchange-point-and-mark))
- (setq start-marker (point-marker))
- (set-marker-insertion-type start-marker t)
- (setq end-marker (copy-marker (mark))))
- (setq LaTeX-float float)
- (LaTeX-insert-environment environment
- (concat
- ;; First check if 'relwidth' is given:
- (when (and relwidth
- (not (string= relwidth "")))
- (concat LaTeX-optop relwidth
- LaTeX-optcl))
- ;; We have to insert a pair of brackets
- ;; if 'float' is given and 'relwidth'
- ;; was empty, otherwise 'float' becomes
- ;; 'relwidth':
- (unless (zerop (length float))
- (concat
- (when (or (null relwidth)
- (string= relwidth ""))
- (concat LaTeX-optop LaTeX-optcl))
- LaTeX-optop float LaTeX-optcl))))
- (when active-mark
- (goto-char start-marker)
- (set-marker start-marker nil))
- (when center
- (insert TeX-esc "centering")
- (indent-according-to-mode)
- (LaTeX-newline)
- (indent-according-to-mode))
- ;; Insert caption and ask for a label, do nothing if user skips caption
- (unless (zerop (length caption))
- (if (member environment LaTeX-top-caption-list)
- ;; top caption
- (progn
- (insert (LaTeX-compose-caption-macro caption short-caption))
- ;; If `auto-fill-mode' is active, fill the caption.
- (if auto-fill-function (LaTeX-fill-paragraph))
- (LaTeX-newline)
- (indent-according-to-mode)
- ;; ask for a label and insert a new line only if a label is
- ;; actually inserted
- (when (LaTeX-label environment 'environment)
- (LaTeX-newline)
- (indent-according-to-mode)))
- ;; bottom caption (default)
- (when active-mark (goto-char end-marker))
- (save-excursion
- (LaTeX-newline)
- (indent-according-to-mode)
- ;; If there is an active region point is before the backslash of
- ;; "\end" macro, go one line upwards.
- (when active-mark (forward-line -1) (indent-according-to-mode))
- (insert (LaTeX-compose-caption-macro caption short-caption))
- ;; If `auto-fill-mode' is active, fill the caption.
- (if auto-fill-function (LaTeX-fill-paragraph))
- ;; ask for a label and if necessary insert a new line between caption
- ;; and label
- (when (save-excursion (LaTeX-label environment 'environment))
- (LaTeX-newline)
- (indent-according-to-mode)))
- ;; Insert an empty line between caption and marked region, if any.
- (when active-mark (LaTeX-newline) (forward-line -1))
- (indent-according-to-mode)))
- (when (markerp end-marker)
- (set-marker end-marker nil))
+This function runs `LaTeX-env-figure' and inserts the first
+optional argument 'relwidth' provided by environments of the
+package sidecap."
+ (let ((relwidth (TeX-read-string
+ (TeX-argument-prompt t nil "Relative caption width")))
+ (sc-active-mark (and (TeX-active-mark)
+ (not (eq (mark) (point)))))
+ (p (point-marker))
+ s)
+ ;; Run `LaTeX-env-figure' which does the major part of the job:
+ (LaTeX-env-figure environment)
+ ;; Now save the position:
+ (setq s (point-marker))
+ ;; Search backwards to see if an optional float-placement arg is
+ ;; inserted; this would be the 2nd arg for sidecap environments:
+ (save-excursion
+ (re-search-backward (concat (regexp-quote TeX-esc)
+ "begin"
+ "[ \t]*"
+ TeX-grop
+ (regexp-quote environment)
+ "\\(" TeX-grcl "\\)"
+ "[ \t]*"
+ "\\("
+ (regexp-quote LaTeX-optop)
+ ;; Float placement:
+ "\\([a-zA-Z!]*\\)"
+ (regexp-quote LaTeX-optcl)
+ "\\)?")
+ p t))
+ (cond (;; Insert the first optional arg at any rate if non-empty:
+ (and relwidth (not (string= relwidth "")))
+ (goto-char (match-end 1))
+ (insert LaTeX-optop relwidth LaTeX-optcl))
+ ;; Insert a pair of empty brackets if relwidth is empty and
+ ;; float-placement is given:
+ ((and (or (null relwidth)
+ (string= relwidth ""))
+ (match-string 3))
+ (goto-char (match-beginning 2))
+ (insert LaTeX-optop LaTeX-optcl))
+ (t nil))
+ ;; Go back to where we started if we have moved at all:
+ (unless (= s (point))
+ (goto-char s))
+ ;; Insert a tabular stored in `LaTeX-default-tabular-environment':
(when (and (member environment '("SCtable" "SCtable*"))
- ;; Suppose an existing tabular environment should just
- ;; be wrapped into a table if there is an active region.
- (not active-mark))
- (LaTeX-environment-menu LaTeX-default-tabular-environment))))
+ (not sc-active-mark))
+ (LaTeX-environment-menu LaTeX-default-tabular-environment))
+ ;; Clean up the markers:
+ (set-marker s nil)
+ (set-marker p nil)))
(TeX-add-style-hook
"sidecap"
@@ -147,7 +111,14 @@ environments of the package sidecap."
;; The next 2 can be set with '\renewcommand':
(TeX-add-symbols
"sidecaptionsep"
- "sidecaptionrelwidth"))
+ "sidecaptionrelwidth")
+
+ ;; Run the style hook for 'ragged2e' if necessary:
+ (when (or (LaTeX-provided-package-options-member "sidecap" "raggedright")
+ (LaTeX-provided-package-options-member "sidecap" "raggedleft")
+ (LaTeX-provided-package-options-member "sidecap" "ragged"))
+ (TeX-run-style-hooks "ragged2e")))
+
TeX-dialect)
(defvar LaTeX-sidecap-package-options
- [AUCTeX-diffs] [elpa] externals/auctex updated (8ff369bd92 -> 03ed9004cd), Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 90b1803b02 10/60: Use DEFAULT argument in latex.el where appropriate, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex e625dc05ea 01/60: Improve keymap handling, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 0847db39c9 03/60: Improve file query in style/ltxtable.el, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 7119e9b58c 14/60: ; Fix tests relying on font-lock has put syntax properties already, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 3e95554c27 19/60: Reduce code duplication in style/sidecap.el,
Tassilo Horn <=
- [AUCTeX-diffs] [elpa] externals/auctex 163dcb75bd 02/60: Fix label insertion at env. insertion with active region (bug#28382), Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex f464242eab 29/60: Enable indent by square bracket, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex f686fbca6d 16/60: Add new test, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex e37c7a8b39 31/60: Revise documentation about simultaneous process, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 844e758a47 07/60: Improve indent in tabular-like environments, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 0e0551126d 17/60: * doc/changes.texi: Document switch from initial input to default., Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex ab3bfaf103 13/60: Don't use obsolete font-lock-syntactic-keywords, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 2be733a3e3 28/60: Add new style/l3doc.el, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex dff1592319 09/60: Adjust argument list of `TeX-arg-length', Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex c43d21326d 42/60: Follow similar update of latex.el in context.el, Tassilo Horn, 2022/04/08