Commits

ZyX_I committed 41e6469

Added more local themes

Comments (0)

Files changed (2)

autoload/aurum/powerline.vim

 scriptencoding utf-8
 execute frawor#Setup('0.0', {'@%aurum/cache': '2.3',
             \                 '@%aurum/repo': '5.0',
+            \              '@%aurum/bufvars': '0.0',
             \             '@%aurum/cmdutils': '4.2',
             \                     '@/python': '1.0',})
 python import aurum.powerline
 "▶1 VimEnter
 function s:F.define_local_themes()
 python <<EOF
+buffer_type_hl = [u"aurum_buffer_type", u"line_current_symbol"]
+filler_segment = {u"type": u"string", u"width": u"auto", u"highlight_group": u"background", "draw_divider": False}
 powerline.add_local_theme("aurum.powerline.is_commit", {
     u"default_module": u"aurum.powerline",
     u"segments": {
             {
                 u"name": u"mode",
                 u"module": u"powerline.segments.vim",
+                u"priority": 40,
             },
             {
                 u"type": u"string",
                 u"contents": u"Commit",
-                u"highlight_group": [u"line_current_symbol"],
+                u"highlight_group": buffer_type_hl,
+                u"priority": 20,
             },
             {
                 u"name": u"branch",
+                u"priority": 35,
+            },
+            filler_segment
+        ],
+        u"right": [
+            {
+                u"name": "virtcol_current",
+                u"module": u"powerline.segments.vim",
+                u"priority": 30,
+            },
+        ],
+    }
+})
+powerline.add_local_theme("aurum.powerline.is_annotate", {
+    u"default_module": u"aurum.powerline",
+    u"segments": {
+        u"left": [
+            {
+                u"type": u"string",
+                u"contents": u"Ann",
+                u"highlight_group": buffer_type_hl,
+                u"priority": 30,
+            },
+            {
+                u"name": u"annotated_changeset",
+                u"priority": 40,
+            },
+        ],
+        u"right": [
+        ],
+    }
+})
+powerline.add_local_theme("aurum.powerline.is_status", {
+    u"default_module": u"aurum.powerline",
+    u"segments": {
+        u"left": [
+            {
+                u"type": u"string",
+                u"contents": u"Status",
+                u"highlight_group": buffer_type_hl,
+                u"priority": 30,
+            },
+            {
+                u"name": u"status_changesets",
+                u"priority": 40,
+            },
+        ],
+        u"right": [
+        ],
+    }
+})
+powerline.add_local_theme("aurum.powerline.is_log", {
+    u"default_module": u"aurum.powerline",
+    u"segments": {
+        u"left": [
+            {
+                u"type": u"string",
+                u"contents": u"Log",
+                u"highlight_group": buffer_type_hl,
+                u"priority": 30,
+            },
+            {
+                u"name": u"repository_root",
+                u"priority": 33,
+            },
+            {
+                u"name": u"log_options",
+                u"priority": 40,
+            },
+            filler_segment
+        ],
+        u"right": [
+            {
+                u"name": "line_percent",
+                u"module": u"powerline.segments.vim",
+                u"priority": 37,
+                # Keys args, after, width and align must be inherited from the 
+                # top theme (currently not implemented)
+            },
+            {
+                u"name": "line_current",
+                u"module": u"powerline.segments.vim",
+                u"priority": 35,
+            },
+        ],
+    }
+})
+powerline.add_local_theme("aurum.powerline.is_file", {
+    u"default_module": u"aurum.powerline",
+    u"segments": {
+        u"left": [
+            {
+                u"type": u"string",
+                u"contents": u"File",
+                u"highlight_group": buffer_type_hl,
+                u"priority": 30,
+            },
+            {
+                u"name": u"repository_root",
+                u"priority": 33,
+            },
+            {
+                u"name": u"file_directory",
+                u"priority": 40,
+            },
+            {
+                u"name": u"file_name",
+                u"priority": 45,
+            },
+            filler_segment
+        ],
+        u"right": [
+            {
+                u"name": "line_percent",
+                u"module": u"powerline.segments.vim",
+                u"priority": 37,
+                # Keys args, after, width and align must be inherited from the 
+                # top theme (currently not implemented)
+            },
+            {
+                u"name": "line_current",
+                u"module": u"powerline.segments.vim",
+                u"priority": 35,
+            },
+        ],
+    }
+})
+powerline.add_local_theme("aurum.powerline.is_diff", {
+    u"default_module": u"aurum.powerline",
+    u"segments": {
+        u"left": [
+            {
+                u"type": u"string",
+                u"contents": u"Diff",
+                u"highlight_group": buffer_type_hl,
+                u"priority": 30,
+            },
+            {
+                u"name": u"repository_root",
+                u"priority": 33,
+            },
+            {
+                u"name": u"diff_files",
+                u"priority": 40,
+            },
+            filler_segment
+        ],
+        u"right": [
+            {
+                u"name": u"diff_changesets",
+                u"priority": 38,
+            },
+            {
+                u"name": "line_percent",
+                u"module": u"powerline.segments.vim",
+                u"priority": 37,
+                # Keys args, after, width and align must be inherited from the 
+                # top theme (currently not implemented)
+            },
+            {
+                u"name": "line_current",
+                u"module": u"powerline.segments.vim",
+                u"priority": 35,
             },
         ],
     }

python/aurum/powerline.py

+from __future__ import absolute_import
 from importlib import import_module
 from collections import namedtuple
 from time import time
 import aurum.repeatedcmd as rc
 import vim
 from os.path import dirname, isdir, join, relpath
+from powerline.theme import requires_segment_info
+from powerline.bindings.vim import getbufvar, vim_get_func
+from powerline.lib.memoize import memoize
 
 Funcs = namedtuple('Funcs', 'branch status')
 dummy_func = lambda *args : None
 funcs_cache = {}
 fname_cache = {}
 
+def plugin_eval(expr):
+    global plugin_eval
+    plugin_eval = vim_get_func('<SNR>'+sid+'_Eval')
+    return plugin_eval(expr)
+
 if hasattr(vim, 'bindeval'):
     self_dict = vim.bindeval('{}')
 
     def get_repo(path):
         global get_repo
-        vim_get_repo = vim.bindeval('<SNR>'+sid+'_Eval("s:_r.repo.get")')
+        vim_get_repo = plugin_eval('s:_r.repo.get')
         get_repo = lambda path: vim_get_repo(path, self=self_dict)
         return get_repo(path)
 
     def get_interval(key):
         global get_interval
-        vim_get_interval = vim.bindeval('<SNR>'+sid+'_Eval("s:_r.cache.getinterval")')
+        vim_get_interval = plugin_eval('s:_r.cache.getinterval')
         get_interval = lambda key: vim_get_interval(key, self=self_dict)
         return get_interval(key)
 
 
     def get_rrf():
         global get_rrf
-        vim_get_rrf = vim.bindeval('<SNR>'+sid+'_Eval("s:_r.cmdutils.getrrf")')
+        vim_get_rrf = plugin_eval('s:_r.cmdutils.getrrf')
         get_rrf = lambda : list(vim_get_rrf(rf_dict, 0, 'getsilent', self=self_dict))[1:]
         return get_rrf()
 
+    # bufvars = plugin_eval('')
+
 else:
     import json
     def get_repo(path):
-        return vim.eval('<SNR>'+sid+'_Eval(printf("s:_r.repo.get(%s)", string('+json.dumps(path)+')))')
+        return plugin_eval('s:_r.repo.get('+json.dumps(path)+')')
 
     def get_interval(key):
-        return float(vim.eval('<SNR>'+sid+'_Eval("s:_r.cache.getinterval(\''+key+'\')")'))
+        return float(plugin_eval('s:_r.cache.getinterval("'+key+'")'))
 
     def get_rrf():
-        return vim.eval('<SNR>'+sid+'_Eval("s:_r.cmdutils.getrrf({\'repo\': \':\'}, 0, \'getsilent\')")[1:]')
+        return plugin_eval('s:_r.cmdutils.getrrf({"repo": ":"}, 0, "getsilent")[1:]')
 
-def get_rf():
+def get_rf(bufnr):
     global funcs_cache
     global fname_cache
 
-    bufnr = vim.current.buffer.number
-
     if bufnr in fname_cache and (time()-fname_cache[bufnr][1]) < get_repo_interval():
         return funcs_cache[bufnr][0], fname_cache[bufnr][0]
 
     except:
         return None
 
-def guess():
+def guess(bufnr):
     global funcs_cache
 
-    bufnr = vim.current.buffer.number
-
     if bufnr in funcs_cache and (time()-funcs_cache[bufnr][1]) < get_repo_interval():
         return funcs_cache[bufnr][0]
 
         if 'funcs' in bdict:
             funcs = bdict['funcs']
         else:
-            funcs = guess()
+            funcs = guess(bufnr)
             bdict['funcs'] = funcs
     else:
         bdict['funcs'] = funcs
 
     return bdict['rcids'][func_name]
 
-def branch():
-    bsetup = setup_buffer(vim.current.buffer.number, 'branch')
+@requires_segment_info
+def branch(pl, segment_info):
+    bsetup = setup_buffer(segment_info['bufnr'], 'branch')
     if bsetup is None:
         return None
     return rc.get(bsetup)
 
-def file_vcs_status():
-    if not vim.current.buffer.name or vim.eval('&buftype'):
+@requires_segment_info
+def file_vcs_status(pl, segment_info):
+    if not segment_info['buffer'].name or getbufvar(segment_info['bufnr'], '&buftype'):
         return None
 
-    funcs, fname = get_rf()
+    funcs, fname = get_rf(segment_info['bufnr'])
     if not fname or not funcs:
         return None
 
-    bsetup = setup_buffer(vim.current.buffer.number, 'status', funcs, fname)
+    bsetup = setup_buffer(segment_info['bufnr'], 'status', funcs, fname)
     if bsetup is None:
         return None
 
             'highlight': ['file_vcs_status_'+statchar, 'file_vcs_status']
            }]
 
