Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jumplist: browser-style (or 'tagstack') navigation #11530

Merged
merged 1 commit into from
Dec 10, 2019

Conversation

butwerenotthereyet
Copy link
Contributor

@butwerenotthereyet butwerenotthereyet commented Dec 7, 2019

Traditionally, when navigating to a specific location from the middle of the jumplist results in shifting the current location to the bottom of the list and adding the new location after it. This behavior is not desireable to all users--see, for example https://vi.stackexchange.com/questions/18344/how-to-change-jumplist-behavior.

Here, another jumplist behavior is introduced. When g:jumplistmode is set to "history", the jumplist behaves like history of a web browser. When navigating to a location from the middle of the jumplist

2 first
1 second
0 third <-- current location
1 fourth
2 fifth

to a location that is different from the location that is currently next in the jumplist

new != fourth

the locations after the current location in the jump list are discarded

2 first
1 second
0 third

The result is that when moving forward from that location, the new location will be appended to the jumplist:

3 first
2 second
1 third
0 new

If the new location is the same

new == second

as some previous (but not immediately prior) entry in the jumplist,

2 first
1 second
0 third <-- current location
1 fourth
2 fifth

both occurrences preserved

3 first
2 second
1 third
0 second (new)

when moving forward from that location.

It would be desireable to go farther and, when the new location is the same as the location that is currently next in the jumplist,

new == fourth

make the result of navigating to the new location by navigating directly (e.g. 50gg) be the same as moving forward in the jumplist

2 first
1 second
0 third
1 new <-- current location
2 fifth

and simply increment the jumplist index. That change is NOT part of this patch because it would require passing the new cursor location to the function (setpcmark) from all of its callees. That in turn would require those callees to know before calling what the new cursor location is, which they do not currently.

@butwerenotthereyet butwerenotthereyet changed the title jumplist: enable browser-history-style navigation [RFC] jumplist: enable browser-history-style navigation Dec 7, 2019
@marvim marvim added the RFC label Dec 7, 2019
@justinmk justinmk added core Nvim core functionality or code enhancement feature request labels Dec 8, 2019
@justinmk
Copy link
Member

justinmk commented Dec 8, 2019

Looks good except:

  • instead of g:foo variable, introduce a new jumpoptions option, which takes a list of strings. See 'wildoptions' for example.
  • src/nvim/testdir/test_jumplist.vim is a Vim old test. Do not add new tests there, it makes merging upstream patches more difficult. Add new tests to test/functional.... See test/functional/example_spec.lua for an example.
    • You can run the test like this:
      TEST_FILE=test/functional/example_spec.lua make functionaltest
      

@justinmk justinmk added the needs:response waiting for reply from the author label Dec 8, 2019
@butwerenotthereyet
Copy link
Contributor Author

butwerenotthereyet commented Dec 8, 2019

@justinmk Thank you!

There's now jumpoptions and this behavior occurs when jumpoptions includes history rather than when g:jumplistmode equals history: a0740dc . The tests are now in functionaltest/ui: e5505c8.

Is the next step to document on jumpoptions?

src/nvim/mark.c Outdated Show resolved Hide resolved
src/nvim/option_defs.h Outdated Show resolved Hide resolved
src/nvim/mark.c Outdated Show resolved Hide resolved
@justinmk
Copy link
Member

justinmk commented Dec 8, 2019

Is the next step to document on jumpoptions?

yes.

Also, calling this "history" is pretty misleading since that could describe the old behavior as well. Perhaps "stack" is a better term? Browser-like behavior pops items off the stack, whereas Vim-like behavior is always additive. In fact, this essentially makes ctrl-o/ctrl-i behave like the 'tagstack', which (as mentioned in https://vi.stackexchange.com/q/18344/578 ) is what ctrl-t already does.

@justinmk justinmk added this to the 0.5 milestone Dec 8, 2019
@butwerenotthereyet
Copy link
Contributor Author

butwerenotthereyet commented Dec 9, 2019

calling this "history" is pretty misleading since that could describe the old behavior as well. Perhaps "stack" is a better term? Browser-like behavior pops items off the stack, whereas Vim-like behavior is always additive.

Agreed, "stack" fits much better with existing Vim terminology. The option is now ( 3aca2ea ) stack.

In fact, this essentially makes ctrl-o/ctrl-i behave like the 'tagstack', which (as mentioned in https://vi.stackexchange.com/q/18344/578 ) is what ctrl-t already does.

The first-pass on the documentation now mentions that adding stack to jumpoptions makes the jumplist behave like the tagstack.

@butwerenotthereyet butwerenotthereyet force-pushed the jumplist-history branch 2 times, most recently from 1c912dd to 0aacabc Compare December 9, 2019 02:56
src/nvim/mark.c Outdated
@@ -1204,16 +1214,27 @@ void cleanup_jumplist(win_T *wp, bool checktail)
break;
}
}
if (i >= wp->w_jumplistlen) { // no duplicate
bool mustfree = false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a "dead assignment", static analysis will flag it.

Suggested change
bool mustfree = false;
bool mustfree;

I would probably lean towards a ternary or some other way to be less verbose in the logic below, but I suppose that could turn out worse.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the dead store in 7f29497 . The less verbose versions I've been able to come up with so far have been less readable (highly subjective), but if there's a better way to write this let's do it.

runtime/doc/motion.txt Outdated Show resolved Hide resolved
src/nvim/option.c Outdated Show resolved Hide resolved
@butwerenotthereyet butwerenotthereyet force-pushed the jumplist-history branch 2 times, most recently from ab58f93 to 452656d Compare December 9, 2019 03:38
Copy link
Member

@justinmk justinmk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Nice attention to detail--thanks for taking care about formatting the tests and other details :)

