Skip to content

Commit

Permalink
ENH: Add context parameter to lh#warning#emit()
Browse files Browse the repository at this point in the history
  • Loading branch information
LucHermitte committed Nov 26, 2024
1 parent d51bc71 commit b8d79fe
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
14 changes: 10 additions & 4 deletions autoload/lh/warning.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
" Version: 5.4.0.
let s:k_version = '540'
" Created: 20th Feb 2024
" Last Update: 20th Feb 2024
" Last Update: 26th Nov 2024
"------------------------------------------------------------------------
" Description:
" Support functions for emitting warnings that remember their context
Expand Down Expand Up @@ -63,9 +63,15 @@ function! lh#warning#clear() abort
let s:warnings = []
endfunction

" Function: lh#warning#emit(message) {{{2
function! lh#warning#emit(message) abort
let context = lh#exception#callstack_as_qf_from('lh#warning', [a:message, 'W'])
" Function: lh#warning#emit(message [, context]) {{{2
function! lh#warning#emit(message, ...) abort
if a:0 == 0
let context = lh#exception#callstack_as_qf_from('lh#warning', [a:message, 'W'])
elseif type(a:1) == type({}) " let's suppose it's already a context object
let context = a:1
else " Let's suppose it's a throwpoint
let context = lh#exception#decode(a:1).as_qf_from('lh#warning', [a:message, 'W'])
endif
call add(s:warnings, [a:message, context])
call lh#common#warning_msg(a:message)
endfunction
Expand Down
9 changes: 7 additions & 2 deletions doc/lh-vim-lib.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*lh-vim-lib.txt* Vim common libraries (v5.4.0)
For Vim version 7+ Last change: 14th Oct 2024
For Vim version 7+ Last change: 26th Nov 2024

By Luc Hermitte
hermitte {at} free {dot} fr
Expand Down Expand Up @@ -4399,12 +4399,17 @@ The warning cache is:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*lh#warning#emit()* {{{3
lh#warning#emit(message)~
lh#warning#emit(message [, context])~
Emits a new warning as a coloured message.
Also the |callstack|| is automatically recorded when calling the function.
It's cached with the message for future display in the |quickfix-window| with
|:Warnings|.

@param {message} Message printed and registered
@param {context} Optional context. Can be |v:throwpoint|, or a |setqflist()|
compatible |Dictionary| that could be returned by
`lh#exception#decode().as_qf()`.

@since Version 5.4.0

------------------------------------------------------------------------------
Expand Down

0 comments on commit b8d79fe

Please sign in to comment.