diff --git a/Manifest.toml b/Manifest.toml index e41956f..ddeec99 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -1,12 +1,215 @@ # This file is machine-generated - editing it directly is not advised +[[ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" + +[[Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + [[CSTParser]] deps = ["Tokenize"] git-tree-sha1 = "9723e1c07c1727082e169ca50789644a552fb023" uuid = "00ebfdb7-1f24-5e51-bd34-a7502290713f" version = "3.2.3" +[[CommonMark]] +deps = ["Crayons", "JSON", "URIs"] +git-tree-sha1 = "1060c5023d2ac8210c73078cb7c0c567101d201c" +uuid = "a80b9123-70ca-4bc0-993e-6e3bcb318db6" +version = "0.8.2" + +[[Compat]] +deps = ["Base64", "Dates", "DelimitedFiles", "Distributed", "InteractiveUtils", "LibGit2", "Libdl", "LinearAlgebra", "Markdown", "Mmap", "Pkg", "Printf", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "Test", "UUIDs", "Unicode"] +git-tree-sha1 = "4866e381721b30fac8dda4c8cb1d9db45c8d2994" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "3.37.0" + +[[CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" + +[[Crayons]] +git-tree-sha1 = "3f71217b538d7aaee0b69ab47d9b7724ca8afa0d" +uuid = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f" +version = "4.0.4" + +[[DataStructures]] +deps = ["Compat", "InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "7d9d316f04214f7efdbb6398d545446e246eff02" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.18.10" + +[[Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[DelimitedFiles]] +deps = ["Mmap"] +uuid = "8bb1440f-4735-579b-a4ab-409b98df4dab" + +[[Distributed]] +deps = ["Random", "Serialization", "Sockets"] +uuid = "8ba89e20-285c-5b6f-9357-94700520ee1b" + +[[Downloads]] +deps = ["ArgTools", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" + +[[InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "8076680b162ada2a031f707ac7b4953e30667a37" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.2" + +[[JuliaFormatter]] +deps = ["CSTParser", "CommonMark", "DataStructures", "Pkg", "Tokenize"] +git-tree-sha1 = "03d48b801c3d497c301a137ad32be7a70f1a64cb" +uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899" +version = "0.15.2" + +[[LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" + +[[LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" + +[[LibGit2]] +deps = ["Base64", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" + +[[Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[LinearAlgebra]] +deps = ["Libdl", "libblastrampoline_jll"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" + +[[Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" + +[[NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" + +[[OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" + +[[OrderedCollections]] +git-tree-sha1 = "85f8e6578bf1f9ee0d11e7bb1b1456435479d47c" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.4.1" + +[[Parsers]] +deps = ["Dates"] +git-tree-sha1 = "438d35d2d95ae2c5e8780b330592b6de8494e779" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.0.3" + +[[Pkg]] +deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" + +[[Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[Random]] +deps = ["Serialization"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" + +[[Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[SharedArrays]] +deps = ["Distributed", "Mmap", "Random", "Serialization"] +uuid = "1a1011a3-84de-559e-8e89-a11a2f7dc383" + +[[Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[SparseArrays]] +deps = ["LinearAlgebra", "Random"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" + +[[Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" + +[[TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" + +[[Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" + +[[Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + [[Tokenize]] git-tree-sha1 = "eee92eda3cc8e104b7e56ff4c1fcf0d78ca37c89" uuid = "0796e94c-ce3b-5d07-9a54-7f471281c624" version = "0.5.18" + +[[URIs]] +git-tree-sha1 = "97bbe755a53fe859669cd907f2d96aee8d2c1355" +uuid = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4" +version = "1.3.0" + +[[UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" + +[[libblastrampoline_jll]] +deps = ["Artifacts", "Libdl", "OpenBLAS_jll"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" + +[[nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" + +[[p7zip_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" diff --git a/Project.toml b/Project.toml index 7f8fdaa..86bc0fb 100644 --- a/Project.toml +++ b/Project.toml @@ -1,2 +1,3 @@ [deps] CSTParser = "00ebfdb7-1f24-5e51-bd34-a7502290713f" +JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899" diff --git a/formatter.jl b/formatter.jl new file mode 100644 index 0000000..321ee58 --- /dev/null +++ b/formatter.jl @@ -0,0 +1,10 @@ +#Format regions and buffers via JuliaFormatter +#Inspired by https://codeberg.org/FelipeLema/julia-formatter.el/ + +function format_data(str::String) + try + JuliaFormatter.format_text(str) + catch #sthg went wrong, syntax probably invalid + return [] + end +end diff --git a/julia-snail.el b/julia-snail.el index 6f43db1..ce38e73 100644 --- a/julia-snail.el +++ b/julia-snail.el @@ -1343,6 +1343,47 @@ autocompletion aware of the available modules." (define-key map (kbd "C-k") #'julia-snail-repl-vterm-kill-line) map)) +;; Format regions and buffers via JuliaFormatter +;; Inspired by https://codeberg.org/FelipeLema/julia-formatter.el/ + +(defun julia-snail--format-text (txt) + (julia-snail--send-to-server + :JuliaSnail + (format "format_data(\"%s\")" txt) + :async nil)) + + +(defun julia-snail-format-region (begin end) + "Format region delimited by BEGIN and END using JuliaFormatter.jl. +The code in the region must be syntactically valid Julia, otherwise no formatting will take place. " + (interactive "r") + (let* ((text-to-be-formatted + (buffer-substring-no-properties + begin end)) + (ftext (julia-snail--format-text + text-to-be-formatted)) + ) + + (if (eq :nothing ftext) + (message "Parsing error, formatting failed") + (progn + (delete-region begin end) + (insert ftext) + )) + )) + + +(defun julia-snail-format-buffer () + "Format buffer using JuliaFormatter.jl. +The buffer must be syntactically valid Julia, otherwise no formatting will take place. +Point placement after reformatting is heuristic, since the code might have changed quite a bit. " + + (interactive ) + (let* ((old-point (point) )) + (julia-snail-format-region (point-min) (point-max)) + (goto-char old-point) + ) +) ;;; --- mode definitions