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

[PATCH] w3m-filter: correct return value, remove extra code



I noticed `w3m-filter-delete-regions' wasn't always returning a
correct return value. The attached patch should fix that. While I was
at it, it seemed that `w3m-filter-replace-regexp' had some unnecessary
code.

For your review and approval,

--
hkp://keys.gnupg.net
CA45 09B5 5351 7C11 A9D1  7286 0036 9E45 1595 8BC0
--- w3m-filter.el_orig	2017-06-02 16:56:29.000000000 -0400
+++ w3m-filter.el	2017-06-11 15:03:57.498056561 -0400
@@ -356,7 +356,8 @@
 START-POS is a position from which to begin deletions.
 END-POS is a position at which to stop deletions.
 COUNT is the maximum number of deletions to make."
-  `(let (p ,@(if count '((i 0))))
+; BORUCH's NOTE: return t if deleted at least one region
+  `(let (p (i 0))
      (goto-char ,(or start-pos '(point-min)))
      (while (and ,@(if count `((< i ,count)))
 		 ,(if use-regex
@@ -371,25 +372,22 @@
        (delete-region p ,(if without-end
 			     '(match-beginning 0)
 			   '(match-end 0)))
-       ,@(if count '((setq i (1+ i)))))))
+       (setq i (1+ i)))
+     (> i 0)))
 
 (defmacro w3m-filter-replace-regexp (url regexp to-string
 					 &optional start-pos end-pos count)
   "Replace all occurrences of REGEXP with TO-STRING.
 Optional START-POS, END-POS, and COUNT limit the scope of
 the replacements."
-  (if count
-      `(let ((i 0))
+; BORUCH's NOTE: removed unneccessary clause
+  `(let ((i 0))
 	 (goto-char ,(or start-pos '(point-min)))
-	 (while (and (< i ,count)
+     (while (and ,@(if count `((< i ,count)))
 		     (re-search-forward ,regexp ,end-pos t))
 	   (replace-match ,to-string nil nil)
 	   (setq i (1+ i)))
-	 (> i 0))
-    `(progn
-       (goto-char ,(or start-pos '(point-min)))
-       (while (re-search-forward ,regexp ,end-pos t)
-	 (replace-match ,to-string nil nil)))))
+	 (> i 0)))
 
 ;; Filter functions:
 (defun w3m-filter-google-click-tracking (url)