From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.general/83762 Path: news.gmane.org!not-for-mail From: Rasmus Newsgroups: gmane.emacs.gnus.general Subject: [patch][gnus-fun] Support for random png Faces Date: Tue, 10 Sep 2013 00:05:50 +0200 Message-ID: <878uz5zm4h.fsf@gmx.us> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1378764435 17849 80.91.229.3 (9 Sep 2013 22:07:15 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Sep 2013 22:07:15 +0000 (UTC) To: ding@gnus.org Original-X-From: ding-owner+M32018@lists.math.uh.edu Tue Sep 10 00:07:17 2013 Return-path: Envelope-to: ding-account@gmane.org Original-Received: from util0.math.uh.edu ([129.7.128.18]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1VJ9c4-0004Sv-CW for ding-account@gmane.org; Tue, 10 Sep 2013 00:07:16 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.math.uh.edu) by util0.math.uh.edu with smtp (Exim 4.63) (envelope-from ) id 1VJ9b4-0003jk-C9; Mon, 09 Sep 2013 17:06:14 -0500 Original-Received: from mx1.math.uh.edu ([129.7.128.32]) by util0.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1VJ9b1-0003jW-BM for ding@lists.math.uh.edu; Mon, 09 Sep 2013 17:06:11 -0500 Original-Received: from quimby.gnus.org ([80.91.231.51]) by mx1.math.uh.edu with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1VJ9az-0002pB-7A for ding@lists.math.uh.edu; Mon, 09 Sep 2013 17:06:10 -0500 Original-Received: from plane.gmane.org ([80.91.229.3]) by quimby.gnus.org with esmtp (Exim 4.72) (envelope-from ) id 1VJ9ax-0008Nd-9k for ding@gnus.org; Tue, 10 Sep 2013 00:06:07 +0200 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1VJ9ax-0002dc-2C for ding@gnus.org; Tue, 10 Sep 2013 00:06:07 +0200 Original-Received: from f053038129.adsl.alicedsl.de ([78.53.38.129]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Sep 2013 00:06:07 +0200 Original-Received: from rasmus by f053038129.adsl.alicedsl.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Tue, 10 Sep 2013 00:06:07 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 212 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: f053038129.adsl.alicedsl.de Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAAAAAByaaZbAAAAAmJLR0QA/4ePzL8AAAAJcEhZ cwAAAEgAAABIAEbJaz4AAAJLSURBVEjHzZa7geQwDEMdoxm0wlJYCVtBMWgHwQXyT7O7txceI9vj J1EkCM8xSbWdJN2yx7mi0RJRCXU/PCqpWddecf3okm2hMpUHYMx7UTsDwPcCsTGC895BLz4uiXw/ QL3fz9Hh+162vVKWlCQF5Q2o+31v2+lJ0gDoJOUdqM/3LSoZjAUk0WzAzifxEIoxdgbKfsYcdz1e laJDJlGjvgXknaAaTAZF+BvAqh0ogJVURVD2qhxwbOohbKs1XBWAU3tZq2Oz7a2wnkpiT8XMnhL8 yO8WVLoS2+VUfwB0wtl3sEexMpXBfAKKkXkUfO4hygWOduII1v6NLSl12XEpEdld15wcQpb8+OTq ZmtXjPrU6EFlOkmE/BS27ebZB51Xu8wTTc+SOWXbZq15uMtWStJXmwo9U0vfkB276Et8N9A8eUGO LTgxa4otD3sDlpwvB1nFHSZpcJromPMClgFwqWqlLTWcsypmefgGmvKA8VmaIUAoa2STlPQATXSS DC7hDlpr9b57rT5eg7YCOi+XJHqSRwSt40uXKF91SmImfY6cSfhnYMmUswp19SZfgNs4jUqMs3kf rvFWxD3yZGJgn5+vwCNTYSx92tYn4JenNAHszvoJeOhE5y62pvhlRDdrh+Ii4MTL3qwPm9nyhzPl 1a1BjdSyN/t9A0K51hnGyYAAUN6c6dhagGuwVVkNs9mb930c+tns/laanvlLH1YMnxmv+Qeg+ml5 d/0GyI5vKxS2z+6366Nf1qlNTt8Cnn79g/Akv57h5/gPgT/tvnoH3s4GngAAAABJRU5ErkJggg== User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:dqGaniIR568rUy97ax5Me18EVvQ= X-Spam-Score: -2.8 (--) List-ID: Precedence: bulk Xref: news.gmane.org gmane.emacs.gnus.general:83762 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Hi, There is already support for random X-Face in Gnus. This patch adds support for png faces as well. Further, support to omit certain faces in a dir is added. It works nicely e.g. for posting-styles. I'd welcome any feedback. I have mainly tested with png faces as the suggested way of producing X-Faces (e.g. gnus-convert-pbm-to-x-face-command) didn't work as expected on my system (with compface 1.5.2 and netpbm 10.61.0). I have signed copyright paper to Emacs. –Rasmus --=-=-= Content-Type: text/x-diff Content-Disposition: attachment; filename=0001-gnus-fun.el-Random-faces-for-png-Face.patch >From 22cac76a05e72116e868cf18d86f80ffb93ebf67 Mon Sep 17 00:00:00 2001 From: rasmus Date: Wed, 4 Sep 2013 19:05:15 +0200 Subject: [PATCH] gnus-fun.el: Random faces for png Face. --- lisp/ChangeLog | 18 +++++++++++ lisp/gnus-fun.el | 93 ++++++++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 92 insertions(+), 19 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index dfb4d54..abf1acc 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,21 @@ +2013-09-04 Rasmus Pank Roulund + + * gnus-fun.el (gnus-x-face-omit-files): Regexp to omit matched results + from random face commands. + (gnus-face-directory): Like `gnus-x-face-directory` for png files and + Face. + (gnus-face-omit-files): Like `gnus-x-face-omit-files` for Face. + (gnus--random-face-with-type): Generic function returning a face-type + as a string. + (gnus--insert-random-face-with-type): Generic function inserting a face + in a message buffer header. + (gnus-random-x-face): Rewritten to use `gnus--random-face-with-type`. + (gnus-insert-random-x-face-header): Rewritten to use + `gnus--insert-random-face-with-type`. + (gnus-random-face): Return random (png) Face as string. + (nus-insert-random-face-header): Insert random (png) Face in a message + buffer. + 2013-08-28 Katsumi Yamaoka * mm-decode.el (mm-temp-files-delete): Fix file deletion logic. diff --git a/lisp/gnus-fun.el b/lisp/gnus-fun.el index 1c9b4ce..4eb726a 100644 --- a/lisp/gnus-fun.el +++ b/lisp/gnus-fun.el @@ -44,6 +44,24 @@ :group 'gnus-fun :type 'directory) +(defcustom gnus-x-face-omit-files nil + "Regexp to match faces in `gnus-x-face-directory' to be omitted." + :version "24.3" + :group 'gnus-fun + :type 'string) + +(defcustom gnus-face-directory (expand-file-name "faces" gnus-directory) + "*Directory where Face PNG files are stored." + :version "24.3" + :group 'gnus-fun + :type 'directory) + +(defcustom gnus-face-omit-files nil + "Regexp to match faces in `gnus-face-directory' to be omitted." + :version "24.3" + :group 'gnus-fun + :type 'string) + (defcustom gnus-convert-pbm-to-x-face-command "pbmtoxbm %s | compface" "Command for converting a PBM to an X-Face." :version "22.1" @@ -86,35 +104,57 @@ PNG format." nil shell-command-switch command))) ;;;###autoload -(defun gnus-random-x-face () - "Return X-Face header data chosen randomly from `gnus-x-face-directory'." - (interactive) - (when (file-exists-p gnus-x-face-directory) - (let* ((files (directory-files gnus-x-face-directory t "\\.pbm$")) - (file (nth (random (length files)) files))) +(defun gnus--random-face-with-type (dir ext omit fun) + "Return file from DIR with extension EXT, omitting matches of OMIT, processed by FUN." + (when (file-exists-p dir) + (let* ((files + (remove nil (mapcar + (lambda (f) (unless (string-match (or omit "^$") f) f)) + (directory-files dir t ext)))) + (file (nth (random (length files)) files))) (when file - (gnus-shell-command-to-string - (format gnus-convert-pbm-to-x-face-command - (shell-quote-argument file))))))) + (funcall fun file))))) +;;;###autoload (autoload 'message-goto-eoh "message" nil t) +(autoload 'message-insert-header "message" nil t) + +(defun gnus--insert-random-face-with-type (fun type) + "Get a random face using FUN and insert it as a header TYPE. + +For instance, to insert an X-Face use `gnus-random-x-face' as FUN + and \"X-Face\" as TYPE." + (let ((data (funcall fun))) + (save-excursion + (if data + (progn (message-goto-eoh) + (insert type ": " data "\n")) + (message + "No face returned by the function %s." (symbol-name fun)))))) + + + +;;;###autoload +(defun gnus-random-x-face () + "Return X-Face header data chosen randomly from `gnus-x-face-directory'. + +Files matching `gnus-x-face-omit-files' are not considered." + (interactive) + (gnus--random-face-with-type gnus-x-face-directory "\\.pbm$" gnus-x-face-omit-files + (lambda (file) + (gnus-shell-command-to-string + (format gnus-convert-pbm-to-x-face-command + (shell-quote-argument file)))))) ;;;###autoload (defun gnus-insert-random-x-face-header () "Insert a random X-Face header from `gnus-x-face-directory'." (interactive) - (let ((data (gnus-random-x-face))) - (save-excursion - (message-goto-eoh) - (if data - (insert "X-Face: " data) - (message - "No face returned by `gnus-random-x-face'. Does %s/*.pbm exist?" - gnus-x-face-directory))))) + (gnus--insert-random-face-with-type 'gnus-random-x-face 'X-Face)) ;;;###autoload (defun gnus-x-face-from-file (file) - "Insert an X-Face header based on an image file. + "Insert an X-Face header based on an image FILE. Depending on `gnus-convert-image-to-x-face-command' it may accept different input formats." @@ -126,7 +166,7 @@ different input formats." ;;;###autoload (defun gnus-face-from-file (file) - "Return a Face header based on an image file. + "Return a Face header based on an image FILE. Depending on `gnus-convert-image-to-face-command' it may accept different input formats." @@ -191,6 +231,21 @@ FILE should be a PNG file that's 48x48 and smaller than or equal to (buffer-size))) (gnus-face-encode))) +;;;###autoload +(defun gnus-random-face () + "Return randomly chosen Face from `gnus-face-directory'. + +Files matching `gnus-face-omit-files' are not considered." + (interactive) + (gnus--random-face-with-type gnus-face-directory "\\.png$" + gnus-face-omit-files + 'gnus-convert-png-to-face)) + +;;;###autoload +(defun gnus-insert-random-face-header () + "Insert a randome Face header from `gnus-face-directory'." + (gnus--insert-random-face-with-type 'gnus-random-face 'Face)) + (defface gnus-x-face '((t (:foreground "black" :background "white"))) "Face to show X-Face. The colors from this face are used as the foreground and background -- 1.8.4 --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit -- ツ --=-=-=--