Skip to content

Commit 13e753a

Browse files
committed
test: add fzf-lua example
1 parent 1417bbf commit 13e753a

File tree

4 files changed

+164
-11
lines changed

4 files changed

+164
-11
lines changed

lua/vimtex/fzf-lua/init.lua

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,22 @@ local color_map = {
1515
---@return string number
1616
local function format_number(n)
1717
local num = {
18-
n["chapter"] ~= 0 and n["chapter"] or nil,
19-
n["section"] ~= 0 and n["section"] or nil,
20-
n["subsection"] ~= 0 and n["subsection"] or nil,
21-
n["subsubsection"] ~= 0 and n["subsubsection"] or nil,
22-
n["subsubsubsection"] ~= 0 and n["subsubsubsection"] or nil,
18+
n.chapter ~= 0 and n.chapter or nil,
19+
n.section ~= 0 and n.section or nil,
20+
n.subsection ~= 0 and n.subsection or nil,
21+
n.subsubsection ~= 0 and n.subsubsection or nil,
22+
n.subsubsubsection ~= 0 and n.subsubsubsection or nil,
2323
}
24-
if vim.tbl_isempty(num) then
25-
return ""
26-
end
2724
num = vim.tbl_filter(function(t)
2825
return t ~= nil
2926
end, num)
27+
if vim.tbl_isempty(num) then
28+
return ""
29+
end
3030

3131
-- Convert appendix items numbers to letters (e.g. 1 -> A, 2 -> B)
3232
if n.appendix ~= 0 then
33-
local ind = table.sort(vim.tbl_keys(num))[1]
34-
num[ind] = string.char(num[ind] + 64)
33+
num[1] = string.char(num[1] + 64)
3534
end
3635

3736
num = vim.tbl_map(function(t)
@@ -75,7 +74,7 @@ M.run = function(layers)
7574
["--with-nth"] = "{2} {3}",
7675
},
7776
actions = {
78-
["default"] = function(selection, o)
77+
default = function(selection, o)
7978
local s = vim.tbl_map(function(t)
8079
return vim.split(t, "####")[1]
8180
end, selection)

test/example-fzf-lua/main.tex

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
\documentclass{book}
2+
3+
\begin{document}
4+
5+
% Folding of multiline comments
6+
%
7+
% -- Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam
8+
% -- nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
9+
% -- sed diam voluptua. At vero eos et accusam et justo duo dolores et ea
10+
% -- rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem
11+
% -- ipsum dolor sit amet.
12+
13+
\frontmatter
14+
15+
\chapter{Preface}
16+
Preface.
17+
18+
\section{Acknowledgements}
19+
20+
\chapter[Other]{Other frontmatter chapter}
21+
22+
\tableofcontents
23+
24+
\mainmatter
25+
26+
\chapter*{Test chapter 1}
27+
Test of starred chapter.
28+
29+
\chapter{Test chapter 1}
30+
This test document is created to test advanced TOC functionality.
31+
32+
\begin{table}
33+
\caption[foo]{bar}
34+
\end{table}
35+
\begin{table}
36+
\caption[foo] {bar}
37+
\end{table}
38+
39+
\section{Test section 1}
40+
41+
\subsection{sub}
42+
43+
\subsubsection{subsub}
44+
45+
\subsubsubsection{subsub}
46+
47+
\subsection{Test sub section 1}
48+
49+
\section{$\alpha$}
50+
51+
\subsection{Test sub section 1}
52+
53+
\subsection{Test sub section 2}
54+
Some text.
55+
56+
\chapter{Test chapter 2}
57+
58+
\section{Testing TOC levels}
59+
Testing more input and TOC levels.
60+
61+
\subsection{Testing TOC sub levels}
62+
63+
\subsubsection{Testing TOC sub sub levels}
64+
Hello world.
65+
66+
\subsubsection{Text $\Gamma^{r}(\ensuremath{{\mathbf{Z}}}_p^d,\mathbf{K})$}
67+
68+
\subsection{Another test subsection}
69+
70+
\subsubsection{Other text $\Gamma^{r}$}
71+
72+
\section{Testing more appendix levels}
73+
Testing more input and TOC levels.
74+
75+
\subsection{Testing TOC sub levels}
76+
77+
\appendix
78+
79+
\chapter{Appendix 1}
80+
This test document is created to test advanced TOC functionality.
81+
82+
\section{Appendix subsection}
83+
84+
\subsection{sub}
85+
86+
\subsubsection{subsub}
87+
88+
\subsubsubsection{subsub}
89+
90+
\subsection{Test sub section 1}
91+
92+
\chapter{Appendix 2}
93+
94+
\section{Testing TOC levels}
95+
Testing more input and TOC levels.
96+
97+
\subsection{Testing TOC sub levels}
98+
99+
\subsubsection{Testing TOC sub sub levels}
100+
Hello world.
101+
102+
\subsubsection{Text $\Gamma^{r}(\ensuremath{{\mathbf{Z}}}_p^d,\mathbf{K})$}
103+
104+
\subsection{Another test subsection}
105+
106+
\subsubsection{Other text $\Gamma^{r}$}
107+
108+
\section{Testing more appendix levels}
109+
Testing more input and TOC levels.
110+
111+
\subsection{Testing TOC sub levels}
112+
113+
114+
\backmatter
115+
116+
\chapter{No numbers in backmatter 1}
117+
118+
\section{Section 1}
119+
120+
\section{Section 2}
121+
122+
\chapter{No numbers in backmatter 2}
123+
124+
\section{Section 1}
125+
126+
\section{Section 2}
127+
128+
\end{document}

test/example-fzf-lua/mise.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tools]
2+
fzf = "latest"

test/example-fzf-lua/test.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
local fzf_lua_path = "./fzf-lua"
2+
if not vim.uv.fs_stat(fzf_lua_path) then
3+
vim.fn.system {
4+
"git",
5+
"clone",
6+
"--filter=blob:none",
7+
"https://github.com/ibhagwan/fzf-lua/",
8+
fzf_lua_path,
9+
}
10+
end
11+
vim.opt.rtp:prepend(fzf_lua_path)
12+
13+
vim.opt.runtimepath:prepend "../.."
14+
vim.opt.runtimepath:append "../../after"
15+
vim.cmd [[filetype plugin indent on]]
16+
17+
vim.keymap.set("n", "q", "<cmd>qall!<cr>")
18+
vim.keymap.set("n", "<localleader>lt", function()
19+
return require("vimtex.fzf-lua").run()
20+
end)
21+
22+
vim.g.vimtex_cache_persistent = false
23+
24+
vim.cmd.edit "main.tex"

0 commit comments

Comments
 (0)