From d6198095041e7967a409915583a2f200bfe49010 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Wed, 23 Dec 2020 15:40:21 +0800 Subject: [PATCH] better error handling --- plugin/fcitx.py | 5 ++++- plugin/fcitx.vim | 8 +++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/plugin/fcitx.py b/plugin/fcitx.py index 01d1689..3dc9ef5 100644 --- a/plugin/fcitx.py +++ b/plugin/fcitx.py @@ -18,7 +18,10 @@ class FcitxComm(): def deactivate(self): self.fcitx.Deactivate() -Fcitx = FcitxComm() +try: + Fcitx = FcitxComm() +except dbus.exceptions.DBusException as e: + vim.command('echohl WarningMsg | echom "fcitx.vim not loaded: %s" | echohl NONE' % e) def may_reconnect(func): @functools.wraps(func) diff --git a/plugin/fcitx.vim b/plugin/fcitx.vim index 3d43647..6a414e9 100644 --- a/plugin/fcitx.vim +++ b/plugin/fcitx.vim @@ -12,9 +12,11 @@ let s:keepcpo = &cpo set cpo&vim let g:loaded_fcitx = 1 -exe 'py3file' expand(':r') . '.py' -au InsertLeave * py3 fcitx2en() -au InsertEnter * py3 fcitx2zh() +try " abort on fail + exe 'py3file' expand(':r') . '.py' + au InsertLeave * py3 fcitx2en() + au InsertEnter * py3 fcitx2zh() +endtry " --------------------------------------------------------------------- " Restoration And Modelines: let &cpo=s:keepcpo