From 254a27a2abb3208a3059cbee09dc823a93ad47bf Mon Sep 17 00:00:00 2001 From: Riccardo Milani Date: Tue, 10 Nov 2020 10:51:14 +0100 Subject: [PATCH 1/3] Add motion between frames --- autoload/vimtex.vim | 13 +++++++++++++ autoload/vimtex/motion.vim | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/autoload/vimtex.vim b/autoload/vimtex.vim index a4e746986a..8c99bec59e 100644 --- a/autoload/vimtex.vim +++ b/autoload/vimtex.vim @@ -206,6 +206,19 @@ function! s:init_default_mappings() abort " {{{1 call s:map(1, 'o', '[N', '(vimtex-[N)') call s:map(1, 'o', '[n', '(vimtex-[n)') + call s:map(1, 'n', ']R', '(vimtex-]R)') + call s:map(1, 'n', ']r', '(vimtex-]r)') + call s:map(1, 'n', '[R', '(vimtex-[R)') + call s:map(1, 'n', '[r', '(vimtex-[r)') + call s:map(1, 'x', ']R', '(vimtex-]R)') + call s:map(1, 'x', ']r', '(vimtex-]r)') + call s:map(1, 'x', '[R', '(vimtex-[R)') + call s:map(1, 'x', '[r', '(vimtex-[r)') + call s:map(1, 'o', ']R', '(vimtex-]R)') + call s:map(1, 'o', ']r', '(vimtex-]r)') + call s:map(1, 'o', '[R', '(vimtex-[R)') + call s:map(1, 'o', '[r', '(vimtex-[r)') + call s:map(1, 'n', ']/', '(vimtex-]/)') call s:map(1, 'n', ']*', '(vimtex-]*)') call s:map(1, 'n', '[/', '(vimtex-[/)') diff --git a/autoload/vimtex/motion.vim b/autoload/vimtex/motion.vim index 53eade34bd..b75ead360f 100644 --- a/autoload/vimtex/motion.vim +++ b/autoload/vimtex/motion.vim @@ -71,6 +71,24 @@ function! vimtex#motion#init_buffer() abort " {{{1 onoremap (vimtex-[m) :execute "normal \(V)" . v:count1 . "\(vimtex-[m)" onoremap (vimtex-[M) :execute "normal \(V)" . v:count1 . "\(vimtex-[M)" + " Frames + nnoremap (vimtex-]r) :call vimtex#motion#frame(1,0,0) + nnoremap (vimtex-]R) :call vimtex#motion#frame(0,0,0) + nnoremap (vimtex-[r) :call vimtex#motion#frame(1,1,0) + nnoremap (vimtex-[R) :call vimtex#motion#frame(0,1,0) + xnoremap (vimtex-]r) :call vimtex#motion#frame(1,0,1) + xnoremap (vimtex-]R) :call vimtex#motion#frame(0,0,1) + xnoremap (vimtex-[r) :call vimtex#motion#frame(1,1,1) + xnoremap (vimtex-[R) :call vimtex#motion#frame(0,1,1) + xmap (vimtex-]r) (vimtex-]r) + xmap (vimtex-]R) (vimtex-]R) + xmap (vimtex-[r) (vimtex-[r) + xmap (vimtex-[R) (vimtex-[R) + onoremap (vimtex-]r) :execute "normal \(V)" . v:count1 . "\(vimtex-]r)" + onoremap (vimtex-]R) :execute "normal \(V)" . v:count1 . "\(vimtex-]R)" + onoremap (vimtex-[r) :execute "normal \(V)" . v:count1 . "\(vimtex-[r)" + onoremap (vimtex-[R) :execute "normal \(V)" . v:count1 . "\(vimtex-[R)" + " Comments nnoremap (vimtex-]/) :call vimtex#motion#comment(1,0,0) nnoremap (vimtex-]*) :call vimtex#motion#comment(0,0,0) @@ -189,6 +207,21 @@ function! vimtex#motion#environment(begin, backwards, visual) abort " {{{1 endfor endfunction +" }}}1 +function! vimtex#motion#frame(begin, backwards, visual) abort " {{{1 + let l:count = v:count1 + if a:visual + normal! gv + endif + + let l:re = g:vimtex#re#not_comment . (a:begin ? '\\begin\s*\{frame\}' : '\\end\s*\{frame\}') + let l:flags = 'W' . (a:backwards ? 'b' : '') + + for l:_ in range(l:count) + call search(l:re, l:flags) + endfor +endfunction + " }}}1 function! vimtex#motion#comment(begin, backwards, visual) abort " {{{1 let l:count = v:count1 From 7de51702529567e6230b0f476d9f3fadc19d2e22 Mon Sep 17 00:00:00 2001 From: Riccardo Milani Date: Wed, 11 Nov 2020 09:25:36 +0100 Subject: [PATCH 2/3] Update docs with frame-related r-based motions (e.g. ]r) --- doc/vimtex.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/vimtex.txt b/doc/vimtex.txt index 01eed28c1c..ddd41e7e82 100644 --- a/doc/vimtex.txt +++ b/doc/vimtex.txt @@ -172,6 +172,7 @@ FEATURE OVERVIEW *vimtex-features* - Move between section boundaries with `[[`, `[]`, `][`, and `]]` - Move between environment boundaries with `[m`, `[M`, `]m`, and `]M` - Move between math environment boundaries with `[n`, `[N`, `]n`, and `]N` + - Move between frame environment boundaries with `[r`, `[R`, `]r`, and `]R` - Move between comment boundaries with `[*` and `]*` - Move between matching delimiters with `%` - Text objects @@ -787,6 +788,10 @@ This feature is explained in more detail later, see |vimtex-imaps|. ]N |(vimtex-]N)| `nxo` [n |(vimtex-[n)| `nxo` [N |(vimtex-[N)| `nxo` + ]r |(vimtex-]r)| `nxo` + ]R |(vimtex-]R)| `nxo` + [r |(vimtex-[r)| `nxo` + [R |(vimtex-[R)| `nxo` ]/ |(vimtex-]/| `nxo` ]* |(vimtex-]star| `nxo` [/ |(vimtex-[/| `nxo` @@ -2965,6 +2970,22 @@ object, see |text-objects|. go to [count] previous end of a math zone. |exlusive| motion. +*(vimtex-]r)* + go to [count] next start of a frame environment. + |exlusive| motion. + +*(vimtex-]R)* + go to [count] next end of a frame environment. + |exlusive| motion. + +*(vimtex-[r)* + go to [count] previous start of a frame environment. + |exlusive| motion. + +*(vimtex-[R)* + go to [count] previous end of a frame environment. + |exlusive| motion. + *(vimtex-]/)* go to [count] next start of a LaTeX comment "%". |exlusive| motion. From dae22d31aad8fb4363c9ffa6c3607525ebd877b9 Mon Sep 17 00:00:00 2001 From: Riccardo Milani Date: Wed, 11 Nov 2020 09:51:47 +0100 Subject: [PATCH 3/3] Add test for frame/beamer motions --- .../test-motions/test-beamer-motions.tex | 45 +++++++++++++++++++ .../test-motions/test-beamer-motions.vim | 26 +++++++++++ 2 files changed, 71 insertions(+) create mode 100644 test/tests/test-motions/test-beamer-motions.tex create mode 100644 test/tests/test-motions/test-beamer-motions.vim diff --git a/test/tests/test-motions/test-beamer-motions.tex b/test/tests/test-motions/test-beamer-motions.tex new file mode 100644 index 0000000000..6528844431 --- /dev/null +++ b/test/tests/test-motions/test-beamer-motions.tex @@ -0,0 +1,45 @@ +\documentclass[]{beamer} + +\begin{document} + +Test file for frame/beamer motion. + +\begin{frame} % [r[r or 2[r + \frametitle{Test I} + Simple frame % [R[R or 2[R +\end{frame} + +\begin{frame} % [r + \frametitle{Test II} + Frame with nested environments. + \begin{equation} + \begin{aligned} + 1 + 1 = & 2 + \end{aligned} + \end{equation} +\end{frame} % [R + +\begin{enumerate} + \item 1 + \item 2 + \item 3 + \item 4 +\end{enumerate} + % CURSOR +\begin{frame} % ]r + \frametitle{Test III} + Frame with nested environments. + \begin{block}{A block} + Block body + \end{block} +\end{frame} % ]R + +\begin{frame} % ]r]r or 2]r + \frametitle{Test IV} + Frame with nested environments. + \begin{exampleblock}{A block} + Block body + \end{exampleblock} +\end{frame} % ]R]R or 2]R + +\end{document} diff --git a/test/tests/test-motions/test-beamer-motions.vim b/test/tests/test-motions/test-beamer-motions.vim new file mode 100644 index 0000000000..8826ed72b4 --- /dev/null +++ b/test/tests/test-motions/test-beamer-motions.vim @@ -0,0 +1,26 @@ +set nocompatible +let &rtp = '../../..,' . &rtp +filetype plugin on +syntax on + +nnoremap q :qall! + +silent edit test-beamer-motions.tex + +if empty($INMAKE) | finish | endif + +" vint: -ProhibitCommandRelyOnUser + +normal 28G2]r +call vimtex#test#assert_equal(line('.'), 37) + +normal 28G]R +call vimtex#test#assert_equal(line('.'), 35) + +normal 28G2[r +call vimtex#test#assert_equal(line('.'), 7) + +normal 28G[R +call vimtex#test#assert_equal(line('.'), 20) + +quit!