[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/auctex 4bcda2d50c 35/60: Improve indentation in env fro
From: |
Tassilo Horn |
Subject: |
[elpa] externals/auctex 4bcda2d50c 35/60: Improve indentation in env from algpseudocode package |
Date: |
Fri, 8 Apr 2022 11:52:51 -0400 (EDT) |
branch: externals/auctex
commit 4bcda2d50c5b3752a0b292c006f7d90b099a67a7
Author: Arash Esbati <arash@gnu.org>
Commit: Arash Esbati <arash@gnu.org>
Improve indentation in env from algpseudocode package
* style/algpseudocode.el (LaTeX-algpseudocode-package-options):
Adjust package options.
("algpseudocode"): Rearrange provided macros. Add macros to
appropriate indentation variables. Inhibit filling by adding the
environment "algorithmic" to `LaTeX-indent-environment-list'
without a function. Cater for fontification.
* tests/latex/latex-test.el (LaTeX-conditionals-indent): Parse the
test file and run the style hook for loaded package algpseudocode.
* tests/latex/conditionals-indent-in.tex:
* tests/latex/conditionals-indent-out.tex: Expand files with code
from algpseudocode package.
---
style/algpseudocode.el | 103 ++++++++++++++++++++++++++------
tests/latex/conditionals-indent-in.tex | 55 +++++++++++++++++
tests/latex/conditionals-indent-out.tex | 55 +++++++++++++++++
tests/latex/latex-test.el | 4 +-
4 files changed, 198 insertions(+), 19 deletions(-)
diff --git a/style/algpseudocode.el b/style/algpseudocode.el
index b0c455fef1..619052b614 100644
--- a/style/algpseudocode.el
+++ b/style/algpseudocode.el
@@ -1,6 +1,6 @@
;;; algpseudocode.el --- AUCTeX style for the (LaTeX) algpseudocode package
-*- lexical-binding: t; -*-
-;; Copyright (C) 2020 Free Software Foundation, Inc.
+;; Copyright (C) 2020--2022 Free Software Foundation, Inc.
;; Author: Uwe Brauer <oub@mat.ucm.es>
;; Created: 2020-01-26
@@ -24,6 +24,7 @@
;; 02110-1301, USA.
;;; Commentary:
+
;; This file adds support for the algpseudocode package.
;;; Code:
@@ -31,46 +32,112 @@
(require 'tex)
(require 'latex)
+;; Silence the compiler:
+(declare-function font-latex-add-keywords
+ "font-latex"
+ (keywords class))
+
(defvar LaTeX-algpseudocode-package-options
- '("compatible" "nocompatible")
+ '("compatible" "nocompatible" "end" "noend")
"Package options for the algpseudocode package.")
-
(TeX-add-style-hook
"algpseudocode"
(lambda ()
(TeX-add-symbols
- '("algref" 2)
+ ;; 2.3 Simple lines
+ '("State" (TeX-arg-literal " "))
+ '("Statex" 0)
+
+ ;; 2.4 Placing comments in sources
+ '("Comment" 1)
+
+ ;; 2.5 Labels and references
+ '("algref" (TeX-arg-ref "Algorithm") (TeX-arg-ref "Line"))
+
+ ;; 2.6 Breaking up long algorithms
'("algstore" 1)
- '("algrestore" 1)
'("algstore*" 1)
+ '("algrestore" 1)
'("algrestore*" 1)
- '("Procedure" 2)
- '("Comment" 1)
- '("State" 0)
- '("While" 0)
- '("EndWhile" 0)
- '("EndProcedure" 0)
- '("Repeat" 0)
- '("Until" 0)
+
+ ;; 3.1.1 The for block
'("For" 1)
'("ForAll" 1)
'("EndFor" 0)
+
+ ;; 3.1.2 The while block
+ '("While" 0)
+ '("EndWhile" 0)
+
+ ;; 3.1.3 The repeat block
+ '("Repeat" 0)
+ '("Until" 1)
+
+ ;; 3.1.4 The if block
'("If" 1)
'("ElsIf" 1)
'("Else" 0)
'("EndIf" 0)
+
+ ;; 3.1.5 The procedure block
+ '("Procedure" 2)
+ '("EndProcedure" 0)
+
+ ;; 3.1.6 The function block
'("Function" 2)
'("EndFunction" 0)
+
+ ;; 3.1.7 The loop block
'("Loop" 0)
'("EndLoop" 0)
- '("Require" 0)
- '("Ensure" 0)
- '("State" 0)
- '("Statex" 0)
- '("Call" 0))
+
+ ;; 3.1.8 Other commands in this layout
+ '("Require" (TeX-arg-literal " "))
+ '("Ensure" (TeX-arg-literal " "))
+ '("Call" 2))
+
(LaTeX-add-environments
'("algorithmic" [ "Number" ]))
+
+ ;; Indentation: Add the keywords above to the respective variables
+ ;; and run `LaTeX-indent-commands-regexp-make'.
+ (let ((beg '("For" "ForAll"
+ "While"
+ "Repeat"
+ "If"
+ "Procedure"
+ "Function"
+ "Loop"))
+ (mid '("ElsIf" "Else"))
+ (end '("EndFor"
+ "EndWhile"
+ "Until"
+ "EndIf"
+ "EndProcedure"
+ "EndFunction"
+ "EndLoop")))
+ (dolist (elt beg)
+ (add-to-list 'LaTeX-indent-begin-list elt t))
+ (dolist (elt mid)
+ (add-to-list 'LaTeX-indent-mid-list elt t))
+ (dolist (elt end)
+ (add-to-list 'LaTeX-indent-end-list elt t))
+ (LaTeX-indent-commands-regexp-make))
+
+ ;; Add the 'algorithmic' environment to a local version of
+ ;; `LaTeX-indent-environment-list'. This effectively kills filling
+ ;; but indenting works as expected. Hence, 'M-q' gives a better
+ ;; experience.
+ (add-to-list (make-local-variable 'LaTeX-indent-environment-list)
+ '("algorithmic")
+ t)
+
+ ;; Fontification
+ (when (and (featurep 'font-latex)
+ (eq TeX-install-font-lock 'font-latex-setup))
+ (font-latex-add-keywords '(("algref" "{{"))
+ 'reference))
TeX-dialect))
;;; algpseudocode.el ends here
diff --git a/tests/latex/conditionals-indent-in.tex
b/tests/latex/conditionals-indent-in.tex
index 606177516f..b832d5e2dd 100644
--- a/tests/latex/conditionals-indent-in.tex
+++ b/tests/latex/conditionals-indent-in.tex
@@ -1,5 +1,6 @@
\documentclass{article}
+\usepackage{algpseudocode}
\usepackage[%
key = val , %
key = val , %
@@ -88,6 +89,60 @@
\wlog{\string#1=\string\insert\the\allocationnumber}%
}
+\begin{algorithmic}[1]
+ \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
+ \State $r\gets a\bmod b$
+ \While{$r\not=0$}\Comment{We have the answer if r is 0 and what
+ about a large comment}
+ \State $a\gets b$
+\State $b\gets r$
+ \State $r\gets a\bmod b$
+ \EndWhile\label{euclidendwhile}
+ \State \textbf{return} $b$\Comment{The gcd is b}
+ \State
+\Statex
+ \EndProcedure
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+\State $sum\gets 0$
+\For{$i\gets 1, n$}
+\State $sum\gets sum+i$
+\EndFor
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+\State $sum\gets 0$
+\State $i\gets 1$
+\While{$i\le n$}
+\State $sum\gets sum+i$
+ \State $i\gets i+1$
+ \EndWhile
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+ \If{$quality\ge 9$}
+ \State $a\gets perfect$
+ \ElsIf{$quality\ge 7$}
+ \State $a\gets good$
+ \ElsIf{$quality\ge 5$}
+ \State $a\gets medium$
+ \ElsIf{$quality\ge 3$}
+ \State $a\gets bad$
+ \Else
+ \State $a\gets unusable$
+ \EndIf
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+ \Require $x\ge5$
+\Ensure $x\le-5$
+ \Statex
+\While{$x>-5$}
+ \State $x\gets x-1$
+ \EndWhile
+\end{algorithmic}
+
\end{document}
%%% Local Variables:
diff --git a/tests/latex/conditionals-indent-out.tex
b/tests/latex/conditionals-indent-out.tex
index 2440466428..864f718090 100644
--- a/tests/latex/conditionals-indent-out.tex
+++ b/tests/latex/conditionals-indent-out.tex
@@ -1,5 +1,6 @@
\documentclass{article}
+\usepackage{algpseudocode}
\usepackage[%
key = val , %
key = val , %
@@ -88,6 +89,60 @@
\wlog{\string#1=\string\insert\the\allocationnumber}%
}
+\begin{algorithmic}[1]
+ \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
+ \State $r\gets a\bmod b$
+ \While{$r\not=0$}\Comment{We have the answer if r is 0 and what
+ about a large comment}
+ \State $a\gets b$
+ \State $b\gets r$
+ \State $r\gets a\bmod b$
+ \EndWhile\label{euclidendwhile}
+ \State \textbf{return} $b$\Comment{The gcd is b}
+ \State
+ \Statex
+ \EndProcedure
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+ \State $sum\gets 0$
+ \For{$i\gets 1, n$}
+ \State $sum\gets sum+i$
+ \EndFor
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+ \State $sum\gets 0$
+ \State $i\gets 1$
+ \While{$i\le n$}
+ \State $sum\gets sum+i$
+ \State $i\gets i+1$
+ \EndWhile
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+ \If{$quality\ge 9$}
+ \State $a\gets perfect$
+ \ElsIf{$quality\ge 7$}
+ \State $a\gets good$
+ \ElsIf{$quality\ge 5$}
+ \State $a\gets medium$
+ \ElsIf{$quality\ge 3$}
+ \State $a\gets bad$
+ \Else
+ \State $a\gets unusable$
+ \EndIf
+\end{algorithmic}
+
+\begin{algorithmic}[1]
+ \Require $x\ge5$
+ \Ensure $x\le-5$
+ \Statex
+ \While{$x>-5$}
+ \State $x\gets x-1$
+ \EndWhile
+\end{algorithmic}
+
\end{document}
%%% Local Variables:
diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el
index 2ab7d3a96f..d10b98a6e1 100644
--- a/tests/latex/latex-test.el
+++ b/tests/latex/latex-test.el
@@ -663,7 +663,9 @@ check the indentation for optional argument of
\\usepackage."
(insert-file-contents LaTeX-conditionals-indent/in)
(LaTeX-mode)
(let ((TeX-indent-open-delimiters "[")
- (TeX-indent-close-delimiters "]"))
+ (TeX-indent-close-delimiters "]")
+ (TeX-parse-self t))
+ (TeX-update-style t)
(indent-region (point-min) (point-max))
(buffer-string)))
(with-temp-buffer
- [elpa] externals/auctex e625dc05ea 01/60: Improve keymap handling, (continued)
- [elpa] externals/auctex e625dc05ea 01/60: Improve keymap handling, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 259ffc34c4 12/60: Use DEFAULT argument of `TeX-read-string' in styles, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 90b1803b02 10/60: Use DEFAULT argument in latex.el where appropriate, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex ab3bfaf103 13/60: Don't use obsolete font-lock-syntactic-keywords, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex c731038844 11/60: Improve regexp matching new environments, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 3e95554c27 19/60: Reduce code duplication in style/sidecap.el, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex b7d45e19c6 22/60: Discard obsolete hook, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex f9356664c8 23/60: Update documentation, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex f464242eab 29/60: Enable indent by square bracket, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 2be733a3e3 28/60: Add new style/l3doc.el, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 4bcda2d50c 35/60: Improve indentation in env from algpseudocode package,
Tassilo Horn <=
- [elpa] externals/auctex 8938787491 37/60: ; * style/algpseudocode.el ("algpseudocode"): Fix "While"., Tassilo Horn, 2022/04/08
- [elpa] externals/auctex b3d4a509d0 39/60: ; * doc/auctex.texi (Indenting): Fix wording., Tassilo Horn, 2022/04/08
- [elpa] externals/auctex c43d21326d 42/60: Follow similar update of latex.el in context.el, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex b2cea20056 53/60: ; Delete unnecessary quoting in docstrings, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex eb4e331bd6 51/60: Add news for new indent feature, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 1823017839 55/60: Wrap the 'function' environment better with %, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 7119e9b58c 14/60: ; Fix tests relying on font-lock has put syntax properties already, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 163dcb75bd 02/60: Fix label insertion at env. insertion with active region (bug#28382), Tassilo Horn, 2022/04/08
- [elpa] externals/auctex 844e758a47 07/60: Improve indent in tabular-like environments, Tassilo Horn, 2022/04/08
- [elpa] externals/auctex e032df90e7 05/60: Fix simultaneity, Tassilo Horn, 2022/04/08