# HG changeset patch # User Uwe Brauer # Date 1661325260 -7200 # Wed Aug 24 09:14:20 2022 +0200 # Node ID f5fedff23d18504b60eea1ec930a37ee045a82e5 # Parent 97a08e692fa3c4599b9acc5bae2003992ccbfeac Add Support for catchfilebetweentags * style/catchfilebetweentags.el: Add support for catchfilebetweentags, including optional automatic labeling. diff --git a/style/catchfilebetweentags.el b/style/catchfilebetweentags.el new file mode 100644 --- /dev/null +++ b/style/catchfilebetweentags.el @@ -0,0 +1,102 @@ +;;; catchfilebetweentags.el --- AUCTeX style for the (LaTeX) catchfilebetweentags style -*- lexical-binding: t; -*- + +;; Copyright (C) 2016--2022 Free Software Foundation, Inc. + +;; Author: Uwe Brauer +;; 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 for a very useful advice. + +;;; Code: + +(require 'tex) +(require 'latex) +(require 'cl-lib) + +(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")) + + (LaTeX-add-environments + '("catchfilebetweenfiletags" catchbetween-insert-environment)) + ;; Fontification + (when (and (featurep 'font-latex) + (eq TeX-install-font-lock 'font-latex-setup)) + (font-latex-add-keywords '(("ExecuteMetaData" "*[{")) + 'function))) + TeX-dialect) + + + + +(defvar catchbetween-use-numeric-label t + "Variable to insert automatic numerical labels.") +(make-variable-buffer-local 'catchbetween-use-numeric-label) + +(defvar catchbetween-counter 0 + "Counter for catchfilebetweentags numbers.") +(make-variable-buffer-local 'catchbetween-counter) + +(defconst catchbetween-chars + "[[:alnum:]-]" + "Regular expression maching any character that is allowed in a footnote identifier.") + +;; scanning function, stolen from markdown-mode +(defun catchbetween-counter-inc () + "Increment `catchbetween-counter' and return the new value." + (when (= catchbetween-counter 0) + (save-excursion + (goto-char (point-min)) + (while (re-search-forward (concat "^\\%<\\*\\(" catchbetween-chars "*?\\)>$") + (point-max) t) + (let ((fn (string-to-number (match-string 1)))) + (when (> fn catchbetween-counter) + (setq catchbetween-counter fn)))))) + (cl-incf catchbetween-counter)) + + +(defun catchbetween-environment () + "Insert a skeleton with a counter for the `LaTeX' package `catchfilebetweentags'." + (interactive) + (save-excursion + (when catchbetween-use-numeric-label + (let ((fn (catchbetween-counter-inc))) + (insert (concat "%<*" (format "%s" fn) ">\n\n%" )))) + (unless catchbetween-use-numeric-label + (insert (concat "%<*" ">\n\n%" )))) + (forward-line)) + +(defun catchbetween-insert-environment (environment) + (catchbetween-environment)) + +;;; catchfilebetweentags.el ends here