>>> "AE" == Arash Esbati <ar...@gnu.org> writes:

> Hi Uwe,
> Uwe Brauer <o...@mat.ucm.es> writes:

>> I hope it is now ok.

> Thanks, we're almost there, I think.  Some comments below.

I think that's it.

# HG changeset patch
# User Uwe Brauer <o...@mat.ucm.es>
# Date 1661861790 -7200
#      Tue Aug 30 14:16:30 2022 +0200
# Node ID 7e3b474a5bb4ce9c40d91fee750fbfbab56dce7a
# Parent  6d877f34b76f48b8cc29110232dbb4a41d9bcecb
Add support for catchfilebetweentags

* Merge Makefile.in with the master version

* tex-style.el (LaTeX-catchfilebetweentags-use-numeric-label):
Add a new variable, that controls whether a numeric label gets
inserted automatically. Default is t.

* style/catchfilebetweentags.el: New file.

diff --git a/Makefile.in b/Makefile.in
--- a/Makefile.in
+++ b/Makefile.in
@@ -194,7 +194,8 @@
 	   style/ifpdf.el     style/iftex.el     style/ifvtex.el \
 	   style/ifxetex.el   style/multibib.el  style/ltcaption.el \
 	   style/keyval.el    style/kvoptions.el style/kvsetkeys.el \
-	   style/proc.el      style/microtype.el style/tcolorboxlib-theorems.el
+	   style/proc.el      style/microtype.el style/tcolorboxlib-theorems.el \
+	   style/catchfilebetweentags.el
 
 STYLEELC = $(STYLESRC:.el=.elc)
 
