From a021d256eaf425add2b70986e1f5e2a3125e96de Mon Sep 17 00:00:00 2001 From: Ingo Karkat Date: Fri, 18 Nov 2016 00:00:00 +0000 Subject: [PATCH] - After a jump to another file, also re-query the jumps, because the jumplist got updated with the text for the jumps, whereas it previously only contained the buffer name. Thanks to Daniel Hahler for sending a patch. - Especially in small terminals, jump messages may not fit and cause a hit-enter prompt. Truncate messages in s:Echo(). - Local jump message only considers the header, but not the file jump messages. If its one, and cmdheight is 1, add its width to the number of reserved columns, as we append the following location. Thanks to Daniel Hahler for the patch. - The warning message before a remote jump isn't truncated to fit. - Minor: Use ingo#compat#abs(). --- autoload/EnhancedJumps.vim | 66 ++++++++++++++++++++---------- autoload/EnhancedJumps/Changes.vim | 11 ++--- doc/EnhancedJumps.txt | 16 +++++++- 3 files changed, 62 insertions(+), 31 deletions(-) diff --git a/autoload/EnhancedJumps.vim b/autoload/EnhancedJumps.vim index 037ac6c..817142a 100644 --- a/autoload/EnhancedJumps.vim +++ b/autoload/EnhancedJumps.vim @@ -3,15 +3,32 @@ " DEPENDENCIES: " - EnhancedJumps/Common.vim autoload script " - ingo/avoidprompt.vim autoload script +" - ingo/compat.vim autoload script " - ingo/msg.vim autoload script " - ingo/record.vim autoload script " -" Copyright: (C) 2009-2014 Ingo Karkat +" Copyright: (C) 2009-2016 Ingo Karkat " The VIM LICENSE applies to this script; see ':help copyright'. " " Maintainer: Ingo Karkat " " REVISION DATE REMARKS +" 3.03.020 18-Nov-2016 After a jump to another file, also re-query the +" jumps, because the jumplist got updated with the +" text for the jumps, whereas it previously only +" contained the buffer name. Thanks to Daniel +" Hahler for sending a patch. +" Especially in small terminals, jump messages may +" not fit and cause a hit-enter prompt. Truncate +" messages in s:Echo(). +" Local jump message only considers the +" header, but not the file jump messages. If its +" one, and cmdheight is 1, add its width to the +" number of reserved columns, as we append the +" following location. Thanks to Daniel Hahler for +" the patch. +" The warning message before a remote jump isn't +" truncated to fit. " 3.02.019 29-Sep-2014 Add g:EnhancedJumps_CaptureJumpMessages " configuration to turn off the capturing of the " messages during the jump, as the used :redir may @@ -224,15 +241,16 @@ function! s:DoJump( count, isNewer ) endfunction function! s:Echo( fileJumpMessages, message ) if empty(a:fileJumpMessages) - echo a:message + echo ingo#avoidprompt#Truncate(a:message) elseif &cmdheight > 1 || len(a:fileJumpMessages) > 1 for l:message in a:fileJumpMessages echomsg l:message endfor - echo a:message + echo ingo#avoidprompt#Truncate(a:message) else - echomsg a:fileJumpMessages[0] . ' ' - echon a:message + let l:message = ingo#avoidprompt#Truncate(a:message, ingo#compat#strdisplaywidth(a:fileJumpMessages[0]) + 1) " The captured jump message may contain unprintable or non-ASCII characters; use strdisplaywidth(). + echomsg a:fileJumpMessages[0] . (empty(l:message) ? '' : ' ') + echon l:message endif endfunction function! s:EchoFollowingMessage( followingJump, jumpDirection, filterName, fileJumpMessages ) @@ -246,11 +264,15 @@ function! s:EchoFollowingMessage( followingJump, jumpDirection, filterName, file elseif s:IsJumpInCurrentBuffer(l:following) let l:header = printf('next%s: %d,%d ', a:filterName, l:following.lnum, l:following.col) call s:Echo(a:fileJumpMessages, l:header) + let l:reservedColumns = len(l:header) " l:header is printable ASCII-only, so can use len() for text width. + if len(a:fileJumpMessages) == 1 && &cmdheight == 1 + let l:reservedColumns += ingo#compat#strdisplaywidth(a:fileJumpMessages[0], l:reservedColumns) + 1 " The captured jump message may contain unprintable or non-ASCII characters; use strdisplaywidth(); it starts after the header, so consider its width, too. + endif echohl Directory - echon ingo#avoidprompt#Truncate(l:following.text, strlen(l:header)) | " l:header is printable ASCII-only, so can use strlen() for text width. + echon ingo#avoidprompt#Truncate(getline(l:following.lnum), l:reservedColumns) echohl None else - call s:Echo(a:fileJumpMessages, ingo#avoidprompt#Truncate(printf('next%s: %s', a:filterName, s:BufferName(l:following.text)))) + call s:Echo(a:fileJumpMessages, printf('next%s: %s', a:filterName, s:BufferName(l:following.text))) endif endfunction function! EnhancedJumps#Jump( isNewer, filter ) @@ -311,20 +333,20 @@ function! EnhancedJumps#Jump( isNewer, filter ) call s:DoJump(l:jumpCount, a:isNewer) endif - if a:filter ==# 'remote' - " After the jump to another file, the filtered list for - " remote files becomes wrong in case the following file is - " the same as the original file (i.e. A(original) -> B(jump) - " -> A(following)), because that jump was initially filtered - " out. To correctly determine the following jump, we must - " re-query and re-filter the jumps. - " In addition, the file paths to the file may have changed - " due to changes in CWD / 'autochdir'. - let l:followingJump = get( - \ s:FilterJumps(EnhancedJumps#Common#SliceJumpsInDirection(EnhancedJumps#Common#GetJumps('jumps'), a:isNewer), a:filter, a:isNewer), - \ 0, '' - \) - endif + " After the jump to another file, the filtered list for + " remote files becomes wrong in case the following file is + " the same as the original file (i.e. A(original) -> B(jump) + " -> A(following)), because that jump was initially filtered + " out. To correctly determine the following jump, we must + " re-query and re-filter the jumps. + " In addition, the file paths to the file may have changed + " due to changes in CWD / 'autochdir'. + " For local files the jumplist gets updated with the text for + " the jumps, while it only contained the buffer name before. + let l:followingJump = get( + \ s:FilterJumps(EnhancedJumps#Common#SliceJumpsInDirection(EnhancedJumps#Common#GetJumps('jumps'), a:isNewer), a:filter, a:isNewer), + \ 0, '' + \) call s:EchoFollowingMessage(l:followingJump, l:jumpDirection, l:filterName, \ filter( @@ -343,7 +365,7 @@ function! EnhancedJumps#Jump( isNewer, filter ) " jump command to overcome the warning. let t:lastJumpCommandCount = l:count - call ingo#msg#WarningMsg(printf('next%s: %s', l:filterName, s:BufferName(l:target.text))) + call ingo#msg#WarningMsg(ingo#avoidprompt#Truncate(printf('next%s: %s', l:filterName, s:BufferName(l:target.text)))) " Signal edge case via beep. execute "normal! \\\" diff --git a/autoload/EnhancedJumps/Changes.vim b/autoload/EnhancedJumps/Changes.vim index df9cd5a..df8ef1b 100644 --- a/autoload/EnhancedJumps/Changes.vim +++ b/autoload/EnhancedJumps/Changes.vim @@ -5,12 +5,13 @@ " - ingo/msg.vim autoload script " - ingo/window/dimensions.vim autoload script " -" Copyright: (C) 2012-2014 Ingo Karkat +" Copyright: (C) 2012-2015 Ingo Karkat " The VIM LICENSE applies to this script; see ':help copyright'. " " Maintainer: Ingo Karkat " " REVISION DATE REMARKS +" 3.03.007 24-Feb-2015 Minor: Use ingo#compat#abs(). " 3.02.006 05-May-2014 Use ingo#msg#WarningMsg(). " 3.01.005 14-Jun-2013 Use ingo/msg.vim. " 3.01.004 05-Jun-2013 Handle it when the :changes command sometimes @@ -27,10 +28,6 @@ let s:save_cpo = &cpo set cpo&vim -function! s:abs( num1, num2 ) - let l:difference = a:num1 - a:num2 - return (l:difference >= 0 ? l:difference : -1 * l:difference) -endfunction function! s:FilterNearJumps( jumps, startLnum, endLnum, nearHeight ) "****D echomsg '####' a:startLnum a:endLnum let l:farJumps = [] @@ -48,8 +45,8 @@ function! s:FilterNearJumps( jumps, startLnum, endLnum, nearHeight ) \ l:currentParsedJump.lnum < a:startLnum || \ l:currentParsedJump.lnum > a:endLnum \) && ( - \ s:abs(l:currentParsedJump.lnum, l:prevParsedJump.lnum) > a:nearHeight || - \ s:abs(l:currentParsedJump.lnum, l:lastLnum) > a:nearHeight + \ ingo#compat#abs(l:currentParsedJump.lnum - l:prevParsedJump.lnum) > a:nearHeight || + \ ingo#compat#abs(l:currentParsedJump.lnum - l:lastLnum) > a:nearHeight \) call add(l:farJumps, a:jumps[l:i]) let l:lastLnum = l:currentParsedJump.lnum diff --git a/doc/EnhancedJumps.txt b/doc/EnhancedJumps.txt index 93ee8b8..cd843a5 100644 --- a/doc/EnhancedJumps.txt +++ b/doc/EnhancedJumps.txt @@ -120,7 +120,7 @@ warning about jumping into another buffer defaults to (roughly) two seconds. To change the timeout, set a different value (in milliseconds): > let g:stopFirstAndNotifyTimeoutLen = 2000 < - *g:EnhancedJumps_CaptureJumpMessages* + *g:EnhancedJumps_CaptureJumpMessages* Jumps to another buffer happen with "redir => l:fileJumpCapture". If other plugins triggered by the (e.g. BufWinEnter) event do another :redir, this causes an error, because nested redirs are prohibited. You can avoid this @@ -172,6 +172,18 @@ IDEAS *EnhancedJumps-ideas* ============================================================================== HISTORY *EnhancedJumps-history* +3.03 18-Nov-2016 +- After a jump to another file, also re-query the jumps, because the jumplist + got updated with the text for the jumps, whereas it previously only + contained the buffer name. Thanks to Daniel Hahler for sending a patch. +- Especially in small terminals, jump messages may not fit and cause a + hit-enter prompt. Truncate messages in s:Echo(). Local jump message only + considers the header, but not the file jump messages. If its one, and + cmdheight is 1, add its width to the number of reserved columns, as we + append the following location. Thanks to Daniel Hahler for the patch. +- The warning message before a remote jump isn't truncated to fit. +- Minor: Use ingo#compat#abs(). + 3.02 29-Sep-2014 - Add g:EnhancedJumps_CaptureJumpMessages configuration to turn off the capturing of the messages during the jump, as the used :redir may cause @@ -226,7 +238,7 @@ BF: A '^\)' in the jump text caused "E55: Unmatched \)" First published version. ============================================================================== -Copyright: (C) 2009-2014 Ingo Karkat +Copyright: (C) 2009-2016 Ingo Karkat The VIM LICENSE applies to this plugin; see |copyright|. Maintainer: Ingo Karkat