+persistent = lambda : memoize(100000, cache_key=lambda segment_info, **kwargs: segment_info['bufnr'])
+
+@requires_segment_info
+@persistent()
+def annotated_changeset(pl, segment_info):
+    pass
+
+@requires_segment_info
+@persistent()
+def status_changesets(pl, segment_info):
+    pass
+
+@requires_segment_info
+@persistent()
+def diff_changesets(pl, segment_info):
+    pass
+
+@requires_segment_info
+@persistent()
+def diff_files(pl, segment_info):
+    pass
+
+@requires_segment_info
+@persistent()
+def log_options(pl, segment_info):
+    pass
+
+@requires_segment_info
+@persistent()
+def repository_root(pl, segment_info):
+    pass
+
+@requires_segment_info
+@persistent()
+def file_directory(pl, segment_info):
+    pass
+
+@requires_segment_info
+@persistent()
+def file_name(pl, segment_info):
+    pass
+
 def is_commit(matcher_info):
-    return vim.eval('getbufvar({0}, "&ft")'.format(matcher_info['bufnr'])) == 'aurumcommit'
+    return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumcommit'
+
+def is_annotate(matcher_info):
+    return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumannotate'
+
+def is_status(matcher_info):
+    return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumstatus'
+
+def is_log(matcher_info):
+    return getbufvar(matcher_info['bufnr'], '&filetype') == 'aurumlog'
+
+sep = None
+
+def is_file(matcher_info):
+    global sep
+    if not sep:
+        sep = vim.eval('fnamemodify(".", ":p")')[-1]
+    name = matcher_info['buffer'].name
+    return name and name.startswith('aurum:'+sep+sep+'file:')
+
+def is_diff(matcher_info):
+    global sep
+    if not sep:
+        sep = vim.eval('fnamemodify(".", ":p")')[-1]
+    name = matcher_info['buffer'].name
+    return name and name.startswith('aurum:'+sep+sep+'diff:')
 
 # vim: ft=python ts=4 sw=4 sts=4 et tw=120
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.