Whole document tree
    

Whole document tree

Links-Lua bookmark system

The Links-Lua bookmark system

What you need to get

Installing

1. First Links-Lua must be installed.

2. Copy bm.lua into your ~/.links/ directory.

3. Now we have to edit some things in the ~/.links/hooks.lua file. I will assume you have followed the pwhooks.lua example file for your own configuration. Also, systems functions must be enabled.

Somewhere in the file, we have to load the bm.lua file. So add this line:

 
	dofile (home_dir .. "/.links/bm.lua")
	 

Now you may set some options. Set any of the following you want. The defaults settings are shown.

 
	-- Default location to save and load bookmarks from.
	bm_bookmark_file = home_dir.."/.links/bookmark.lst"

	-- Set to non-`nil' to see URLs in the generated page.
	bm_display_urls = nil

	-- Set to non-`nil' to show links to category headers.
	-- Only useful while sorting categories, otherwise just annoying.
	bm_display_category_links = 1

	-- Set to non-`nil' to automatically sort bookmarks alphabetically.
	-- Do not set this if you care about the sorting of your bookmarks!
	bm_auto_sort_bookmarks = nil
	 

We also have to bind some keystrokes. These are my own keybindings, feel free to change them:

 
	bind_key ('main', 'a', bm_add_bookmark)
	bind_key ('main', 's', bm_view_bookmarks)
	bind_key ('main', 'Alt-e', bm_edit_bookmark)
	bind_key ('main', 'Alt-d', bm_delete_bookmark)
	bind_key ('main', 'Alt-k', bm_move_bookmark_up)
	bind_key ('main', 'Alt-j', bm_move_bookmark_down)
	 

When we start up, we would like to load our list of bookmarks from disk. So we need this line:

 
	-- Be careful not to load bookmarks if this script is being
	-- reloaded while in Links, or we will lose unsaved changes.
	if not bm_bookmarks or getn (bm_bookmarks) == 0 then
	    bm_load_bookmarks ()
	end
	 

For reasons too complicated to explain here, add this function too:

 
	function follow_url_hook (url)
	    if bm_is_category (url)
	    then return nil
	    else return bm_get_bookmark_url (url) or url
	    end
	end
	 

Finally, when we quit Links, we would like our list of bookmarks saved to disk. Find your quit_hook function, and put in bm_save_bookmarks somewhere. For example, mine looks like:

 
	function quit_hook ()
	    bm_save_bookmarks ()
	    if tmp_files and remove then
	        tmp_files.n = nil
	        for i,v in tmp_files do remove (v) end
	    end
	end
	 

If you have done all that but can't get it to work, please see the pwhooks.lua example file.

Using

Adding a bookmark is simple. Press the key you have assigned, and you will be presented with a dialog box with three fields. The first one is the category to put the bookmark in, the second is the name of the bookmark, the third is the URL.

Please don't tell me that the "Category" field being mislabelled. I know about it :-)

Category auto-completion will come later. I do not know how much later.

Viewing the bookmark list is simple. Press the key you have assigned, and Links will go to a generated web page with all your bookmarks in it. Browse, search, follow links as usual.

Deleting a bookmark is simple. While a bookmark is highlighted, press the key you have assigned it, and the bookmark will be deleted (no confirmation!). Warning: you can also delete entire categories at once, by highlighting the category.

Sorting a bookmark list is painful. While a bookmark is highlighted, press the key you have assigned for moving the bookmark up or down, and it will be moved up and down the list bookmarks in that category. You may also sort categories.

The painful bit is because your cursor will be jumped to the top of the page every time you do this.

If you have automatic sorting turned on, these keys will do nothing.

Editing a bookmark is simple. While a bookmark is highlighted, press the key you have assigned to it, and a dialog box (just like the one you saw when adding bookmarks) will pop up. You may again edit the Category, Name and URL fields. Editing the category is how you move bookmarks around.

Warnings

This code is very fragile. Do not edit/delete/sort bookmarks in different Links windows at the same time. Most likely you will lose bookmarks, and get pissed off at me.

Before you start editing bookmarks, make sure you are using an up to date copy of the generated bookmark web page. You can do this by simply pressing the key assigned to View bookmarks. Editing bookmarks from old copies of bookmarks pages (that reside in Links' cache, for example) is a sure way to have a bad day.

If you make a mistake, and want to revert to the bookmarks you have saved on disk, run `bm_load_bookmarks()' from the Lua Console.

It's probably a good idea to back up your bookmarks. This code hasn't got much testing yet...

And finally,

Enjoy.

$Id: bookmark.html,v 1.8 2001/10/28 21:47:07 tjaden Exp $