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

w3m-search-name-anchor return val when already there



In the current cvs, when going to an anchor on a page like

    (w3m-goto-url "http://emacs-w3m.namazu.org/#mailing_list")

and then immediately evalling that again, with point still at the
anchor, point moves to the start of the buffer.  I hoped it would stay
still, which is how it was in 1.4.4.

I guess w3m-goto-url goes to point-min if w3m-search-name-anchor returns
false.  That's when the anchor is not found, is it?  It seems
w3m-search-name-anchor also returns false if

    (= (point) cur-pos)

ie. the anchor is found and you're already at it.

I get the effect I hoped for with the change below (whole thing for
reading, then a diff).  Is this condition for recording in the history
what's intended?


2009-01-21  Kevin Ryde  <user42@xxxxxxxxxx>

	* w3m.el (w3m-search-name-anchor): Return true meaning "found" if
	point is already at the anchor position.


(defun w3m-search-name-anchor (name &optional quiet no-record)
  (interactive "sName: ")
  (let ((pos (point-min))
	(cur-pos (point))
	found)
    (catch 'found
      (while (setq pos (next-single-property-change pos 'w3m-name-anchor))
	(when (member name (get-text-property pos 'w3m-name-anchor))
	  (goto-char pos)
	  (when (eolp) (forward-line))
	  (w3m-horizontal-on-screen)
	  (throw 'found (setq found t))))
      (setq pos (point-min))
      (while (setq pos (next-single-property-change pos 'w3m-name-anchor2))
	(when (member name (get-text-property pos 'w3m-name-anchor2))
	  (goto-char pos)
	  (when (eolp) (forward-line))
	  (w3m-horizontal-on-screen)
	  (throw 'found (setq found t))))
      (unless quiet
	(message "No such anchor: %s" name)))

    (when (and found
	       (not no-record)
	       (/= (point) cur-pos))
	(setq w3m-name-anchor-from-hist
	      (append (list 1 nil (point) cur-pos)
		      (and (integerp (car w3m-name-anchor-from-hist))
			   (nthcdr (1+ (car w3m-name-anchor-from-hist))
				   w3m-name-anchor-from-hist)))))
    found))
--- w3m.el	22 Jan 2009 07:26:49 +1100	1.1410
+++ w3m.el	22 Jan 2009 07:27:06 +1100	
@@ -6132,32 +6132,34 @@
 (defun w3m-search-name-anchor (name &optional quiet no-record)
   (interactive "sName: ")
   (let ((pos (point-min))
-	(cur-pos (point)))
+	(cur-pos (point))
+	found)
     (catch 'found
       (while (setq pos (next-single-property-change pos 'w3m-name-anchor))
 	(when (member name (get-text-property pos 'w3m-name-anchor))
 	  (goto-char pos)
 	  (when (eolp) (forward-line))
 	  (w3m-horizontal-on-screen)
-	  (throw 'found t)))
+	  (throw 'found (setq found t))))
       (setq pos (point-min))
       (while (setq pos (next-single-property-change pos 'w3m-name-anchor2))
 	(when (member name (get-text-property pos 'w3m-name-anchor2))
 	  (goto-char pos)
 	  (when (eolp) (forward-line))
 	  (w3m-horizontal-on-screen)
-	  (throw 'found t)))
+	  (throw 'found (setq found t))))
       (unless quiet
 	(message "No such anchor: %s" name)))
-    (if (= (point) cur-pos)
-	nil
-      (unless no-record
+
+    (when (and found
+	       (not no-record)
+	       (/= (point) cur-pos))
 	(setq w3m-name-anchor-from-hist
 	      (append (list 1 nil (point) cur-pos)
 		      (and (integerp (car w3m-name-anchor-from-hist))
 			   (nthcdr (1+ (car w3m-name-anchor-from-hist))
 				   w3m-name-anchor-from-hist)))))
-      t)))
+    found))
 
 
 (defun w3m-parent-page-available-p ()