Mercurial > vim-lawrencium
comparison autoload/lawrencium.vim @ 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 | 065625e1bb31 |
children | 33cc4af93b44 |
comparison
equal
deleted
inserted
replaced
140:652a6f5df0f3 | 141:4d5f4233b04e |
---|---|
66 echom "lawrencium error: " . a:message | 66 echom "lawrencium error: " . a:message |
67 endfunction | 67 endfunction |
68 | 68 |
69 " Throw a Lawrencium exception message. | 69 " Throw a Lawrencium exception message. |
70 function! lawrencium#throw(message) | 70 function! lawrencium#throw(message) |
71 throw "lawrencium: " . a:message | |
72 endfunction | |
73 | |
74 " Throw a Lawrencium exception message and set Vim's error message. | |
75 function! lawrencium#throwerr(message) | |
71 let v:errmsg = "lawrencium: " . a:message | 76 let v:errmsg = "lawrencium: " . a:message |
72 throw v:errmsg | 77 throw v:errmsg |
73 endfunction | 78 endfunction |
74 | 79 |
75 " }}} | 80 " }}} |
251 | 256 |
252 " Gets a full path given a repo-relative path. | 257 " Gets a full path given a repo-relative path. |
253 function! s:HgRepo.GetFullPath(path) abort | 258 function! s:HgRepo.GetFullPath(path) abort |
254 let l:root_dir = self.root_dir | 259 let l:root_dir = self.root_dir |
255 if lawrencium#isabspath(a:path) | 260 if lawrencium#isabspath(a:path) |
256 call lawrencium#throw("Expected relative path, got absolute path: " . a:path) | 261 call lawrencium#throwerr("Expected relative path, got absolute path: " . a:path) |
257 endif | 262 endif |
258 return lawrencium#normalizepath(l:root_dir . a:path) | 263 return lawrencium#normalizepath(l:root_dir . a:path) |
259 endfunction | 264 endfunction |
260 | 265 |
261 " Gets a repo-relative path given any path. | 266 " Gets a repo-relative path given any path. |
457 endfor | 462 endfor |
458 endfunction | 463 endfunction |
459 | 464 |
460 function! s:Buffer.DefineCommand(name, ...) dict abort | 465 function! s:Buffer.DefineCommand(name, ...) dict abort |
461 if a:0 == 0 | 466 if a:0 == 0 |
462 call lawrencium#throw("Not enough parameters for s:Buffer.DefineCommands()") | 467 call lawrencium#throwerr("Not enough parameters for s:Buffer.DefineCommands()") |
463 endif | 468 endif |
464 if a:0 == 1 | 469 if a:0 == 1 |
465 let l:flags = '' | 470 let l:flags = '' |
466 let l:cmd = a:1 | 471 let l:cmd = a:1 |
467 else | 472 else |
468 let l:flags = a:1 | 473 let l:flags = a:1 |
469 let l:cmd = a:2 | 474 let l:cmd = a:2 |
470 endif | 475 endif |
471 if has_key(self.cmd_names, a:name) | 476 if has_key(self.cmd_names, a:name) |
472 call lawrencium#throw("Command '".a:name."' is already defined in buffer ".self.nr) | 477 call lawrencium#throwerr("Command '".a:name."' is already defined in buffer ".self.nr) |
473 endif | 478 endif |
474 if bufnr('%') != self.nr | 479 if bufnr('%') != self.nr |
475 call lawrencium#throw("You must move to buffer ".self.nr."first before defining local commands") | 480 call lawrencium#throwerr("You must move to buffer ".self.nr."first before defining local commands") |
476 endif | 481 endif |
477 let self.cmd_names[a:name] = 1 | 482 let self.cmd_names[a:name] = 1 |
478 let l:real_flags = '' | 483 let l:real_flags = '' |
479 if type(l:flags) == type('') | 484 if type(l:flags) == type('') |
480 let l:real_flags = l:flags | 485 let l:real_flags = l:flags |
482 execute 'command -buffer '.l:real_flags.' '.a:name.' '.l:cmd | 487 execute 'command -buffer '.l:real_flags.' '.a:name.' '.l:cmd |
483 endfunction | 488 endfunction |
484 | 489 |
485 function! s:Buffer.DeleteCommand(name) dict abort | 490 function! s:Buffer.DeleteCommand(name) dict abort |
486 if !has_key(self.cmd_names, a:name) | 491 if !has_key(self.cmd_names, a:name) |
487 call lawrencium#throw("Command '".a:name."' has not been defined in buffer ".self.nr) | 492 call lawrencium#throwerr("Command '".a:name."' has not been defined in buffer ".self.nr) |
488 endif | 493 endif |
489 if bufnr('%') != self.nr | 494 if bufnr('%') != self.nr |
490 call lawrencium#throw("You must move to buffer ".self.nr."first before deleting local commands") | 495 call lawrencium#throwerr("You must move to buffer ".self.nr."first before deleting local commands") |
491 endif | 496 endif |
492 execute 'delcommand '.a:name | 497 execute 'delcommand '.a:name |
493 call remove(self.cmd_names, a:name) | 498 call remove(self.cmd_names, a:name) |
494 endfunction | 499 endfunction |
495 | 500 |
496 function! s:Buffer.DeleteCommands() dict abort | 501 function! s:Buffer.DeleteCommands() dict abort |
497 if bufnr('%') != self.nr | 502 if bufnr('%') != self.nr |
498 call lawrencium#throw("You must move to buffer ".self.nr."first before deleting local commands") | 503 call lawrencium#throwerr("You must move to buffer ".self.nr."first before deleting local commands") |
499 endif | 504 endif |
500 for name in keys(self.cmd_names) | 505 for name in keys(self.cmd_names) |
501 execute 'delcommand '.name | 506 execute 'delcommand '.name |
502 endfor | 507 endfor |
503 let self.cmd_names = {} | 508 let self.cmd_names = {} |
507 let l:win_nr = bufwinnr(self.nr) | 512 let l:win_nr = bufwinnr(self.nr) |
508 if l:win_nr < 0 | 513 if l:win_nr < 0 |
509 if a:0 > 0 && a:1 == 0 | 514 if a:0 > 0 && a:1 == 0 |
510 return 0 | 515 return 0 |
511 endif | 516 endif |
512 call lawrencium#throw("No windows currently showing buffer ".self.nr) | 517 call lawrencium#throwerr("No windows currently showing buffer ".self.nr) |
513 endif | 518 endif |
514 execute l:win_nr.'wincmd w' | 519 execute l:win_nr.'wincmd w' |
515 return 1 | 520 return 1 |
516 endfunction | 521 endfunction |
517 | 522 |
671 let s:lawrencium_file_readers = {} | 676 let s:lawrencium_file_readers = {} |
672 let s:lawrencium_file_customoptions = {} | 677 let s:lawrencium_file_customoptions = {} |
673 | 678 |
674 function! lawrencium#add_reader(action, callback, ...) abort | 679 function! lawrencium#add_reader(action, callback, ...) abort |
675 if has_key(s:lawrencium_file_readers, a:action) | 680 if has_key(s:lawrencium_file_readers, a:action) |
676 call lawrencium#throw("Lawrencium file '".a:action."' has alredy been registered.") | 681 call lawrencium#throwerr("Lawrencium file '".a:action."' has alredy been registered.") |
677 endif | 682 endif |
678 let s:lawrencium_file_readers[a:action] = function(a:callback) | 683 let s:lawrencium_file_readers[a:action] = function(a:callback) |
679 if a:0 && a:1 | 684 if a:0 && a:1 |
680 let s:lawrencium_file_customoptions[a:action] = 1 | 685 let s:lawrencium_file_customoptions[a:action] = 1 |
681 endif | 686 endif |
683 | 688 |
684 function! lawrencium#read_lawrencium_file(path) abort | 689 function! lawrencium#read_lawrencium_file(path) abort |
685 call lawrencium#trace("Reading Lawrencium file: " . a:path) | 690 call lawrencium#trace("Reading Lawrencium file: " . a:path) |
686 let l:path_parts = lawrencium#parse_lawrencium_path(a:path) | 691 let l:path_parts = lawrencium#parse_lawrencium_path(a:path) |
687 if l:path_parts['root'] == '' | 692 if l:path_parts['root'] == '' |
688 call lawrencium#throw("Can't get repository root from: " . a:path) | 693 call lawrencium#throwerr("Can't get repository root from: " . a:path) |
689 endif | 694 endif |
690 if !has_key(s:lawrencium_file_readers, l:path_parts['action']) | 695 if !has_key(s:lawrencium_file_readers, l:path_parts['action']) |
691 call lawrencium#throw("No registered reader for action: " . l:path_parts['action']) | 696 call lawrencium#throwerr("No registered reader for action: " . l:path_parts['action']) |
692 endif | 697 endif |
693 | 698 |
694 " Call the registered reader. | 699 " Call the registered reader. |
695 let l:repo = lawrencium#hg_repo(l:path_parts['root']) | 700 let l:repo = lawrencium#hg_repo(l:path_parts['root']) |
696 let l:full_path = l:repo.root_dir . l:path_parts['path'] | 701 let l:full_path = l:repo.root_dir . l:path_parts['path'] |