diff --git a/style/catchfilebetweentags.el b/style/catchfilebetweentags.el
new file mode 100644
--- /dev/null
+++ b/style/catchfilebetweentags.el
@@ -0,0 +1,119 @@
+;;; catchfilebetweentags.el --- AUCTeX style for catchfilebetweentags package  -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 Free Software Foundation, Inc.
+
+;; Author: Uwe Brauer <o...@mat.ucm.es>
+;; Created: Aug 23, 2022
+;; Keywords: tex
+
+;; This file is part of AUCTeX.
+
+;; AUCTeX is free software; you can redistribute it and/or modify it
+;; under the terms of the GNU General Public License as published by
+;; the Free Software Foundation; either version 3, or (at your option)
+;; any later version.
+
+;; AUCTeX is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+;; General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with AUCTeX; see the file COPYING.  If not, write to the Free
+;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+;; 02110-1301, USA.
+
+;;; Commentary:
+
+;; This file adds support for the catchfilebetweentags.
+
+;; Acknowledgements
+;; Arash Esbati <ar...@gnu.org> for, basically, a complete rewrite, thanks.
+
+;;; Code:
+
+(require 'tex)
+(require 'latex)
+
+
+(defvar-local LaTeX-catchfilebetweentags-counter nil
+  "Counter for LaTeX-catchfilebetweentags numbers.")
+
+;; Scanning function, stolen from markdown-mode
+(defun LaTeX-catchfilebetweentags-counter-inc () 
+  "Increment `LaTeX-catchfilebetweentags-counter' and return the new value."
+  (when (null LaTeX-catchfilebetweentags-counter)
+    (setq LaTeX-catchfilebetweentags-counter 0)
+    (save-excursion
+      (goto-char (point-min))
+      (while (re-search-forward (concat "^%<\\*\\([^>]+\\)>$")
+                                (point-max) t)
+        (let ((fn (string-to-number (match-string 1))))
+          (when (> fn LaTeX-catchfilebetweentags-counter)
+            (setq LaTeX-catchfilebetweentags-counter fn))))))
+  (setq LaTeX-catchfilebetweentags-counter
+        (1+ LaTeX-catchfilebetweentags-counter)))
+
+(defun LaTeX-env-catchfilebetweentags (_environment)
+  "Insert a tag-skeleton defined by `LaTeX-catchfilebetweentags'.
+ENVIRONMENT is ignored."
+  (let* ((fn (when LaTeX-catchfilebetweentags-use-numeric-label
+               (LaTeX-catchfilebetweentags-counter-inc)))
+         (tag  (TeX-read-string
+                (if fn (format "Tag (default %s): " fn) "Tag: ")
+                nil nil (when fn (number-to-string fn)))))
+    (unless (bolp)
+      (newline)
+      (delete-horizontal-space))
+    (save-excursion
+      (insert (concat (format "%%<*%s>" tag)
+                      "\n\n"
+                      (format "%%</%s>" tag)))))
+  (forward-line))
+
+(TeX-add-style-hook
+ "catchfilebetweentags"
+ (lambda ()
+   (TeX-add-symbols
+    '("ExecuteMetaData"
+      ;; Act like \include and not like \input:
+      [TeX-arg-input-file "File" t] "Tag")
+    '("ExecuteMetaData*"
+      ;; Act like \include and not like \input:
+      [TeX-arg-input-file "File" t] "Tag")
+
+   '("CatchFileBetweenTags"
+     TeX-arg-define-macro (TeX-arg-input-file  "File-name" t) "Tag")
+   '("CatchFileBetweenTags*"
+     TeX-arg-define-macro (TeX-arg-input-file  "File-name" t) "Tag")
+
+;;    '("CatchFileBetweenTags"
+;;      "cs-name" (TeX-arg-input-file  "File-name" t) "Tag")
+;;    '("CatchFileBetweenTags*"
+;;      "cs-name" (TeX-arg-input-file  "File-name" t) "Tag")
+;;    '("CatchFileBetweenDelims"
+;;      "cs-name" (TeX-arg-input-file  "File-name" t) "start-delimiter" "stop-delimiter" ["setup"]))
+
+   '("CatchFileBetweenDelims"
+     TeX-arg-define-macro (TeX-arg-input-file  "File-name" t)
+     "Start delimiter" "Stop delimiter" ["Setup"]))
+
+
+   (LaTeX-add-environments
+    '("catchfilebetweenfiletags" LaTeX-env-catchfilebetweentags))
+
+   ;; Add `LaTeX-catchfilebetweentags-counter' to
+   ;; `TeX-normal-mode-reset-list' in case the variable gets out of
+   ;; sync:
+   (add-to-list 'TeX-normal-mode-reset-list
+                'LaTeX-catchfilebetweentags-counter)
+   ;; Fontification
+   (when (and (featurep 'font-latex)
+              (eq TeX-install-font-lock 'font-latex-setup))
+     (font-latex-add-keywords '(("ExecuteMetaData" "*[{")
+                                ("CatchFileBetweenTags"   "*|{\\{{")
+                                ("CatchFileBetweenDelims" "|{\\{{{["))
+                              'function)))
+ TeX-dialect)
+
+;;; catchfilebetweentags.el ends here
diff --git a/tex-style.el b/tex-style.el
--- a/tex-style.el
+++ b/tex-style.el
@@ -226,6 +226,14 @@
 (make-variable-buffer-local 'LaTeX-biblatex-use-Biber)
 (put 'LaTeX-biblatex-use-Biber 'safe-local-variable #'booleanp)
 
+
+;; style/catchfilebetweentags.el
+
+(defcustom LaTeX-catchfilebetweentags-use-numeric-label t
+  "Insert automatic numerical labels if non-nil, otherwise the
+prompts asks you for a label name."
+  :type 'boolean)
+
 ;; style/comment.el
 
 (defcustom LaTeX-comment-env-list '("comment")
@@ -408,6 +416,7 @@
 ;; example in the docstring of `LaTeX-shortvrb-chars' isn't picked up.

 
+
 (provide 'tex-style)
 
 ;;; tex-style.el ends here

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to