tell application "TaskPaper"
    tell front document
        set p to containing project of selected entry
        set today_entry_ids to {}
        set current_index to 1
        set need_move to false
        set insert_index to -1
        repeat with each in entries of p
            if exists (tag named "today" of each) then
                if need_move then
                    set today_entry_ids to today_entry_ids & id of each
                end if
            else if not need_move then
                set insert_index to current_index
                set need_move to true
            end if
            set current_index to current_index + 1
        end repeat

        repeat with each in today_entry_ids
            move entry id each to before entry insert_index of p
            set insert_index to insert_index + 1
        end repeat
    end tell
end tell