-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclimacs.lisp
106 lines (96 loc) · 4.41 KB
/
climacs.lisp
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
;;; -*- Mode: Lisp; Package: CLIMACS -*-
;;; (c) copyright 2004-2005 by
;;; Robert Strandh ([email protected])
;;; (c) copyright 2004-2005 by
;;; Elliott Johnson ([email protected])
;;; (c) copyright 2005 by
;;; Matthieu Villeneuve ([email protected])
;;; (c) copyright 2005 by
;;; Aleksandar Bakic ([email protected])
;;; (c) copyright 2006 by
;;; Troels Henriksen ([email protected])
;;; This library is free software; you can redistribute it and/or
;;; modify it under the terms of the GNU Library General Public
;;; License as published by the Free Software Foundation; either
;;; version 2 of the License, or (at your option) any later version.
;;;
;;; This library 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
;;; Library General Public License for more details.
;;;
;;; You should have received a copy of the GNU Library General Public
;;; License along with this library; if not, write to the
;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
;;; Boston, MA 02111-1307 USA.
;;; Entry points for the Climacs editor.
(in-package :climacs)
(defun find-climacs-frame ()
(let ((frame-manager (find-frame-manager)))
(when frame-manager
(find-if (lambda (x) (and (typep x 'climacs)
(eq (clim:frame-state x) :enabled)))
(frame-manager-frames frame-manager)))))
(defun climacs (&rest args &key new-process (process-name "Climacs")
(text-style *climacs-text-style*)
(width 900) (height 400))
"Starts up a climacs session"
(declare (ignore new-process process-name width height text-style))
(apply #'climacs-common nil args))
(defun climacs-rv (&rest args &key new-process (process-name "Climacs")
(text-style *climacs-text-style*)
(width 900) (height 400))
"Starts up a climacs session with alternative colors."
;; SBCL doesn't inherit dynamic bindings when starting new
;; processes, so start a new processes and THEN setup the colors.
(declare (ignore text-style width height))
(flet ((run ()
(let ((*background-color* +black+)
(*foreground-color* +gray+)
(*info-bg-color* +darkslategray+)
(*info-fg-color* +gray+)
(*mini-bg-color* +black+)
(*mini-fg-color* +white+))
(apply #'climacs-common nil :new-process nil args))))
(if new-process
(clim-sys:make-process #'run :name process-name)
(run))))
(defun edit-file (thing &rest args
&key (process-name "Climacs") (width 900) (height 400)
(text-style *climacs-text-style*))
"Edit THING in an existing climacs process or start a new one. THING
can be a filename (edit the file) or symbol (edit its function definition)."
(declare (ignore process-name width height text-style))
(let ((climacs-frame (find-climacs-frame))
(command
(typecase thing
(null nil)
(symbol (list 'drei-lisp-syntax::com-edit-definition thing))
((or string pathname)
(truename thing) ; raise file-error if file doesn't exist
(list 'esa-io::com-find-file thing))
(t (error 'type-error :datum thing
:expected-type '(or null string pathname symbol))))))
(if climacs-frame
(when command
(execute-frame-command climacs-frame command))
(apply #'climacs-common command :new-process t args)))
t)
(defun climacs-common (command &key new-process (process-name "Climacs")
(text-style *climacs-text-style*)
(width 900) (height 400))
(let* ((frame (make-application-frame 'climacs :width width :height height))
(*climacs-text-style* text-style)
(*application-frame* frame)
(esa:*esa-instance* frame))
(adopt-frame (find-frame-manager) *application-frame*)
(when command (execute-frame-command *application-frame* command))
(flet ((run () (run-frame-top-level frame)))
(if new-process
(clim-sys:make-process #'run :name process-name)
(run)))))
;;; Append to end of *ed-functions* so we don't overwrite the user's
;;; preferred editor
#+sbcl
(unless (member 'edit-file sb-ext:*ed-functions*)
(setf sb-ext:*ed-functions* (append sb-ext:*ed-functions* (list 'edit-file))))