From bfa5fb959a5ef7b5b8f362992414ff5e0380433d Mon Sep 17 00:00:00 2001 From: SqrtMinusOne Date: Fri, 18 Oct 2019 16:57:21 +0300 Subject: [PATCH] Auto insert last added image in figure snippet --- nvim/init.vim | 2 +- nvim/my-snippets/UltiSnips/tex.snippets | 33 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/nvim/init.vim b/nvim/init.vim index 951d8f5..fc9d097 100644 --- a/nvim/init.vim +++ b/nvim/init.vim @@ -371,7 +371,7 @@ let g:startify_custom_header = [ \ ' /____/\__, /_/ \__/_/ /_/_/_/ /_/\__,_/____/\____/_/ /_/\___/ ', \ ' /_/ ', \ ' ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――', - \ ' Unity. Precision. Perfection. ', + \ ' Conquering the darkest places ', \ ] " }}} diff --git a/nvim/my-snippets/UltiSnips/tex.snippets b/nvim/my-snippets/UltiSnips/tex.snippets index bdf8496..502878b 100644 --- a/nvim/my-snippets/UltiSnips/tex.snippets +++ b/nvim/my-snippets/UltiSnips/tex.snippets @@ -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