-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathHISTORY
More file actions
84 lines (74 loc) · 3.49 KB
/
HISTORY
File metadata and controls
84 lines (74 loc) · 3.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
;; -*- mode: Gimp; -*-
;;; This file describes the history of various parts of Gimp Mode.
;;;; 1. History of `emacs-cl-output' macro.
;; The problems this macro solves is twofold: first, the
;; script-fu-server in GIMP does not print the return value after
;; evaluation. Second, the evaluation is not part of the running
;; scheme image. This macro will write back the evaluation to a file,
;; to be read both by Emacs and GIMP itself.
;; Note that the problem of not returning the result of evaluation is
;; addressed in https://bugzilla.gnome.org/show_bug.cgi?id=583778,
;; with a working patch available and planned for taking a look at
;; with version 2.8.
;; First try: make sure define'd stuff is loaded into the image
;; Major defect: double evaluation.
(define-macro (emacs-cl-output . body)
`(begin
;; first, give us some output
(with-output-to-file
(string-append gimp-dir "/emacs-output.scm")
(lambda ()
(write ,@body)))
;; then make sure stuff is loaded into the scheme image
(with-output-to-file
(string-append gimp-dir "/emacs-input.scm")
(lambda ()
(write ',@body))) ;note the quote!
(load (string-append gimp-dir "/emacs-input.scm")))) ;and load...
;; 2nd try: attempt to break the side-effect of evalling twice (does
;; not load the evalled stuff into the scheme image) :
(define-macro (emacs-cl-output . body)
(let ((input-file (string-append gimp-dir "/emacs-input.scm"))
(output-file (string-append gimp-dir "/emacs-output.scm")))
`(begin
(with-output-to-file ,input-file
(lambda ()
(write
'(with-output-to-file
,output-file
(lambda ()
(write ,@body))))
(write nil))) ;;needed for the scheme lisp reader (if the
;;last sexp is immediately followed by EOF,
;;it complains about unbalanced parentheses:1
;;...) later I found out (display "\n") does
;;a better job.
(load ,input-file))))
;; Final solution: evals once, loads evaluated expression into image,
;; writes output of evaluation back, and pushes a specially crafted
;; handler to be called by *error-hook*. And by this time I had made a
;; `with-output-to-emacs-file' macro that wraps the body in a lambda
;; form.
(define-macro (emacs-cl-output . body)
(let ((input-file "emacs-input.scm")
(output-file "emacs-output.scm"))
(unless (memq gimp-cl-handler *handlers*)
(push-handler gimp-cl-handler))
`(begin
(with-output-to-emacs-file ,input-file
(write
'(set! *emacs-cl-output* ,@body))
(newline) ;apparently, any sexp at
;top-level needs some distance
;for the reader
(write '(with-output-to-emacs-file
,output-file
(write *emacs-cl-output*)))
(newline))
(load ,(make-emacs-file input-file)))))
;; Concluding: we let GIMP write two forms into a file. The fist form
;; is to evaluate the initial input and put the result in a temporary
;; variable (called `*emacs-cl-output*'). The second form is to write
;; back this evaluation into a file to be read by Emacs.
;; After that, GIMP loads the file, and thereby loads the initial
;; input just once, leaving a file for Emacs to read the result from.