# -*- shell-script -*-

################################################################################

§class "bookmark" --properties "name" --with-interface

§function.clone "§bookmark.new" "§bookmark._new"
§function.clone "§bookmarks.dump" "§bookmarks._dump"

################################################################################

function §bookmark.new {

    §bookmark._new "$1"
    
    eval "function $1 { 
        +action-browse
    }"
}

function §bookmarks.dump {
    
    local file="$(§objects.data_home)/${1:-bookmarks.dump}"
    local remote_bookmarks="$bashrun_cache_home/remote-bookmarks.bash"
    local name=""

    [[ -f "$remote_bookmarks" ]] && /bin/rm "$remote_bookmarks"

    §bookmarks._dump "$1"

    §bookmarks.seek_start
    while §bookmarks.next?; do
	name="$(§bookmark.get_name)"

	# dump the bookmark function
	§function.code "$name" >> "$file"
	
	# create the remote interface bookmark function
	§quote name
	printf '%s\n' "function $name { bashrun2 do browse $name; }" \
	    >> "$remote_bookmarks"
    
	§bookmarks.next
    done
}
