1 ;;; gnus-fun.el --- various frivoluos extension functions to Gnus
2 ;; Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4 ;; Author: Lars Magne Ingebrigtsen <larsi@gnus.org>
7 ;; This file is part of GNU Emacs.
9 ;; GNU Emacs is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; GNU Emacs is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
28 (defcustom gnus-x-face-directory (expand-file-name "x-faces" gnus-directory)
29 "*Directory where X-Face PBM files are stored."
33 (defcustom gnus-convert-pbm-to-x-face-command "pbmtoxbm %s | compface"
34 "Command for converting a PBM to an X-Face."
38 (defcustom gnus-convert-image-to-x-face-command "giftopnm %s | ppmnorm | pnmscale -width 48 -height 48 | ppmtopgm | pgmtopbm | pbmtoxbm | compface"
39 "Command for converting an image to an X-Face.
40 By default it takes a GIF filename and output the X-Face header data
45 (defcustom gnus-convert-image-to-face-command "djpeg %s | ppmnorm | pnmscale -width 48 -height 48 | ppmquant %d | pnmtopng"
46 "Command for converting an image to an Face.
47 By default it takes a JPEG filename and output the Face header data
52 (defun gnus-shell-command-to-string (command)
53 "Like `shell-command-to-string' except not mingling ERROR."
54 (with-output-to-string
55 (call-process shell-file-name nil (list standard-output nil)
56 nil shell-command-switch command)))
58 (defun gnus-shell-command-on-region (start end command)
59 "A simplified `shell-command-on-region'.
60 Output to the current buffer, replace text, and don't mingle error."
61 (call-process-region start end shell-file-name t
62 (list (current-buffer) nil)
63 nil shell-command-switch command))
66 (defun gnus-random-x-face ()
67 "Return X-Face header data chosen randomly from `gnus-x-face-directory'."
69 (when (file-exists-p gnus-x-face-directory)
70 (let* ((files (directory-files gnus-x-face-directory t "\\.pbm$"))
71 (file (nth (random (length files)) files)))
73 (gnus-shell-command-to-string
74 (format gnus-convert-pbm-to-x-face-command
75 (shell-quote-argument file)))))))
78 (defun gnus-insert-random-x-face-header ()
79 "Insert a random X-Face header from `gnus-x-face-directory'."
81 (let ((data (gnus-random-x-face)))
85 (insert "X-Face: " data)
87 "No face returned by `gnus-random-x-face'. Does %s/*.pbm exist?"
88 gnus-x-face-directory)))))