# HG changeset patch # User Uwe Brauer # Date 1661545374 -7200 # Fri Aug 26 22:22:54 2022 +0200 # Node ID 95d66512156efbf7e37996fc955c2442c8a1fa28 # Parent 97a08e692fa3c4599b9acc5bae2003992ccbfeac Add support for catchfilebetweentags * Makefile.in (STYLEELC): Add style/catchfilebetweentags.el. * 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: Almost complete rewrite of all functions. diff --git a/Makefile.in b/Makefile.in --- a/Makefile.in +++ b/Makefile.in @@ -183,7 +183,7 @@ 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/proc.el style/microtype.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,107 @@ +;;; catchfilebetweentags.el --- AUCTeX style for catchfilebetweentags package -*- lexical-binding: t; -*- + +;; Copyright (C) 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, 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 "%%" 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" + "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"])) + + + (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" "*[{")) + '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 @@ -408,6 +408,12 @@ ;; example in the docstring of `LaTeX-shortvrb-chars' isn't picked up. +(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) + + (provide 'tex-style) ;;; tex-style.el ends here