Gnus development mailing list
 help / color / mirror / Atom feed
* [PATCH] new format specifier
@ 1998-10-22 12:57 Didier Verna
  0 siblings, 0 replies; only message in thread
From: Didier Verna @ 1998-10-22 12:57 UTC (permalink / raw)



	Hi folks.

	I've implemented a new format specifier (%[0-9]?< and %>) which lets
you put a 'balloon-help property on text. A patch is appended below[1]. This
specifier uses variables named `gnus-balloon-face-*' which can be either
strings or syumbols naming functions that return a string. This string will
appear in the help balloon when the mouse passes over the text.

Usefull? Hmmm. As an example, I use this on the Group lines. When the mouse
passes over one of my nnml groups, I get a balloon window with a summary of
the new mails arrived (author & subject). I find this rather neat ;-)

... somewhere in the group-line-format: "%<%(%g%)%>".
... somewhere in the gnusrc file:
| (defun gnus-group-new-mails-summary (balloon-object)	
|   "Build a balloon help containing headers of new mails in this group."
|   (let ((group (get-text-property 			
| 		  (save-excursion 			
| 		    (goto-char (extent-start-position balloon-object))
| 		    (point-at-bol))			
| 		  'gnus-group)))				
|     (when (and group 					
| 		 (setq group (symbol-name group))		
| 		 (string-match "nnml\\+mail" group)	
| 		 (numberp (gnus-group-unread group))	
| 		 (> (gnus-group-unread group) 0))		
| 	(let ((summary ""))				
| 	  (gnus-retrieve-headers (gnus-list-of-unread-articles group) group)
| 	  (with-current-buffer nntp-server-buffer		
| 	    (goto-char (point-min))			
| 	    (while (re-search-forward			
| 		    "^[^\t]+\t\\([^\t]+\\)\t\\([^<]+\\) <.*$" nil t)
| 	      (setq summary				
| 		    (concat summary 			
| 			    (format "%10s:\t%s\n"		
| 				    (match-string 2) (match-string 1))))))
| 	  summary						
| 	  ))						
|     ))							
| (setq gnus-balloon-face-0 'gnus-group-new-mails-summary)


	Lars, if you like it, fell free to twiddle it as you want. I'm working 
with XEmacs 21.2.


Have fun !


1998-10-22  Didier Verna  <verna@inf.enst.fr>

	* gnus-spec.el (gnus-balloon-face-function): new function
	(gnus-parse-format): understand the %< %> specifiers
	(gnus-parse-complex-format): ditto.


--- gnus-spec.el.orig	Wed Oct 21 14:39:44 1998
+++ gnus-spec.el	Thu Oct 22 14:09:04 1998
@@ -241,6 +241,12 @@
     (point) (progn ,@form (point))
     '(gnus-face t face ,(symbol-value (intern (format "gnus-face-%d" type))))))
 
+(defun gnus-balloon-face-function (form type)
+  `(gnus-put-text-property 
+    (point) (progn ,@form (point))
+    'balloon-help
+    ,(intern (format "gnus-balloon-face-%d" type))))
+
 (defun gnus-tilde-max-form (el max-width)
   "Return a form that limits EL to MAX-WIDTH."
   (let ((max (abs max-width)))
@@ -287,8 +293,10 @@
   ;; SPEC-ALIST and returns a list that can be eval'ed to return the
   ;; string.  If the FORMAT string contains the specifiers %( and %)
   ;; the text between them will have the mouse-face text property.
+  ;; If the FORMAT string contains the specifiers %< and %>, the text between
+  ;; them will have the balloon-help text property.
   (if (string-match
-       "\\`\\(.*\\)%[0-9]?[{(]\\(.*\\)%[0-9]?[})]\\(.*\n?\\)\\'"
+       "\\`\\(.*\\)%[0-9]?[{(<]\\(.*\\)%[0-9]?[})>]\\(.*\n?\\)\\'"
        format)
       (gnus-parse-complex-format format spec-alist)
     ;; This is a simple format.
@@ -303,13 +311,17 @@
       (replace-match "\\\"" nil t))
     (goto-char (point-min))
     (insert "(\"")
-    (while (re-search-forward "%\\([0-9]+\\)?\\([{}()]\\)" nil t)
+    (while (re-search-forward "%\\([0-9]+\\)?\\([{}()<>]\\)" nil t)
       (let ((number (if (match-beginning 1)
 			(match-string 1) "0"))
 	    (delim (aref (match-string 2) 0)))
 	(if (or (= delim ?\()
-		(= delim ?\{))
-	    (replace-match (concat "\"(" (if (= delim ?\() "mouse" "face")
+		(= delim ?\{)
+		(= delim ?\<))
+	    (replace-match (concat "\"(" 
+				   (cond ((= delim ?\() "mouse")
+					 ((= delim ?\{) "face")
+					 (t "balloon"))
 				   " " number " \""))
 	  (replace-match "\")\""))))
     (goto-char (point-max))



Footnotes: 
[1]  Sorry, I'm not on the bleeding edge. This is against gnus 5.6.44.


-- 
    /     /   _   _       Didier Verna        http://www.inf.enst.fr/~verna/
 - / / - / / /_/ /      E.N.S.T. INF C201.1      mailto:verna@inf.enst.fr
/_/ / /_/ / /__ /        46 rue Barrault        Tel.   (33) 01 45 81 73 46
                      75634 Paris  cedex 13     Fax.   (33) 01 45 81 31 19


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1998-10-22 12:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-10-22 12:57 [PATCH] new format specifier Didier Verna

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).