-
Notifications
You must be signed in to change notification settings - Fork 0
/
filesrc.py
37 lines (28 loc) · 1.03 KB
/
filesrc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# ============================================================================
# FILE: filesrc.py
# AUTHOR: Andrew Pyatkov <andrew.pyatkov at gmail.com>
# License: MIT license
# ============================================================================
from .base import Base
from os.path import exists, getmtime, expandvars, expanduser
class Source(Base):
def __init__(self, vim):
super().__init__(vim)
self.name = 'filesrc'
self.mark = '[f]'
self.__cache = []
self.__mtime = 0
def on_init(self, context):
self.__filepath = expandvars(expanduser(
context['vars'].get('deoplete#filesrc#path', '')))
def on_event(self, context):
if not exists(self.__filepath):
return
mtime = getmtime(self.__filepath)
if mtime == self.__mtime:
return
self.__mtime = mtime
with open(self.__filepath, 'r') as f:
self.__cache = f.read().split()
def gather_candidates(self, context):
return self.__cache