Index: src/ephy-location-action.c
===================================================================
--- src/ephy-location-action.c	(revision 7972)
+++ src/ephy-location-action.c	(working copy)
@@ -91,65 +91,12 @@ static guint signals[LAST_SIGNAL];
 
 G_DEFINE_TYPE (EphyLocationAction, ephy_location_action, EPHY_TYPE_LINK_ACTION)
 
-static const 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}
-};
-
-
-static gboolean
-keyword_match (const char *list,
-	       const char *keyword)
-{
-	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;
-}
-
 static gboolean
 completion_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,6 +104,7 @@ completion_func (GtkEntryCompletion *com
 	GtkTreeModel *model;
 	GtkTreeIter iter2;
 	EphyLocationActionPrivate *priv;
+	GRegex *regex;
 	
 	priv = EPHY_LOCATION_ACTION (data)->priv;
 
@@ -167,40 +115,18 @@ completion_func (GtkEntryCompletion *com
 			    EPHY_COMPLETION_URL_COL, &url,
 			    EPHY_COMPLETION_KEYWORDS_COL, &keywords,
 			    -1);
+	
+	if (!key)
+		return FALSE;
+	
+	regex = g_regex_new (key, G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, NULL);
+	
+	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)
+		);
 
-	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;
-			}
-
-		}
-	}
+	g_regex_unref (regex);
 	
 	gtk_tree_model_sort_convert_iter_to_child_iter 
 		(GTK_TREE_MODEL_SORT (model), &iter2, iter);
@@ -213,10 +139,6 @@ completion_func (GtkEntryCompletion *com
 	    (iter2.user_data2 == priv->history))
 		ret = FALSE;
 
-	g_free (item);
-	g_free (url);
-	g_free (keywords);
-
 	return ret;
 }
 
Index: lib/widgets/ephy-location-entry.c
===================================================================
--- lib/widgets/ephy-location-entry.c	(revision 7972)
+++ 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,9 @@ ephy_location_entry_finalize (GObject *o
 	{
 		g_object_unref (priv->favicon);
 	}
+	
+	if (priv->regex)
+		g_regex_unref (priv->regex);
 
 	parent_class->finalize (object);
 }
@@ -347,6 +357,11 @@ editable_changed_cb (GtkEditable *editab
 	EphyLocationEntryPrivate *priv = entry->priv;
 
 	update_address_state (entry);
+	
+	if (priv->regex)
+		g_regex_unref (priv->regex);
+	priv->regex = g_regex_new (gtk_entry_get_text (GTK_ENTRY (editable)), 
+				G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, NULL);
 
 	if (priv->block_update == TRUE) 
 		return;
@@ -925,7 +940,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,7 +982,6 @@ cursor_on_match_cb  (GtkEntryCompletion 
 	gtk_tree_model_get (model, iter,
 			    le->priv->url_col,
 			    &item, -1);
-	
 	entry = gtk_entry_completion_get_entry (completion);
 	gtk_entry_set_text (GTK_ENTRY (entry), item);
 	gtk_editable_set_position (GTK_EDITABLE (entry), -1);
@@ -1002,6 +1017,35 @@ 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;
+	GRegex *regex;
+	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,
@@ -1084,6 +1128,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);
