changeset 141:4d5f4233b04e

Only set `v:errmsg` for real errors, not exceptions.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 07 Dec 2016 21:33:18 -0800
parents 652a6f5df0f3
children c9169233d45a
files autoload/lawrencium.vim autoload/lawrencium/diff.vim autoload/lawrencium/log.vim autoload/lawrencium/record.vim autoload/lawrencium/status.vim
diffstat 5 files changed, 21 insertions(+), 16 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/lawrencium.vim	Mon Jun 13 21:55:40 2016 -0700
+++ b/autoload/lawrencium.vim	Wed Dec 07 21:33:18 2016 -0800
@@ -68,6 +68,11 @@
 
 " Throw a Lawrencium exception message.
 function! lawrencium#throw(message)
+    throw "lawrencium: " . a:message
+endfunction
+
+" Throw a Lawrencium exception message and set Vim's error message.
+function! lawrencium#throwerr(message)
     let v:errmsg = "lawrencium: " . a:message
     throw v:errmsg
 endfunction
@@ -253,7 +258,7 @@
 function! s:HgRepo.GetFullPath(path) abort
     let l:root_dir = self.root_dir
     if lawrencium#isabspath(a:path)
-        call lawrencium#throw("Expected relative path, got absolute path: " . a:path)
+        call lawrencium#throwerr("Expected relative path, got absolute path: " . a:path)
     endif
     return lawrencium#normalizepath(l:root_dir . a:path)
 endfunction
@@ -459,7 +464,7 @@
 
 function! s:Buffer.DefineCommand(name, ...) dict abort
     if a:0 == 0
-        call lawrencium#throw("Not enough parameters for s:Buffer.DefineCommands()")
+        call lawrencium#throwerr("Not enough parameters for s:Buffer.DefineCommands()")
     endif
     if a:0 == 1
         let l:flags = ''
@@ -469,10 +474,10 @@
         let l:cmd = a:2
     endif
     if has_key(self.cmd_names, a:name)
-        call lawrencium#throw("Command '".a:name."' is already defined in buffer ".self.nr)
+        call lawrencium#throwerr("Command '".a:name."' is already defined in buffer ".self.nr)
     endif
     if bufnr('%') != self.nr
-        call lawrencium#throw("You must move to buffer ".self.nr."first before defining local commands")
+        call lawrencium#throwerr("You must move to buffer ".self.nr."first before defining local commands")
     endif
     let self.cmd_names[a:name] = 1
     let l:real_flags = ''
@@ -484,10 +489,10 @@
 
 function! s:Buffer.DeleteCommand(name) dict abort
     if !has_key(self.cmd_names, a:name)
-        call lawrencium#throw("Command '".a:name."' has not been defined in buffer ".self.nr)
+        call lawrencium#throwerr("Command '".a:name."' has not been defined in buffer ".self.nr)
     endif
     if bufnr('%') != self.nr
-        call lawrencium#throw("You must move to buffer ".self.nr."first before deleting local commands")
+        call lawrencium#throwerr("You must move to buffer ".self.nr."first before deleting local commands")
     endif
     execute 'delcommand '.a:name
     call remove(self.cmd_names, a:name)
@@ -495,7 +500,7 @@
 
 function! s:Buffer.DeleteCommands() dict abort
     if bufnr('%') != self.nr
-        call lawrencium#throw("You must move to buffer ".self.nr."first before deleting local commands")
+        call lawrencium#throwerr("You must move to buffer ".self.nr."first before deleting local commands")
     endif
     for name in keys(self.cmd_names)
         execute 'delcommand '.name
@@ -509,7 +514,7 @@
         if a:0 > 0 && a:1 == 0
             return 0
         endif
-        call lawrencium#throw("No windows currently showing buffer ".self.nr)
+        call lawrencium#throwerr("No windows currently showing buffer ".self.nr)
     endif
     execute l:win_nr.'wincmd w'
     return 1
@@ -673,7 +678,7 @@
 
 function! lawrencium#add_reader(action, callback, ...) abort
     if has_key(s:lawrencium_file_readers, a:action)
