Index: src/ephy-location-action.c
===================================================================
--- src/ephy-location-action.c	(revision 7992)
+++ src/ephy-location-action.c	(working copy)
@@ -91,65 +91,24 @@ static guint signals[LAST_SIGNAL];
 
 G_DEFINE_TYPE (EphyLocationAction, ephy_location_action, EPHY_TYPE_LINK_ACTION)
 
-static const struct
+typedef struct
 {
-	const char *prefix;
-	int len;
-}
-web_prefixes [] =
-{
-	{ "http://www.", 11 },
-	{ "http://ftp.", 11 },
-	{ "http://", 7 },
-	{ "https://www.", 12 },
-	{ "https://", 8 },
-	{ "ftp://", 6},
-	{ "ftp://ftp.", 10},
-	{ "www.", 4 },
-	{ "ftp.", 4}
-};
-
+	EphyLocationEntry *entry;
+	EphyLocationAction *action;
+} LocationEntryAction;
 
-static gboolean
-keyword_match (const char *list,
-	       const char *keyword)
+static void
+destroy_match_func (gpointer data)
 {
-	const char *p;
-	gsize keyword_len;
-
-	p = list;
-	keyword_len = strlen (keyword);
-
-	while (*p)
-	{
-		int i;
-
-		for (i = 0; i < keyword_len; i++)
-		{
-			if (p[i] != keyword[i])
-			{
-				goto next_token;
-			}
-		}
-	  
-		return TRUE;
-	  
-		next_token:
-
-		while (*p && !g_ascii_ispunct(*p) && !g_ascii_isspace(*p)) p++;
-		while (*p && (g_ascii_ispunct(*p) || g_ascii_isspace(*p))) p++;
-	}
-
-	return FALSE;
+	g_slice_free (LocationEntryAction, data);
 }
 
 static gboolean
