summaryrefslogtreecommitdiff
path: root/elpa/auctex-13.1.3/style/algpseudocode.el
blob: 1d8bdd7a031eae6d08c234281d473737f20326da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
;;; algpseudocode.el --- AUCTeX style for the (LaTeX) algpseudocode package  -*- lexical-binding: t; -*-

;; Copyright (C) 2020--2022 Free Software Foundation, Inc.

;; Author: Uwe Brauer <oub@mat.ucm.es>
;; Created: 2020-01-26
;; 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 algpseudocode package.

;;; Code:

(require 'tex)
(require 'latex)

;; Silence the compiler:
(declare-function font-latex-add-keywords
                  "font-latex"
                  (keywords class))

(defvar LaTeX-algpseudocode-package-options
  '("compatible" "nocompatible" "end" "noend")
  "Package options for the algpseudocode package.")

(TeX-add-style-hook
 "algpseudocode"
 (lambda ()
   (TeX-add-symbols
    ;; 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)
    '("algstore*" 1)
    '("algrestore" 1)
    '("algrestore*" 1)

    ;; 3.1.1 The for block
    '("For" 1)
    '("ForAll" 1)
    '("EndFor" 0)

    ;; 3.1.2 The while block
    '("While" 1)
    '("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)

    ;; 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