-        call lawrencium#throw("Lawrencium file '".a:action."' has alredy been registered.")
+        call lawrencium#throwerr("Lawrencium file '".a:action."' has alredy been registered.")
     endif
     let s:lawrencium_file_readers[a:action] = function(a:callback)
     if a:0 && a:1
@@ -685,10 +690,10 @@
     call lawrencium#trace("Reading Lawrencium file: " . a:path)
     let l:path_parts = lawrencium#parse_lawrencium_path(a:path)
     if l:path_parts['root'] == ''
-        call lawrencium#throw("Can't get repository root from: " . a:path)
+        call lawrencium#throwerr("Can't get repository root from: " . a:path)
     endif
     if !has_key(s:lawrencium_file_readers, l:path_parts['action'])
-        call lawrencium#throw("No registered reader for action: " . l:path_parts['action'])
+        call lawrencium#throwerr("No registered reader for action: " . l:path_parts['action'])
     endif
 
     " Call the registered reader.
--- a/autoload/lawrencium/diff.vim	Mon Jun 13 21:55:40 2016 -0700
+++ b/autoload/lawrencium/diff.vim	Wed Dec 07 21:33:18 2016 -0800
@@ -127,7 +127,7 @@
     " It's needed because `diffoff` reverts those settings to their default
     " values, instead of their previous ones.
     if &diff
-        call lawrencium#throw("Calling diffthis too late on a buffer!")
+        call lawrencium#throwerr("Calling diffthis too late on a buffer!")
         return
     endif
     call lawrencium#trace('Enabling diff mode on ' . bufname('%'))
--- a/autoload/lawrencium/log.vim	Mon Jun 13 21:55:40 2016 -0700
+++ b/autoload/lawrencium/log.vim	Wed Dec 07 21:33:18 2016 -0800
@@ -167,7 +167,7 @@
     " Behold, Vim's look-ahead regex syntax again! WTF.
     let l:rev = matchstr(l:line, '\v^(\d+)(\:)@=')
     if l:rev == ''
-        call lawrencium#throw("Can't parse revision number from line: " . l:line)
+        call lawrencium#throwerr("Can't parse revision number from line: " . l:line)
     endif
     return l:rev
 endfunction
--- a/autoload/lawrencium/record.vim	Mon Jun 13 21:55:40 2016 -0700
+++ b/autoload/lawrencium/record.vim	Wed Dec 07 21:33:18 2016 -0800
@@ -70,7 +70,7 @@
     endif
 
     if !exists('b:lawrencium_record_for')
-        call lawrencium#throw("This doesn't seem like a record buffer, something's wrong!")
+        call lawrencium#throwerr("This doesn't seem like a record buffer, something's wrong!")
     endif
     if b:lawrencium_record_for == '%'
         " Switch to the 'recording' buffer's window.
@@ -149,7 +149,7 @@
     let l:buf_obj = lawrencium#buffer_obj(a:buf_nr)
     call l:buf_obj.MoveToFirstWindow()
     if !exists('b:lawrencium_record_for') || b:lawrencium_record_for != '%'
-        call lawrencium#throw("Cleaning up something else than the original buffer ".
+        call lawrencium#throwerr("Cleaning up something else than the original buffer ".
                 \"for a record operation. That's suspiciously incorrect! ".
                 \"Aborting.")
     endif
--- a/autoload/lawrencium/status.vim	Mon Jun 13 21:55:40 2016 -0700
+++ b/autoload/lawrencium/status.vim	Wed Dec 07 21:33:18 2016 -0800
@@ -85,7 +85,7 @@
         let l:win_nr = bufwinnr(a:1)
         call lawrencium#trace("Switching back to status window ".l:win_nr)
         if l:win_nr < 0
-            call lawrencium#throw("Can't find the status window anymore!")
+            call lawrencium#throwerr("Can't find the status window anymore!")
         endif
         execute l:win_nr . 'wincmd w'
         " Delete everything in the buffer, and re-read the status into it.