-completion_func (GtkEntryCompletion *completion,
-		 const char *key,
-		 GtkTreeIter *iter,
-		 gpointer data)
+match_func (GtkEntryCompletion *completion,
+		const char *key,
+		GtkTreeIter *iter,
+		gpointer data)
 {
-	int i, len_key, len_prefix;
 	char *item = NULL;
 	char *url = NULL;
 	char *keywords = NULL;
@@ -157,8 +116,9 @@ completion_func (GtkEntryCompletion *com
 	GtkTreeModel *model;
 	GtkTreeIter iter2;
 	EphyLocationActionPrivate *priv;
-	
-	priv = EPHY_LOCATION_ACTION (data)->priv;
+	GRegex *regex;
+
+	priv = EPHY_LOCATION_ACTION (((LocationEntryAction *) data)->action)->priv;
 
 	model = gtk_entry_completion_get_model (completion);
 
@@ -167,40 +127,16 @@ completion_func (GtkEntryCompletion *com
 			    EPHY_COMPLETION_URL_COL, &url,
 			    EPHY_COMPLETION_KEYWORDS_COL, &keywords,
 			    -1);
-
-	len_key = strlen (key);
-	if (!strncasecmp (key, item, len_key))
-	{
-		ret = TRUE;
-	}
-	else if (keyword_match (keywords, key))
-	{
-		ret = TRUE;
-	}
-	else if (!strncasecmp (key, url, len_key))
-	{
-		ret = TRUE;
-	}
-	else
-	{
-		for (i = 0; i < G_N_ELEMENTS (web_prefixes); i++)
-		{
-			len_prefix = web_prefixes[i].len;
-			if (!strncmp (web_prefixes[i].prefix, item, len_prefix) &&
-			    !strncasecmp (key, item + len_prefix, len_key))
-			{
-				ret = TRUE;
-				break;
-			}
-			else if (!strncmp (web_prefixes[i].prefix, url, len_prefix) &&
-			        !strncasecmp (key, url + len_prefix, len_key))
-			{
-				ret = TRUE;
-				break;
-			}
-
-		}
-	}
+	
+	if (!key)
+		return FALSE;
+	
+	regex = ephy_location_entry_get_regex (((LocationEntryAction *) data)->entry);
+	
+	ret = (g_regex_match (regex, item, G_REGEX_MATCH_NOTEMPTY, NULL)
+		|| g_regex_match (regex, url, G_REGEX_MATCH_NOTEMPTY, NULL)
+		|| g_regex_match (regex, keywords, G_REGEX_MATCH_NOTEMPTY, NULL)
+		);
 	
 	gtk_tree_model_sort_convert_iter_to_child_iter 
 		(GTK_TREE_MODEL_SORT (model), &iter2, iter);
@@ -470,6 +406,7 @@ connect_proxy (GtkAction *action, GtkWid
 		EphyLocationEntry *lentry = EPHY_LOCATION_ENTRY (proxy);
 		EphyCompletionModel *model;
 		GtkWidget *entry;
+		LocationEntryAction *lea;
 
 		model = ephy_completion_model_new ();
 		ephy_location_entry_set_completion (EPHY_LOCATION_ENTRY (proxy),
@@ -481,10 +418,15 @@ connect_proxy (GtkAction *action, GtkWid
 						    EPHY_COMPLETION_EXTRA_COL,
 						    EPHY_COMPLETION_FAVICON_COL,
 						    EPHY_COMPLETION_URL_COL);
-
-		ephy_location_entry_set_completion_func (EPHY_LOCATION_ENTRY (proxy), 
-							completion_func, 
-							EPHY_LOCATION_ACTION (action));
+		
+		lea = g_slice_new (LocationEntryAction);
+		lea->entry = EPHY_LOCATION_ENTRY (proxy);
+		lea->action = EPHY_LOCATION_ACTION (action);
+		
+		ephy_location_entry_set_match_func (EPHY_LOCATION_ENTRY (proxy), 
+							match_func, 
+							lea,
+							destroy_match_func);
 
 		add_completion_actions (action, proxy);
 
Index: lib/widgets/ephy-location-entry.c
===================================================================
--- lib/widgets/ephy-location-entry.c	(revision 7992)
+++ lib/widgets/ephy-location-entry.c	(working copy)
@@ -71,6 +71,7 @@ struct _EphyLocationEntryPrivate
 	GdkColor secure_fg_colour;
 
 	GtkCellRenderer *extracell;
+	GRegex *regex;
 
 	char *before_completion;
 	char *saved_text;
@@ -114,6 +115,12 @@ static void extracell_data_func (GtkCell
 				GtkTreeIter *iter,
 				gpointer data);
 
+static void textcell_data_func (GtkCellLayout *cell_layout,
+			GtkCellRenderer *cell,
+			GtkTreeModel *tree_model,
+			GtkTreeIter *iter,
+			gpointer data);
+
 static GObjectClass *parent_class = NULL;
 
 enum signalsEnum
@@ -231,6 +238,12 @@ ephy_location_entry_finalize (GObject *o
 	{
 		g_object_unref (priv->favicon);
 	}
+	
+	if (priv->regex)
+	{
+		g_regex_unref (priv->regex);
+		priv->regex = NULL;
+	}
 
 	parent_class->finalize (object);
 }
@@ -345,9 +358,11 @@ editable_changed_cb (GtkEditable *editab
 		     EphyLocationEntry *entry)
 {
 	EphyLocationEntryPrivate *priv = entry->priv;
+	const char *text;
+	char *pattern;
 
 	update_address_state (entry);
-
+	
 	if (priv->block_update == TRUE) 
 		return;
 	else
@@ -355,6 +370,24 @@ editable_changed_cb (GtkEditable *editab
 		priv->user_changed = TRUE;
 		priv->can_redo = FALSE;
 	}	
+	
+	if (priv->regex)
+	{
+		g_regex_unref (priv->regex);
+		priv->regex = NULL;
+	}
+	
+	text = gtk_entry_get_text (GTK_ENTRY (editable));
+
+	if (g_str_has_prefix (text, "re:"))
+		pattern = g_strdup (text+3);
+	else
+		pattern = g_regex_escape_string (text, -1);
+	
+	priv->regex = g_regex_new (pattern, 
+				G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, NULL);
+	
+	g_free (pattern);
 
 	update_favicon (entry);
 
@@ -925,7 +958,8 @@ ephy_location_entry_init (EphyLocationEn
 	p->user_changed = FALSE;
 	p->block_update = FALSE;
 	p->saved_text = NULL;
-
+	p->regex = NULL;
+	
 	ephy_location_entry_construct_contents (le);
 
 	gtk_tool_item_set_expand (GTK_TOOL_ITEM (le), TRUE);
@@ -966,9 +1000,12 @@ cursor_on_match_cb  (GtkEntryCompletion 
 	gtk_tree_model_get (model, iter,
 			    le->priv->url_col,
 			    &item, -1);
-	
 	entry = gtk_entry_completion_get_entry (completion);
+
+	le->priv->block_update = TRUE;
 	gtk_entry_set_text (GTK_ENTRY (entry), item);
+	le->priv->block_update = FALSE;
+	
 	gtk_editable_set_position (GTK_EDITABLE (entry), -1);
 
 	g_free (item);
@@ -1002,16 +1039,45 @@ extracell_data_func (GtkCellLayout *cell
 	g_value_unset (&visible);
 }
 
+static void
+textcell_data_func (GtkCellLayout *cell_layout,
+			GtkCellRenderer *cell,
+			GtkTreeModel *tree_model,
+			GtkTreeIter *iter,
+			gpointer data)
+{
+	char *cdata;
+	char *cdata_escaped;
+	char *markup_final;
+	GValue markup = { 0, };
+	EphyLocationEntryPrivate *priv;
+	
+	priv = EPHY_LOCATION_ENTRY (data)->priv;
+	gtk_tree_model_get (tree_model, iter, priv->text_col, &cdata, -1);
+
+	g_value_init (&markup, G_TYPE_STRING);
+
+	/* This is because urls can break markup due to =, &, blah blah */
+	cdata_escaped = g_markup_escape_text (cdata, -1);
+	markup_final = g_regex_replace (priv->regex, cdata_escaped, -1, 0, "<b>\\0</b>", G_REGEX_MATCH_NOTEMPTY, NULL);
+	
+	g_value_take_string (&markup, markup_final);
+	g_object_set_property (G_OBJECT (cell), "markup", &markup);
+	g_value_unset (&markup);
+}
+
+
 void
-ephy_location_entry_set_completion_func (EphyLocationEntry *le, 
-					GtkEntryCompletionMatchFunc completion_func,
-					gpointer user_data)
+ephy_location_entry_set_match_func (EphyLocationEntry *le, 
+				GtkEntryCompletionMatchFunc match_func,
+				gpointer user_data,
+				GDestroyNotify notify)
 {
 	EphyLocationEntryPrivate *priv = le->priv;
 	GtkEntryCompletion *completion;
 	
 	completion = gtk_entry_get_completion (GTK_ENTRY (priv->icon_entry->entry));
-	gtk_entry_completion_set_match_func (completion, completion_func, user_data, NULL);
+	gtk_entry_completion_set_match_func (completion, match_func, user_data, notify);
 }
 
 void
@@ -1084,6 +1150,11 @@ ephy_location_entry_set_completion (Ephy
 					GUINT_TO_POINTER (extra_col),
 					NULL);
 
+	gtk_cell_layout_set_cell_data_func (GTK_CELL_LAYOUT (completion),
+					cell, textcell_data_func, 
+					le,
+					NULL);
+
 	g_object_set (completion, "inline-selection", TRUE, NULL);
 	g_signal_connect (completion, "cursor-on-match",
 			  G_CALLBACK (cursor_on_match_cb), le);
@@ -1327,3 +1398,11 @@ ephy_location_entry_set_lock_tooltip (Ep
 
 	gtk_widget_set_tooltip_text (priv->lock_ebox, tooltip);
 }
+
+GRegex *
+ephy_location_entry_get_regex (EphyLocationEntry *entry)
+{
+	EphyLocationEntryPrivate *priv = entry->priv;
+	
+	return priv->regex;
+}
Index: lib/widgets/ephy-location-entry.h
===================================================================
--- lib/widgets/ephy-location-entry.h	(revision 7992)
+++ lib/widgets/ephy-location-entry.h	(working copy)
@@ -81,9 +81,10 @@ void		ephy_location_entry_set_location	(
 							 const char *address,
 							 const char *typed_address);
 
-void		ephy_location_entry_set_completion_func (EphyLocationEntry *le, 
-							 GtkEntryCompletionMatchFunc completion_func,
-							 gpointer user_data);
+void		ephy_location_entry_set_match_func	(EphyLocationEntry *le, 
+							 GtkEntryCompletionMatchFunc match_func,
+							 gpointer user_data,
+							 GDestroyNotify notify);
 					
 const char     *ephy_location_entry_get_location	(EphyLocationEntry *le);
 
@@ -91,6 +92,8 @@ gboolean	ephy_location_entry_get_can_und
 
 gboolean	ephy_location_entry_get_can_redo	(EphyLocationEntry *entry);
 
+GRegex *	ephy_location_entry_get_regex		(EphyLocationEntry *entry);
+
 gboolean	ephy_location_entry_reset		(EphyLocationEntry *entry);
 
 void		ephy_location_entry_undo_reset		(EphyLocationEntry *entry);