todo: mention this in vim_diff.txt

@justinmk justinmk removed the needs:response waiting for reply from the author label Dec 9, 2019
@justinmk justinmk changed the title [RFC] jumplist: enable browser-history-style navigation jumplist: browser-style (or 'tagstack') navigation Dec 9, 2019
Traditionally, when navigating to a specific location from the middle of
the jumplist results in shifting the current location to the bottom of
the list and adding the new location after it.  This behavior is not
desireable to all users--see, for example
https://vi.stackexchange.com/questions/18344/how-to-change-jumplist-behavior.

Here, another jumplist behavior is introduced.  When jumpoptions (a new
option set added here) includes stack, the jumplist behaves like the
tagstack or like history in a web browser.  That is, when navigating to
a location from the middle of the jumplist

    2 first
    1 second
    0 third <-- current location
    1 fourth
    2 fifth

to a new location the locations after the current location in the jump
list are discarded

    2 first
    1 second
    0 third
            <-- current location

The result is that when moving forward from that location, the new
location will be appended to the jumplist:

    3 first
    2 second
    1 third
    0 new

If the new location is the same

  new == second

as some previous (but not immediately prior) entry in the jumplist,

    2 first
    1 second
    0 third <-- current location
    1 fourth
    2 fifth

both occurrences preserved

    3 first
    2 second
    1 third
    0 second (new)

when moving forward from that location.

It would be desireable to go farther and, when the new location is the
same as the location that is currently next in the jumplist,

    new == fourth

make the result of navigating to the new location by jumping (e.g. 50gg)
be the same as moving forward in the jumplist

    2 first
    1 second
    0 third
    1 new <-- current location
    2 fifth

and simply increment the jumplist index.  That change is NOT part of
this patch because it would require passing the new cursor location to
the function (setpcmark) from all of its callees.  That in turn would
require those callees to know *before* calling what the new cursor
location is, which do they do not currently.
@butwerenotthereyet
Copy link
Contributor Author

@justinmk Thank you for all the guidance.

mention this in vim_diff.txt

There's now a mention of jumpoptions and jumplist-stack in vimdiff in the Changed Feature section under "motion". Is that what you had in mind?

@butwerenotthereyet butwerenotthereyet changed the title jumplist: browser-style (or 'tagstack') navigation [RDY] jumplist: browser-style (or 'tagstack') navigation Dec 9, 2019
@butwerenotthereyet

This comment has been minimized.

@marvim marvim added RDY and removed RFC labels Dec 9, 2019
@justinmk justinmk merged commit 39094b3 into neovim:master Dec 10, 2019
@justinmk justinmk changed the title [RDY] jumplist: browser-style (or 'tagstack') navigation jumplist: browser-style (or 'tagstack') navigation Dec 10, 2019
@MaskRay
Copy link

MaskRay commented Jan 19, 2020

Is the following the traditional behavior?

first
second
fourth
fifth
third  # shifting the current location to the bottom of the list 
new    # and adding the new location after it

@epheien
Copy link

epheien commented Jan 20, 2020

Is the following the traditional behavior?

first
second
fourth
fifth
third  # shifting the current location to the bottom of the list 
new    # and adding the new location after it

Almost like this

@muniter muniter mentioned this pull request Oct 31, 2021
chrisbra pushed a commit to vim/vim that referenced this pull request Sep 20, 2023
Problem:  not possible to use the jumplist like a stack
Solution: Add the 'jumpoptions' setting to make the jumplist
          a stack.

Add an option for using jumplist like tag stack

related: #7738
closes: #13134

ported from NeoVim:

- https://neovim.io/doc/user/motion.html#jumplist-stack
- neovim/neovim@39094b3
- neovim/neovim#11530
- https://vi.stackexchange.com/questions/18344/how-to-change-jumplist-behavior

Based on the feedback in the previous PR, it looks like many people like
this option.

Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Co-authored-by: butwerenotthereyet <58348703+butwerenotthereyet@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Nvim core functionality or code enhancement feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants