summaryrefslogtreecommitdiff
path: root/elpa/auctex-13.1.3/style/fancyhdr.el
blob: eb9751a43e6efbe702d096784e8375217f5efa48 (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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
;;; fancyhdr.el --- AUCTeX style for `fancyhdr.sty'  -*- lexical-binding: t; -*-

;; Copyright (C) 2012, 2013, 2018-2022 Free Software Foundation, Inc.

;; Author: Mads Jensen <mje@inducks.org>
;; Maintainer: auctex-devel@gnu.org
;; 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 `fancyhdr.sty', v4.0 from 2021/01/04.

;;; Code:

(require 'tex)
(require 'latex)

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

;; Because there can be many places, `TeX-completing-read-multiple' is
;; used instead of just `completing-read', and a `collection' argument
;; is provided as the list of places differs between the macros
(defun TeX-arg-fancyhdr-place (optional
                               &optional prompt collection full)
  "Prompt for fancyhdr places with completion.
If OPTIONAL is non-nil, insert the resulting value as an optional
argument, otherwise as a mandatory one.  If non-nil, PROMPT is
used as the prompt.  If non-nil, COLLECTION is used as the
completion list for the place.

If FULL is non-nil, a full list of places is offered for
completion, otherwise a reduced one omitting place combinations
for H(eader) or F(ooter)."
  (let* ((places (or collection
                     ;; Standard places with no restrictions.
                     ;; Lower-case versions, and reverse versions
                     ;; (e.g., OC) are left out for simplicity.
                     (if full
                         '("L" "LO" "LE" "LOH" "LOF" "LEH" "LEF"
                           "C" "CO" "CE" "COH" "COF" "CEH" "CEF"
                           "R" "RO" "RE" "ROH" "ROF" "REH" "REF")
                       '("L" "LO" "LE" "C" "CO" "CE" "R" "RE" "RO"))))
         (arguments (mapconcat #'identity
                               (TeX-completing-read-multiple
                                (TeX-argument-prompt optional
                                                     prompt
                                                     "Places")
                                places)
                               ",")))
    (TeX-argument-insert arguments optional)))

(defvar LaTeX-fancyhdr-fancypagestyle-regexp
  '("\\\\fancypagestyle{\\([^}]+\\)}"
    1 LaTeX-auto-pagestyle)
  "Regexp matching the first argument of \\fancypagestyle macro.")

(TeX-add-style-hook
 "fancyhdr"
 (lambda ()
   (TeX-add-symbols

    ;; 2 Using fancyhdr
    '("fancyhead" [ TeX-arg-fancyhdr-place ] t)
    '("fancyfoot" [ TeX-arg-fancyhdr-place ] t)
    '("fancyhf"   [ (TeX-arg-fancyhdr-place nil nil t) ] t)

    '("fancyheadoffset"
      [ (TeX-arg-fancyhdr-place nil ("L" "LO" "LE" "R" "RO" "RE")) ]
      TeX-arg-length)
    '("fancyfootoffset"
      [ (TeX-arg-fancyhdr-place nil ("LO" "LE" "L" "RO" "RE" "R")) ]
      TeX-arg-length)
    '("fancyhfoffset"
      [ (TeX-arg-fancyhdr-place nil ("L" "LO" "LE" "LOH" "LOF" "LEH" "LEF"
                                     "R" "RO" "RE" "ROH" "ROF" "REH" "REF")) ]
      TeX-arg-length)

    "headrulewidth" "footrulewidth"
    "headruleskip"  "footruleskip"
    "headrule"      "footrule"
    "headwidth"

    '("fancyheadinit" t)
    '("fancyfootinit" t)
    '("fancyhfinit"   t)

    '("fancycenter"
      [ TeX-arg-length "Distance" ] [ "Stretch" ] 3)

    '("iftopfloat"  2)
    '("ifbotfloat"  2)
    '("iffloatpage" 2)
    '("iffootnote"  2)

    '("fancypagestyle"
      ;; Always add the chosen pagestyle to list of known pagestyles,
      ;; dupes are removed when retrieving with the function
      ;; `LaTeX-pagestyle-list':
      (TeX-arg-pagestyle nil t)
      [ TeX-arg-pagestyle "Base pagestyle" ]
      t)

    ;; 15 The scoop on LATEX’s marks
    '("nouppercase" t))

   ;; Don't increase indentation at various \if* macros:
   (let ((exceptions '("iftopfloat"
                       "ifbotfloat"
                       "iffloatpage"
                       "iffootnote")))
     (dolist (elt exceptions)
       (add-to-list 'LaTeX-indent-begin-exceptions-list elt t))
     (LaTeX-indent-commands-regexp-make))

   ;; 30 Deprecated commands
   ;; Don't offer deprecated commands in V4.0 for completion anymore.
   ;; '("lhead" t)
   ;; '("lfoot" t)
   ;; '("chead" t)
   ;; '("cfoot" t)
   ;; '("rhead" t)
   ;; '("rfoot" t)
   ;; "plainfootrulewidth"
   ;; "plainheadrulewidth"

   ;; `fancyhdr.sty' supplies these two pagestyles.  Pagestyle
   ;; `fancyplain' is now deprecated.
   (LaTeX-add-pagestyles "fancy" "fancydefault")

   ;; Add \fancypagestyle{pagestyle} to AUCTeX parser
   (TeX-auto-add-regexp LaTeX-fancyhdr-fancypagestyle-regexp)

   ;; Fontification
   (when (and (fboundp 'font-latex-add-keywords)
              (eq TeX-install-font-lock 'font-latex-setup))
     (font-latex-add-keywords '(("fancyhead" "[{")
                                ("fancyfoot" "[{")
                                ("fancyhf"   "[{")
                                ("fancyheadoffset" "[{")
                                ("fancyfootoffset" "[{")
                                ("fancyhfoffset"   "[{")
                                ("fancyheadinit"   "{")
                                ("fancyfootinit"   "{")
                                ("fancyhfinit"     "{")
                                ;; Fontify deprecated commands for
                                ;; older documents; to be removed
                                ;; sometimes ...
                                ("lhead" "[{")
                                ("lfoot" "[{")
                                ("chead" "[{")
                                ("cfoot" "[{")
                                ("rhead" "[{")
                                ("rfoot" "[{")
                                ;; Don't fontify the last argument;
                                ;; all macros used there should have
                                ;; their own fontification since they
                                ;; can also be used in a document
                                ;; top-level.
                                ("fancypagestyle"  "{["))
                              'function)))
 TeX-dialect)

(defvar LaTeX-fancyhdr-package-options
  '("nocheck" "compatV3" "headings" "myheadings")
  "Package options for fancyhdr package.")

;;; fancyhdr.el ends here