Hi all,
I think we can improve the support for LaTeX3 programming in
style/expl3. I had a brief look at interfaces.pdf and there is not much
code needed to get completion support for macro defining commands. My
initial approach on this is attached.
Reg. fontification: My current thinking is to do this for top-level
macros and the name of the new macro, leaving out the rest, e.g.:
What do people think, is it worth the trouble?
Best, Arash
diff --git a/style/expl3.el b/style/expl3.el
index d130a66b..22d7d0db 100644
--- a/style/expl3.el
+++ b/style/expl3.el
@@ -44,6 +44,35 @@
(modify-syntax-entry ?\: "_" st)
st))
+(defun TeX-arg-expl3-macro (_optional &optional prompt definition no-param)
+ "Read and insert an expl3 macro."
+ (let* ((macro (completing-read
+ (TeX-argument-prompt nil prompt
+ (concat "Function: " TeX-esc)
+ t)
+ (TeX-symbol-list)))
+ (params (progn
+ (when (string-empty-p macro)
+ (error "%s" "Function name missing"))
+ (if no-param
+ ""
+ (TeX-read-string
+ (TeX-argument-prompt t nil "Parameter")))))
+ (TeX-arg-opening-brace "")
+ (TeX-arg-closing-brace ""))
+ (when (and definition (not (string-empty-p macro)))
+ (TeX-add-symbols macro))
+ (just-one-space)
+ (TeX-argument-insert macro nil TeX-esc)
+ (just-one-space)
+ (unless (string-empty-p params)
+ (TeX-argument-insert params nil)
+ (just-one-space))))
+
+(defun TeX-arg-expl3-define-macro (optional &optional prompt no-param)
+ "Define a expl3 macro."
+ (TeX-arg-expl3-macro optional prompt t no-param))
+
(TeX-add-style-hook
"expl3"
(lambda ()
@@ -55,6 +84,8 @@
(add-to-list 'font-latex-match-simple-include-list ":" t))
(TeX-add-symbols
+
+ ;; 2.1 Using the LaTeX3 modules
'("ExplSyntaxOn" 0)
'("ExplSyntaxOff" 0)
@@ -68,7 +99,108 @@
'("ProvidesExplPackage"
(TeX-arg-file-name-sans-extension "Package name")
- TeX-arg-date TeX-arg-version "Description"))
+ TeX-arg-date TeX-arg-version "Description")
+
+ '("GetIdInfo"
+ (TeX-arg-literal " $Id: ")
+ (TeX-arg-free "SVN info field")
+ (TeX-arg-literal " $ ") "Description")
+
+ '("ExplFileName" 0)
+ '("ExplFileDate" 0)
+ '("ExplFileVersion" 0)
+ '("ExplFileDescription" 0)
+
+ ;; 4.1 No operation functions
+ "prg_do_nothing:" "scan_stop:"
+
+ ;; 4.2 Grouping material
+ "group_begin:" "group_end:"
+ "group_insert_after:N"
+ "group_show_list:" "group_log_list:"
+
+ ;; 4.3.2 Defining new functions using parameter text
+ '("cs_new:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_new:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_new:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_new:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_new:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_new:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_new_nopar:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_new_nopar:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_new_nopar:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_new_nopar:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_new_nopar:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_new_nopar:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected_nopar:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected_nopar:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected_nopar:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected_nopar:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected_nopar:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_new_protected_nopar:cpx" TeX-arg-expl3-define-macro t)
+
+ '("cs_set:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_set:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_set:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_set:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_set:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_set:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_set_nopar:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_set_nopar:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_set_nopar:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_set_nopar:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_set_nopar:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_set_nopar:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected_nopar:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected_nopar:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected_nopar:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected_nopar:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected_nopar:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_set_protected_nopar:cpx" TeX-arg-expl3-define-macro t)
+
+ '("cs_gset:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_gset:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_gset:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_gset:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_gset:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_gset:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_gset_nopar:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_gset_nopar:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_gset_nopar:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_gset_nopar:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_gset_nopar:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_gset_nopar:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected:cpx" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected_nopar:Npn" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected_nopar:cpn" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected_nopar:Npe" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected_nopar:cpe" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected_nopar:Npx" TeX-arg-expl3-define-macro t)
+ '("cs_gset_protected_nopar:cpx" TeX-arg-expl3-define-macro t)
+
+ ;; 4.3.3 Defining new functions using the signature
+ '("cs_new:Nn" TeX-arg-expl3-define-macro t)
+ '("cs_new:cn" TeX-arg-expl3-define-macro t)
+ '("cs_new:Ne" TeX-arg-expl3-define-macro t)
+ '("cs_new:ce" TeX-arg-expl3-define-macro t)
+ )
;; Fontification
(when (and (featurep 'font-latex)
@@ -78,7 +210,90 @@
'warning)
(font-latex-add-keywords '(("ProvidesExplClass" "{{{{")
("ProvidesExplFile" "{{{{")
- ("ProvidesExplPackage" "{{{{"))
+ ("ProvidesExplPackage" "{{{{")
+ ("GetIdInfo" "")
+
+ ("cs_new:Npn" "\\")
+ ("cs_new:cpn" "\\")
+ ("cs_new:Npe" "\\")
+ ("cs_new:cpe" "\\")
+ ("cs_new:Npx" "\\")
+ ("cs_new:cpx" "\\")
+ ("cs_new_nopar:Npn" "\\")
+ ("cs_new_nopar:cpn" "\\")
+ ("cs_new_nopar:Npe" "\\")
+ ("cs_new_nopar:cpe" "\\")
+ ("cs_new_nopar:Npx" "\\")
+ ("cs_new_nopar:cpx" "\\")
+ ("cs_new_protected:Npn" "\\")
+ ("cs_new_protected:cpn" "\\")
+ ("cs_new_protected:Npe" "\\")
+ ("cs_new_protected:cpe" "\\")
+ ("cs_new_protected:Npx" "\\")
+ ("cs_new_protected:cpx" "\\")
+ ("cs_new_protected_nopar:Npn" "\\")
+ ("cs_new_protected_nopar:cpn" "\\")
+ ("cs_new_protected_nopar:Npe" "\\")
+ ("cs_new_protected_nopar:cpe" "\\")
+ ("cs_new_protected_nopar:Npx" "\\")
+ ("cs_new_protected_nopar:cpx" "\\")
+
+ ("cs_set:Npn" "\\")
+ ("cs_set:cpn" "\\")
+ ("cs_set:Npe" "\\")
+ ("cs_set:cpe" "\\")
+ ("cs_set:Npx" "\\")
+ ("cs_set:cpx" "\\")
+ ("cs_set_nopar:Npn" "\\")
+ ("cs_set_nopar:cpn" "\\")
+ ("cs_set_nopar:Npe" "\\")
+ ("cs_set_nopar:cpe" "\\")
+ ("cs_set_nopar:Npx" "\\")
+ ("cs_set_nopar:cpx" "\\")
+ ("cs_set_protected:Npn" "\\")
+ ("cs_set_protected:cpn" "\\")
+ ("cs_set_protected:Npe" "\\")
+ ("cs_set_protected:cpe" "\\")
+ ("cs_set_protected:Npx" "\\")
+ ("cs_set_protected:cpx" "\\")
+ ("cs_set_protected_nopar:Npn" "\\")
+ ("cs_set_protected_nopar:cpn" "\\")
+ ("cs_set_protected_nopar:Npe" "\\")
+ ("cs_set_protected_nopar:cpe" "\\")
+ ("cs_set_protected_nopar:Npx" "\\")
+ ("cs_set_protected_nopar:cpx" "\\")
+
+ ("cs_gset:Npn" "\\")
+ ("cs_gset:cpn" "\\")
+ ("cs_gset:Npe" "\\")
+ ("cs_gset:cpe" "\\")
+ ("cs_gset:Npx" "\\")
+ ("cs_gset:cpx" "\\")
+ ("cs_gset_nopar:Npn" "\\")
+ ("cs_gset_nopar:cpn" "\\")
+ ("cs_gset_nopar:Npe" "\\")
+ ("cs_gset_nopar:cpe" "\\")
+ ("cs_gset_nopar:Npx" "\\")
+ ("cs_gset_nopar:cpx" "\\")
+ ("cs_gset_protected:Npn" "\\")
+ ("cs_gset_protected:cpn" "\\")
+ ("cs_gset_protected:Npe" "\\")
+ ("cs_gset_protected:cpe" "\\")
+ ("cs_gset_protected:Npx" "\\")
+ ("cs_gset_protected:cpx" "\\")
+ ("cs_gset_protected_nopar:Npn" "\\")
+ ("cs_gset_protected_nopar:cpn" "\\")
+ ("cs_gset_protected_nopar:Npe" "\\")
+ ("cs_gset_protected_nopar:cpe" "\\")
+ ("cs_gset_protected_nopar:Npx" "\\")
+ ("cs_gset_protected_nopar:cpx" "\\")
+
+ ("cs_new:Nn" "\\")
+ ("cs_new:cn" "\\")
+ ("cs_new:Ne" "\\")
+ ("cs_new:ce" "\\")
+
+ )
'function)))
TeX-dialect)