[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 03/03: [xpm maint] Add debugging aid Emacs Lisp file.
From: |
Thien-Thi Nguyen |
Subject: |
[elpa] 03/03: [xpm maint] Add debugging aid Emacs Lisp file. |
Date: |
Sat, 17 May 2014 21:39:49 +0000 |
ttn pushed a commit to branch master
in repository elpa.
commit c2c7221e4283de4ea8ac94b7797726f91c929250
Author: Thien-Thi Nguyen <address@hidden>
Date: Sat May 17 23:44:24 2014 +0200
[xpm maint] Add debugging aid Emacs Lisp file.
* packages/xpm/flower.el: New file.
* packages/xpm/.elpaignore: Update.
---
packages/xpm/.elpaignore | 1 +
packages/xpm/flower.el | 100 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 0 deletions(-)
diff --git a/packages/xpm/.elpaignore b/packages/xpm/.elpaignore
index 5c374b1..dd69f33 100644
--- a/packages/xpm/.elpaignore
+++ b/packages/xpm/.elpaignore
@@ -1 +1,2 @@
HACKING
+flower.el
diff --git a/packages/xpm/flower.el b/packages/xpm/flower.el
new file mode 100644
index 0000000..df154ba
--- /dev/null
+++ b/packages/xpm/flower.el
@@ -0,0 +1,100 @@
+;;; flower.el --- can `xpm-raster' DTRT? -*- lexical-binding: t -*-
+
+;; Copyright (C) 2014 Free Software Foundation, Inc.
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; This file helps visualize `xpm-raster' failure modes. Maybe one
+;; day it will be rendered useless by improvements to `xpm-raster'.
+;;
+;; NB: There is no `provide' form.
+;; NB: Loading munges the global keymap -- YHBW!
+
+;;; Code:
+
+(require 'xpm)
+(require 'xpm-m2z)
+(require 'cl-lib)
+
+(defun flower (&optional again)
+ "Stress `xpm-raster' in various ways."
+ (interactive "P")
+ (let ((buf (get-buffer "flower")))
+ (when buf (kill-buffer buf)))
+ (switch-to-buffer
+ (xpm-generate-buffer "flower" 99 99 2
+ '((" " . "green")
+ (".." . "yellow")
+ ("OO" . "red")
+ ("--" . "black"))))
+ (setq truncate-lines t)
+ (let* ((τ (* 4 2 (atan 1)))
+ (half (/ 99 2.0))
+ (mag-fns (vector (lambda (θ) (ignore θ) 1)
+ (lambda (θ) (sin θ))
+ (lambda (θ) (cos θ))
+ (lambda (θ) (sin (* 0.5 τ θ)))
+ (lambda (θ) (cos (* 0.5 τ θ)))
+ (lambda (θ) (sin (* 0.25 τ θ)))
+ (lambda (θ) (cos (* 0.25 τ θ)))
+ (lambda (θ) (sin (* τ θ)))
+ (lambda (θ) (cos (* τ θ)))))
+ (n-mag-fns (length mag-fns)))
+ (cl-flet
+ ((random-mag-fn () (aref mag-fns (random n-mag-fns))))
+ (let* ((x-mag-fn (random-mag-fn))
+ (y-mag-fn (random-mag-fn))
+ (form (if again
+ (get 'flower 'form)
+ (delete-dups
+ (if (zerop (random 5))
+ (let ((one (xpm-m2z-circle
+ half half
+ (random 42)))
+ (two (xpm-m2z-ellipse
+ half half
+ (random 42)
+ (random 42))))
+ (append one two))
+ (loop
+ for θ below τ by 0.003
+ collect
+ (cl-flet
+ ((at (f mfn)
+ (truncate (+ half (* 42 (funcall mfn θ)
+ (funcall f θ))))))
+ (cons (at 'cos x-mag-fn)
+ (at 'sin y-mag-fn)))))))))
+ (put 'flower 'form form)
+ (xpm-raster form "OO" ".."))))
+ (image-mode)
+ ;; strangely, image-mode screws up the markers, so we need to do
+ ;; this again if we want to do subsequent xpm-* access:
+ ;;+ (xpm-grok t)
+ t)
+
+;;;---------------------------------------------------------------------------
+;;; load-time actions
+
+(global-set-key [f9] 'flower)
+(global-set-key
+ [(meta f9)]
+ (lambda () (interactive)
+ (message "xpm-raster-inhibit-continuity-optimization now %s"
+ (setq xpm-raster-inhibit-continuity-optimization
+ (not xpm-raster-inhibit-continuity-optimization)))))
+
+;;; flower.el ends here