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

Re: href "title" attribute



From: Kevin Ryde <user42@xxxxxxxxxx> said
Subject: [emacs-w3m:11477] href "title" attribute
Message-ID: <87d3oesu2d.fsf@xxxxxxxxx>
Date: Mon, 03 Jan 2011 11:35:22 +1100

> At pages like
> 
>     http://oeis.org/A000007
> 
> the cross-reference links like te A001906 in the comments section have a
> "title" attribute describing what's at the target,
> 
>     <a href="/A001906"
>        title="F(2n) = bisection of Fibonacci sequence: a(n)=3a(n-1)-a(n-2)."
>     >A001906</a>
> 
> Mozilla shows that in the tooltip when hovering the mouse over the link.
> Can emacs-w3m do something similar?

Please try this patch.
Emacs-w3m will show such title as following two way;

1) tooltip
2) minibuffer message

If other developers confirm this patch, I will commit the CVS.

-- 
Hideyuki SHIRAI (mailto:shirai@xxxxxxxxxxx)
Index: w3m-util.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m-util.el,v
retrieving revision 1.143
diff -u -r1.143 w3m-util.el
--- w3m-util.el	27 Dec 2010 00:50:15 -0000	1.143
+++ w3m-util.el	3 Jan 2011 07:26:22 -0000
@@ -226,6 +226,15 @@
       `(get-text-property ,position 'w3m-image-alt)
     `(w3m-get-text-property-around 'w3m-image-alt)))
 
+(defmacro w3m-anchor-title (&optional position)
+  "Return the value of the `w3m-anchor-title' property at the given POSITION.
+NOTE: If POSITION is omitted, it searches for the property in one
+character before and behind the current position, and point will move
+to the position where the property exists."
+  (if position
+      `(get-text-property ,position 'w3m-anchor-title)
+    `(w3m-get-text-property-around 'w3m-anchor-title)))
+
 (defmacro w3m-submit (&optional position)
   "Return the value of the `w3m-submit' property at the given POSITION.
 NOTE: If POSITION is omitted, it searches for the property in one
Index: w3m.el
===================================================================
RCS file: /storage/cvsroot/emacs-w3m/w3m.el,v
retrieving revision 1.1510
diff -u -r1.1510 w3m.el
--- w3m.el	28 Dec 2010 02:36:08 -0000	1.1510
+++ w3m.el	3 Jan 2011 07:26:22 -0000
@@ -3553,7 +3553,7 @@
   "Fontify anchor tags in the buffer which contains halfdump."
   (let ((help (w3m-make-help-echo w3m-balloon-help))
 	(balloon (w3m-make-balloon-help w3m-balloon-help))
-	prenames start end)
+	prenames start end rhref)
     (goto-char (point-min))
     (setq w3m-max-anchor-sequence 0)	;; reset max-hseq
     (while (re-search-forward "<_id[ \t\r\f\n]+" nil t)
@@ -3572,7 +3572,7 @@
     (while (re-search-forward "<a[ \t\r\f\n]+" nil t)
       (setq start (match-beginning 0))
       (setq prenames (get-text-property start 'w3m-name-anchor2))
-      (w3m-parse-attributes (href name id charset
+      (w3m-parse-attributes (href name id charset title
 				  (rel :case-ignore) (hseq :integer))
 	(unless name
 	  (setq name id))
@@ -3607,9 +3607,13 @@
 	    (w3m-add-face-property start end (if (w3m-arrived-p href)
 						     'w3m-arrived-anchor
 						   'w3m-anchor))
+	    (if title
+		(setq rhref (concat title "\n" (w3m-url-readable-string href)))
+	      (setq rhref (w3m-url-readable-string href)))
 	    (w3m-add-text-properties start end
 				     (list 'w3m-href-anchor href
-					   'w3m-balloon-help href
+					   'w3m-balloon-help rhref
+					   'w3m-anchor-title title
 					   'mouse-face 'highlight
 					   'w3m-anchor-sequence hseq
 					   'help-echo help
@@ -4099,7 +4103,7 @@
 						 (unless (interactive-p)
 						   safe-regexp))
 	    (setq w3m-display-inline-images (not status))
-	    (when status 
+	    (when status
 	      (w3m-process-stop (current-buffer))
 	      (w3m-idle-images-show-unqueue (current-buffer)))
 	    (force-mode-line-update)))
@@ -7133,16 +7137,22 @@
 	       (or (w3m-anchor (point)) (w3m-image (point)))))
 	(alt (if interactive-p
 		 (w3m-image-alt)
-	       (w3m-image-alt (point)))))
+	       (w3m-image-alt (point))))
+	(title (if interactive-p
+		   (w3m-anchor-title)
+		 (w3m-anchor-title (point)))))
     (when (or url interactive-p)
       (and url interactive-p (kill-new url))
-      (w3m-message "%s%s"
-		   (if (zerop (length alt))
-		       ""
-		     (concat alt ": "))
-		   (or (w3m-url-readable-string url)
-		       (and (w3m-action) "There is a form")
-		       "There is no url under point")))))
+      (setq url (or (w3m-url-readable-string url)
+		    (and (w3m-action) "There is a form")
+		    "There is no url under point"))
+      (w3m-message "%s" (cond
+			 ((> (length alt) 0)
+			  (concat alt ": " url))
+			 ((> (length title) 0)
+			  (concat title " (" url ")"))
+			 (t
+			  url))))))
 
 (defun w3m-print-this-image-url (&optional interactive-p)
   "Display image url under point in echo area and put it into `kill-ring'."