Auto insert last added image in figure snippet

This commit is contained in:
Pavel Korytov 2019-10-18 16:57:21 +03:00
parent f7ec83d186
commit bfa5fb959a
2 changed files with 34 additions and 1 deletions

View file

@ -371,7 +371,7 @@ let g:startify_custom_header = [
\ ' /____/\__, /_/ \__/_/ /_/_/_/ /_/\__,_/____/\____/_/ /_/\___/ ',
\ ' /_/ ',
\ ' ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――',
\ ' Unity. Precision. Perfection. ',
\ ' Conquering the darkest places ',
\ ]
" }}}

View file

@ -2,6 +2,22 @@ priority 50
extends eltech
global !p
import os
def get_last_image():
max_time = 0
last_image = ''
for r, d, files in os.walk(os.path.join(os.getcwd(), 'img')):
for f in files:
time = os.path.getmtime(os.path.join(r, f))
if time > max_time:
max_time = time
last_image = os.path.relpath(os.path.join(r, f))
return last_image
endglobal
snippet 'sympy(.*)sympy' "evaluate sympy" wr
`!p
from sympy import *
@ -16,6 +32,23 @@ snip.rv = eval('latex(' + match.group(1).replace('\\', '') \
`
endsnippet
snippet lfigp "last figure path"
`!p
snip.rv = get_last_image()
`
endsnippet
snippet lfig
\begin{figure}[h]
\centering
\includegraphics[width=$1\textwidth]{`!p snip.rv = get_last_image()`}
\caption{$2}%
\label{img:$3}
\end{figure}
$0
endsnippet
snippet vec "vector sign"
\vec{$0}
endsnippet