annotate lisp/gnus/gnus-picon.el @ 0:376386a54a3c r19-14

Import from CVS: tag r19-14
author cvs
date Mon, 13 Aug 2007 08:45:50 +0200
parents
children ac2d302a0011
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; gnus-picon.el --- displaying pretty icons in Gnus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;; Copyright (C) 1996 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Author: Wes Hardaker <hardaker@ece.ucdavis.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Keywords: news xpm annotation glyph faces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; This file is part of GNU Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; it under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; GNU Emacs is distributed in the hope that it will be useful,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; GNU General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;; Boston, MA 02111-1307, USA.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;; Usage:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;; - You must have XEmacs (19.12 or above I think) to use this.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;; - Read the variable descriptions below.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; - chose a setup:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; 1) display the icons in its own buffer:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; (add-hook 'gnus-article-display-hook 'gnus-article-display-picons t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;; (add-hook 'gnus-summary-prepare-hook 'gnus-group-display-picons t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; (setq gnus-picons-display-where 'picons)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; Then add the picons buffer to your display configuration:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;; The picons buffer needs to be at least 48 pixels high,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;; which for me is 5 lines:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;; (gnus-add-configuration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;; '(article (vertical 1.0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; (group 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;; (picons 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;; (summary .25 point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;; (article 1.0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;; (gnus-add-configuration
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;; '(summary (vertical 1.0 (group 6)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;; (picons 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;; (summary 1.0 point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;; 2) display the icons in the summary buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;; (add-hook 'gnus-article-display-hook 'gnus-article-display-picons t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;; (add-hook 'gnus-summary-prepare-hook 'gnus-group-display-picons t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;; (setq gnus-picons-display-where 'summary)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 ;; 3) display the icons in the article buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 ;; (add-hook 'gnus-article-display-hook 'gnus-article-display-picons t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 ;; (add-hook 'gnus-article-prepare-hook 'gnus-group-display-picons t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 ;; (setq gnus-picons-display-where 'article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 ;; Warnings:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 ;; - I'm not even close to being a lisp expert.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 ;; - The 't' (append) flag MUST be in the add-hook line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;; TODO:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;; - Remove the TODO section in the headers.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 (require 'xpm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (require 'annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (eval-when-compile (require 'cl))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (defvar gnus-picons-buffer "*Icon Buffer*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 "Buffer name to display the icons in if gnus-picons-display-where is 'picons.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (defvar gnus-picons-display-where 'picons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 "Where to display the group and article icons.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (defvar gnus-picons-database "/usr/local/faces"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 "Defines the location of the faces database.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 For information on obtaining this database of pretty pictures, please
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 see http://www.cs.indiana.edu/picons/ftp/index.html" )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (defvar gnus-picons-news-directory "news"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 "Sub-directory of the faces database containing the icons for newsgroups."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (defvar gnus-picons-user-directories '("local" "users" "usenix" "misc/MISC")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 "List of directories to search for user faces."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar gnus-picons-domain-directories '("domains")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "List of directories to search for domain faces.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 Some people may want to add \"unknown\" to this list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (defvar gnus-picons-x-face-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (format "/tmp/picon-xface.%s.xbm" (user-login-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "The name of the file in which to store the converted X-face header.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (defvar gnus-picons-convert-x-face (format "{ echo '/* Width=48, Height=48 */'; uncompface; } | icontopbm | pbmtoxbm > %s" gnus-picons-x-face-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 "Command to convert the x-face header into a xbm file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defvar gnus-picons-file-suffixes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (when (featurep 'x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (let ((types (list "xbm")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (when (featurep 'gif)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (push "gif" types))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (when (featurep 'xpm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (push "xpm" types))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 types))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 "List of suffixes on picon file names to try.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (defvar gnus-picons-display-article-move-p t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 "*Whether to move point to first empty line when displaying picons.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 This has only an effect if `gnus-picons-display-where' hs value article.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 ;;; Internal variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (defvar gnus-group-annotations nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (defvar gnus-article-annotations nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (defvar gnus-x-face-annotations nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (defun gnus-picons-remove (plist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (let ((listitem (car plist)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (while (setq listitem (car plist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (if (annotationp listitem)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (delete-annotation listitem))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (setq plist (cdr plist))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (defun gnus-picons-remove-all ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 "Removes all picons from the Gnus display(s)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (gnus-picons-remove gnus-article-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (gnus-picons-remove gnus-group-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (gnus-picons-remove gnus-x-face-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (setq gnus-article-annotations nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 gnus-group-annotations nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 gnus-x-face-annotations nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (bufferp gnus-picons-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (kill-buffer gnus-picons-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (defun gnus-get-buffer-name (variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 "Returns the buffer name associated with the contents of a variable."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (cond ((symbolp variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (let ((newvar (cdr (assq variable gnus-window-to-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (cond ((symbolp newvar)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (symbol-value newvar))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ((stringp newvar) newvar))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ((stringp variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (defun gnus-picons-article-display-x-face ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 "Display the x-face header bitmap in the 'gnus-picons-display-where buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 ;; delete any old ones.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (gnus-picons-remove gnus-x-face-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (setq gnus-x-face-annotations nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 ;; display the new one.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (let ((gnus-article-x-face-command 'gnus-picons-display-x-face))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 (gnus-article-display-x-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 (defun gnus-picons-display-x-face (beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 "Function to display the x-face header in the picons window.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 To use: (setq gnus-article-x-face-command 'gnus-picons-display-x-face)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 ;; convert the x-face header to a .xbm file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (let ((process-connection-type nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (process nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (process-kill-without-query
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq process (start-process
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 "gnus-x-face" nil shell-file-name shell-command-switch
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 gnus-picons-convert-x-face)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (process-send-region "gnus-x-face" beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (process-send-eof "gnus-x-face")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; wait for it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (while (not (equal (process-status process) 'exit))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (sleep-for .1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 ;; display it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (set-buffer (get-buffer-create (gnus-get-buffer-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 gnus-picons-display-where)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (gnus-add-current-to-buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (let (buffer-read-only)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (unless (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (push (make-annotation "\n" (point) 'text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 gnus-x-face-annotations))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;; append the annotation to gnus-article-annotations for deletion.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (setq gnus-x-face-annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (gnus-picons-try-to-find-face gnus-picons-x-face-file-name t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 gnus-x-face-annotations)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; delete the tmp file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (delete-file gnus-picons-x-face-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (defun gnus-article-display-picons ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 "Display faces for an author and his/her domain in gnus-picons-display-where."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (let (from at-idx databases)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (when (and (featurep 'xpm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (or (not (fboundp 'device-type)) (equal (device-type) 'x))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (setq from (mail-fetch-field "from"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (setq from (downcase (cadr (mail-extract-address-components
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 at-idx (string-match "@" from)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 (let ((username (substring from 0 at-idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (addrs (nreverse
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 (message-tokenize-header (substring from (1+ at-idx))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 "."))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (set-buffer (get-buffer-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (gnus-get-buffer-name gnus-picons-display-where)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (gnus-add-current-to-buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (if (and (eq gnus-picons-display-where 'article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 gnus-picons-display-article-move-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (when (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (unless (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (push (make-annotation "\n" (point) 'text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 gnus-article-annotations)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (gnus-picons-remove gnus-article-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (setq gnus-article-annotations nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq databases (append gnus-picons-user-directories
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 gnus-picons-domain-directories))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (while databases
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (setq gnus-article-annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (nconc (gnus-picons-insert-face-if-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (car databases)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 addrs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 "unknown")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (gnus-picons-insert-face-if-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (car databases)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 addrs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (downcase username) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 gnus-article-annotations))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (setq databases (cdr databases)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (add-hook 'gnus-summary-exit-hook 'gnus-picons-remove-all))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (defun gnus-group-display-picons ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 "Display icons for the group in the gnus-picons-display-where buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (when (and (featurep 'xpm)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (or (not (fboundp 'device-type)) (equal (device-type) 'x)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (set-buffer (get-buffer-create
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (gnus-get-buffer-name gnus-picons-display-where)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (gnus-add-current-to-buffer-list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (goto-char (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (if (and (eq gnus-picons-display-where 'article)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 gnus-picons-display-article-move-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (if (search-forward "\n\n" nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (unless (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (push (make-annotation "\n" (point) 'text)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 gnus-group-annotations)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 ((listp gnus-group-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (mapcar 'delete-annotation gnus-group-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (setq gnus-group-annotations nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 ((annotationp gnus-group-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (delete-annotation gnus-group-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (setq gnus-group-annotations nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (gnus-picons-remove gnus-group-annotations)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (setq gnus-group-annotations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (gnus-picons-insert-face-if-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 gnus-picons-news-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (message-tokenize-header gnus-newsgroup-name ".")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 "unknown"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (add-hook 'gnus-summary-exit-hook 'gnus-picons-remove-all))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 (defsubst gnus-picons-try-suffixes (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 (let ((suffixes gnus-picons-file-suffixes)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 f)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (while (and suffixes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 (not (file-exists-p (setq f (concat file (pop suffixes))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (setq f nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 f))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (defun gnus-picons-insert-face-if-exists (database addrs filename &optional
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 nobar-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 "Inserts a face at point if I can find one"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 ;; '(gnus-picons-insert-face-if-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 ; "Database" '("edu" "indiana" "cs") "Name")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ;; looks for:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 ;; 1. edu/indiana/cs/Name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 ;; 2. edu/indiana/Name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;; 3. edu/Name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; '(gnus-picons-insert-face-if-exists
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;; "Database/MISC" '("edu" "indiana" "cs") "Name")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;; looks for:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 ;; 1. MISC/Name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; The special treatment of MISC doesn't conform with the conventions for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 ;; picon databases, but otherwise we would always see the MISC/unknown face.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (let ((bar (and (not nobar-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (annotations-in-region
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (point) (min (point-max) (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 (current-buffer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (path (concat (file-name-as-directory gnus-picons-database)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 database "/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 picons found bar-ann)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if (string-match "/MISC" database)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 (setq addrs '("")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (while (and addrs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (file-accessible-directory-p path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (setq path (concat path (pop addrs) "/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 (when (setq found
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (gnus-picons-try-suffixes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (concat path filename "/face.")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (when bar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (setq bar-ann (gnus-picons-try-to-find-face
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (concat gnus-xmas-glyph-directory "bar.xbm")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (when bar-ann
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (setq picons (nconc picons bar-ann))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (setq bar nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (setq picons (nconc (gnus-picons-try-to-find-face found)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 picons))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (nreverse picons)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (defvar gnus-picons-glyph-alist nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (defun gnus-picons-try-to-find-face (path &optional xface-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 "If PATH exists, display it as a bitmap. Returns t if succedded."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (let ((glyph (and (not xface-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (cdr (assoc path gnus-picons-glyph-alist)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (when (or glyph (file-exists-p path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (unless glyph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (setq glyph (make-glyph path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (unless xface-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (push (cons path glyph) gnus-picons-glyph-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (set-glyph-face glyph 'default))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 (nconc
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (list (make-annotation glyph (point) 'text))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (when (eq major-mode 'gnus-article-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (list (make-annotation " " (point) 'text)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (defun gnus-picons-reverse-domain-path (str)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 "a/b/c/d -> d/c/b/a"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (mapconcat 'downcase (nreverse (message-tokenize-header str "/")) "/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (gnus-add-shutdown 'gnus-picons-close 'gnus)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (defun gnus-picons-close ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 "Shut down the picons."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (setq gnus-picons-glyph-alist nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (provide 'gnus-picon)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;;; gnus-picon.el ends here