[Date Prev][Date Next][Thread Prev][][Date Index][Thread Index]

w3m-filter.el: misc fix and contributions



Dear emacs-w3m developers,

it seems, there is a very arguable feature in `w3m-filter':
matching URI pattern only once.  In proposed patch I've
changed function to make it iterate through all cases, which,
obviously, is more suitable.

I've also added a new general filtring function,
`w3m-filter-replace-regexp' and added option to customize
separator used in `w3m-filter-google'.

Index: w3m-filter.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-filter.el,v
retrieving revision 1.25
diff -u -r1.25 w3m-filter.el
--- w3m-filter.el	5 Jun 2007 03:36:14 -0000	1.25
+++ w3m-filter.el	21 Aug 2007 21:03:06 -0000
@@ -83,6 +83,11 @@
   :group 'w3m
   :type 'boolean)
 
+(defcustom w3m-filter-google-separator "<hr>"
+  "Field separator for Google's search results ."
+  :group 'w3m
+  :type 'string)
+
 (defcustom w3m-filter-amazon-regxp (concat
 				    "\\`\\(https?://\\(?:www\\.\\)?amazon\\."
 				    "\\(?:com\\|co\\.\\(?:jp\\|uk\\)\\|fr\\|de\\)"
@@ -109,11 +114,9 @@
 (defun w3m-filter (url)
   "Apply filtering rule of URL against a content in this buffer."
   (save-match-data
-    (catch 'apply-filtering-rule
-      (dolist (elem w3m-filter-rules)
-	(when (string-match (car elem) url)
-	  (throw 'apply-filtering-rule
-		 (apply (cadr elem) url (cddr elem))))))))
+	(dolist (elem w3m-filter-rules)
+	  (when (string-match (car elem) url)
+		(apply (cadr elem) url (cddr elem))))))
 
 (defun w3m-filter-delete-regions (url start end)
   "Delete regions surrounded with a START pattern and an END pattern."
@@ -126,6 +129,12 @@
       (incf i))
     (> i 0)))
 
+(defun w3m-filter-replace-regexp (url regexp to-string)
+  "Replace all occurrences of REGEXP with TO-STRING."
+  (goto-char (point-min))
+  (while (re-search-forward regexp nil t)
+	(replace-match to-string nil nil)))
+
 ;; Filter functions:
 (defun w3m-filter-asahi-shimbun (url)
   "Convert entity reference of UCS."
@@ -166,10 +175,10 @@
       (when (and w3m-filter-google-use-ruled-line
 		 (search-backward "<div class=" end t)
 		 (search-forward "</div>" nil t))
-	(insert "<hr>"))
+	(insert w3m-filter-google-separator))
       (if w3m-filter-google-use-ruled-line
 	  (while (search-backward "<div class=" end t)
-	    (insert "<hr>"))
+	    (insert w3m-filter-google-separator))
 	(while (search-backward "<div class=" end t)
 	  (insert "<p>"))))))