auctex-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[AUCTeX-diffs] GNU AUCTeX branch, master, updated. 4bcda2d50c5b3752a0b29


From: Arash Esbati
Subject: [AUCTeX-diffs] GNU AUCTeX branch, master, updated. 4bcda2d50c5b3752a0b292c006f7d90b099a67a7
Date: Fri, 18 Mar 2022 16:53:04 -0400 (EDT)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
       via  4bcda2d50c5b3752a0b292c006f7d90b099a67a7 (commit)
      from  8460859b6944d86b88863b051db844aeebf85bab (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 4bcda2d50c5b3752a0b292c006f7d90b099a67a7
Author: Arash Esbati <arash@gnu.org>
Date:   Fri Mar 18 21:50:55 2022 +0100

    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.

diff --git a/style/algpseudocode.el b/style/algpseudocode.el
index b0c455fe..619052b6 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 60617751..b832d5e2 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 24404664..864f7180 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 2ab7d3a9..d10b98a6 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

-----------------------------------------------------------------------

Summary of changes:
 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(-)


hooks/post-receive
-- 
GNU AUCTeX



reply via email to

[Prev in Thread] Current Thread [Next in Thread]