commit 5be0afd2b1b614f9f8329182a1fe28e1d68d2e14
parent ee354f5c540c9c374d72cb0eca85463982bd2ca0
Author: René Wagner <rwa@clttr.info>
Date: Thu, 31 Aug 2023 18:37:22 +0200
extend bookmark managing
Adding a bookmark for the url under the cursor is now available per
command "GemivimAddCursorBookmark".
Additionally removing of bookmarks is exposed via the newly introduced
"GemivimRemoveBookmark" and "GemivimRemoveCursorBookmark" commands.
Diffstat:
3 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
@@ -46,7 +46,10 @@ Gemivim provides several commands for processing gemini links and bookmarks, con
- GemivimOpen - invokes prompt for input gemini url
- GemivimGX - open link under the cursor
- GemivimOpenBookmarks - open bookmarks file
-- GemivimAddBookmark - add current link into bookmarks
+- GemivimAddBookmark - add current url into bookmarks
+- GemivimAddCursorBookmark - add url under cursor into bookmarks
+- GemivimRemoveBookmark - remove current url from bookmarks
+- GemivimRemoveCursorBookmark - remove url under cursor from bookmarks
- GemivimRefresh - get and reopen link in current buffer
### Bookmarks:
diff --git a/autoload/gemivim.vim b/autoload/gemivim.vim
@@ -180,6 +180,21 @@ function! s:add_url_to_bookmarks(url)
endif
endfunction
+function! s:remove_url_from_bookmarks(url)
+ if a:url =~? 'gemini://.*'
+ for link in readfile(g:gemini_bookmarks_file)
+ if link =~? '=> ' . a:url . '$' || link =~? '=> ' . a:url . '\_s.*'
+ continue
+ endif
+ call writefile([ link ], g:gemini_bookmarks_file. '.temp', 'a')
+ endfor
+ call system('mv '. g:gemini_bookmarks_file.'.temp '. g:gemini_bookmarks_file)
+ call s:info_msg('Removed bookmark: ' . a:url)
+ else
+ call s:error_msg('Not a gemini url: ' . a:url)
+ endif
+endfunction
+
function! gemivim#OpenBookmarks()
execute 'edit ' . g:gemini_bookmarks_file
endfunction
@@ -189,9 +204,17 @@ function! gemivim#CurrentUrlToBookmarks()
endfunction!
function! gemivim#CursorUrlToBookmarks()
- call s:add_url_to_bookmarks(expand('<cfile>'))
+ call s:add_url_to_bookmarks(expand('<cWORD>'))
endfunction
+function! gemivim#CursorUrlDelBookmark()
+ call s:remove_url_from_bookmarks(expand('<cWORD>'))
+endfunction!
+
+function! gemivim#CurrentUrlDelBookmark()
+ call s:remove_url_from_bookmarks(s:current_url())
+endfunction!
+
function! gemivim#Refresh()
call gemivim#Get(s:current_url())
endfunction
diff --git a/plugin/gemivim.vim b/plugin/gemivim.vim
@@ -3,4 +3,7 @@ command! -nargs=0 GemivimOpen :call gemivim#Open()
command! -nargs=0 GemivimGX :call gemivim#GX()
command! -nargs=0 GemivimOpenBookmarks :call gemivim#OpenBookmarks()
command! -nargs=0 GemivimAddBookmark :call gemivim#CurrentUrlToBookmarks()
+command! -nargs=0 GemivimAddCursorBookmark :call gemivim#CursorUrlToBookmarks()
+command! -nargs=0 GemivimRemoveBookmark :call gemivim#CurrentUrlDelBookmark()
+command! -nargs=0 GemivimRemoveCursorBookmark :call gemivim#CursorUrlDelBookmark()
command! -nargs=0 GemivimRefresh :call gemivim#Refresh()