Commit 93723e9a authored by Adrien Dorsaz's avatar Adrien Dorsaz
Browse files

transform as VIM plugin, use Gio.File to retrieve file info

parent 85aa93b8
# gtk-recent.vim - a gnome logger for Vim
## Behaviour
If you modify a file with vim and want to upload it on a web interface, you wish you could find this file in Firefox's "recent files" category. Well now you can : with this plugin, each opened file will be added to Gnome's recent list (and to Zeitgeist as a consequence, see [Gnome's wiki](https://wiki.gnome.org/Attic/GtkRecentManagerAndZeitgeist#Usage_in_applications)).
This extension add files opened with vim to the GNOME recent files feature
(visible in the "Recent files" view of GNOME File Manager and file chooser).
## Limitations
This thing adds quite a huge latency to vim startup/shutdown. I made a C
version that you can find [here](git.relatif.moi/lafleur/flagRecent).
This plugin adds quite a huge latency to vim startup/shutdown.
## Installation
If you're using Arch linux, there's a PKGBUILD : https://aur.archlinux.org/packages/vim-gtk-recent-git .
Drop this file in a vim plugin folder ($HOME/.vim/plugin,/usr/share/vim/vimfiles/plugin, ...). Vim should be compiled with python enabled.
You will need to have python-gobject installed, and vim or neovim with python support.
This is a vim plugin which can be installed with default vim plugin manager.
## History
Derived from :
https://bougui505.github.io/2016/04/20/adding_vim_data-source_to_zeitgeist.html
Improved to use python 3, and to use [GtkRecentManager](https://bstern.org/gtk+-2.24/GtkRecentManager.html).
* [Port to python3 and GtkRecentManager by lafleur](https://gitlab.gnome.org/lafleur/vim-gtk-recent)
* [Original idea](https://bougui505.github.io/2016/04/20/adding_vim_data-source_to_zeitgeist.html)
## License
......
......@@ -9,16 +9,22 @@ if v:version < 703
finish
endif
function! GtkRecentLog(filename,use_id)
function! GtkRecentLog(filename)
python3 << endpython
filename = vim.eval("a:filename")
manager = Gtk.RecentManager()
recent_data = Gtk.RecentData()
recent_data.app_name = "vi"
recent_data.mime_type = "text/plain"
recent_data.app_exec = "vi"
manager.add_full("file://" + filename, recent_data)
try:
# Use Gio to ensure file exists and retrieve content type
file = Gio.File.new_for_path(filename)
info = file.query_info(Gio.FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, Gio.FileQueryInfoFlags.NONE)
manager = Gtk.RecentManager()
recent_data = Gtk.RecentData()
recent_data.app_name = "vim"
recent_data.mime_type = info.get_content_type()
recent_data.app_exec = "vim %f"
recent_data.is_private = False
manager.add_full(file.get_uri(), recent_data)
except:
pass
endpython
endfunction
......@@ -29,13 +35,12 @@ import vim
from gi import require_version
require_version('Gtk', '3.0')
from gi.repository import Gtk
from gi.repository import Gio
endpython
if match(system('whoami'), 'root') == -1
augroup gtkRecent
au!
au BufRead * call GtkRecentLog (expand("%:p"), "read")
au BufNewFile * call GtkRecentLog (expand("%:p"), "new")
au BufWrite * call GtkRecentLog (expand("%:p"), "write")
au!
au BufNewFile,BufRead,BufWrite,BufEnter,VimEnter * call GtkRecentLog (expand("%:p"))
augroup END
endif
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment