Skip to content
This repository was archived by the owner on Mar 14, 2025. It is now read-only.

Commit 25195d2

Browse files
committed
Add ability to go back after following links
Mapped `<BS>` to go back to previous document after following a link, works like a stack for following deeply nested links and coming back up to the parents with each `<BS>`.
1 parent ecb4216 commit 25195d2

File tree

5 files changed

+39
-2
lines changed

5 files changed

+39
-2
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# VIM Do Too v0.13.2 [![CircleCI](https://circleci.com/gh/dhruvasagar/vim-dotoo.svg?style=svg)](https://circleci.com/gh/dhruvasagar/vim-dotoo)
1+
# VIM Do Too v0.13.3 [![CircleCI](https://circleci.com/gh/dhruvasagar/vim-dotoo.svg?style=svg)](https://circleci.com/gh/dhruvasagar/vim-dotoo)
22
An awesome task manager & clocker inspired by org-mode written in pure viml.
33

44
## Pre-requisites
@@ -24,6 +24,7 @@ accurate agenda information and also for faster updates to these files.
2424
* <kbd>\<C-C\>\<C-C\></kbd>: Normalize a date (fixes day name if incorrect)
2525
* <kbd>\<Tab></kbd>: Cycle headline visibility similar to Org mode
2626
* <kbd>\<CR></kbd>: Follow link under cursor
27+
* <kbd>\<BS></kbd>: Go back to previous document after following a link
2728

2829
The <kbd>\<C-X\></kbd>, <kbd>\<C-A\></kbd>, and <kbd>cic</kbd> commands all work with <kbd>.</kbd>
2930
if you have [repeat.vim](http://github.com/tpope/vim-repeat) installed

autoload/dotoo/link.vim

+29
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,29 @@ function! s:parse_links()
1212
return result
1313
endfunction
1414

15+
let s:link_stack = []
16+
function! s:add_to_link_stack(bufnr)
17+
let winid = winnr()
18+
let item = {'bufnr': a:bufnr, 'from': extend([bufnr()], getcurpos())}
19+
call add(s:link_stack, item)
20+
endfunction
21+
22+
function! s:pop_from_link_stack()
23+
if empty(s:link_stack) | return | endif
24+
25+
let last_entry = remove(s:link_stack, -1)
26+
let bfnr = last_entry.from[0]
27+
if bufnr() != bfnr
28+
exec 'buffer' bfnr
29+
endif
30+
call setpos('.', last_entry.from[1:])
31+
endfunction
32+
1533
function! s:goto_headline(headline)
1634
if empty(a:headline)
1735
return 0
1836
endif
37+
call s:add_to_link_stack(bufnr(a:headline.file))
1938
call dotoo#agenda#goto_headline('edit', a:headline)
2039
return 1
2140
endfunction
@@ -60,9 +79,11 @@ function! s:goto_file(link)
6079

6180
if filereadable(file)
6281
let found = 1
82+
call bufload(file) " ensure buffer is loaded
6383
endif
6484

6585
if found ==# 1
86+
call s:add_to_link_stack(bufnr(file))
6687
exe 'edit' file
6788
return 1
6889
endif
@@ -111,3 +132,11 @@ function! dotoo#link#follow(cmd) abort
111132
endif
112133
endfor
113134
endfunction
135+
136+
function! dotoo#link#stack() abort
137+
return string(s:link_stack)
138+
endfunction
139+
140+
function! dotoo#link#back() abort
141+
call s:pop_from_link_stack()
142+
endfunction

doc/dotoo.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
-------------------------------------------------------------------------------
33

44
DoToo, the awesome TODO management system inspired by Org-Mode.
5-
Version 0.13.2
5+
Version 0.13.3
66

77
Author: Dhruva Sagar (http://dhruvasagar.com)
88
License: MIT (http://opensource.org/licenses/MIT)
@@ -44,6 +44,7 @@ GETTING STARTED *dotoo-getting-started
4444
`<C-C><C-C>`: Normalize a date (fixes day name if incorrect)
4545
`<Tab>`: Cycle headline visibility similar to Org mode
4646
`<CR>`: Follow link under cursor
47+
`<BS>`: Go back to previous document after following a link
4748

4849
They `<C-X>`, `<C-A>` and `cic` commands are repeatable using |.|
4950

ftplugin/dotoo.vim

+3
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ if !g:dotoo_disable_mappings
9191
if !hasmapto('<Plug>(dotoo-link-follow)')
9292
nmap <buffer> <CR> <Plug>(dotoo-link-follow)
9393
endif
94+
if !hasmapto('<Plug>(dotoo-link-back)')
95+
nmap <buffer> <BS> <Plug>(dotoo-link-back)
96+
endif
9497
if !hasmapto('<Plug>(dotoo-date-normalize)')
9598
nmap <buffer> <C-C><C-C> <Plug>(dotoo-date-normalize)
9699
endif

plugin/dotoo.vim

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ nnoremap <silent> <Plug>(dotoo-capture)
5050
nnoremap <silent> <Plug>(dotoo-link-follow)
5151
\ :<C-U>call dotoo#link#follow('edit')<CR>
5252
53+
nnoremap <silent> <Plug>(dotoo-link-back)
54+
\ :<C-U>call dotoo#link#back()<CR>
55+
5356
nnoremap <silent> <Plug>(dotoo-date-increment)
5457
\ :<C-U>call dotoo#date#increment(v:count1)<CR>
5558
nnoremap <silent> <Plug>(dotoo-date-decrement)

0 commit comments

Comments
 (0)