gdl.el 13.1 KB
Newer Older
1
;;;; -*- coding: utf-8 -*-
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
;;                              GDL.EL
;;
;; 1.  INTRODUCTION
;;
;; The purpose of this document is to configure emacs to load SLIME
;; and start an inferior lisp process which will itself load and run
;; the GENDL development environment.
;;
;; The intended readership is users and project developers.
;;
;; This document is not confidential. See end for copyright
;; information.

(require 'cl)


Dave Cooper's avatar
Dave Cooper committed
18 19
(defvar *default-font-size* 15)

Dave Cooper's avatar
Dave Cooper committed
20 21 22 23 24 25 26 27 28 29 30
(defun maximize-frame ()
  "Maximizes the active frame in Windows"
  (interactive)
  ;; Send a `WM_SYSCOMMAND' message to the active frame with the
  ;; `SC_MAXIMIZE' parameter.
  (when (eq system-type 'windows-nt) (w32-send-sys-command 61488))
  (unless (eq system-type 'windows-nt) (set-frame-parameter nil 'fullscreen 'maximized)))

(add-hook 'window-setup-hook 'maximize-frame t)


31 32
;; 2. WHERE ARE WE?

33 34
(defvar *gendl-home* (file-truename (concat (file-name-directory 
					     (file-truename load-file-name)) "../")))
35 36


Dave Cooper's avatar
Dave Cooper committed
37
;; 3. CONFIGURE EMACS
38 39 40 41 42 43 44 45 46
;;
;; This section is not SLIME-specific.
;;
;; 3.1 Flags, for commenting in or out.

;; FLAG -- comment the following if you want a tool bar.
;;         (errors ignored in case running in a console terminal)
(ignore-errors (tool-bar-mode -1))

47
;;(setq visible-bell t)
48 49 50 51 52 53 54 55

;; FLAG -- uncomment the following if you don't need a menu bar.
;;         (errors ignored in case running in a console terminal)
;;
;;(ignore-errors (menu-bar-mode -1))


;; 3.2. Set up color-theme and solarized color-themes
56 57
;;(setq calendar-latitude 42.58 calendar-longitude -83.3 calendar-location-name "Detroit")
;;(setq sunrise-sunset (sunrise-sunset))
58
;; FLAG -- figure out how to use this information with (current-time) to pick a light or dark color-theme. 
59
(add-to-list 'load-path (concat *gendl-home* "emacs/emacs-color-theme")) 
60 61
(require 'color-theme)
(color-theme-initialize)
62
;;(color-theme-subtle-hacker)
63
;;(color-theme-high-contrast)
64
;;(color-theme-taming-mr-arneson)
65
(color-theme-sitaramv-solaris)
66
;;(color-theme-feng-shui)
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
;; 3.3. Indents

(defmacro defindent (name indentation)
  (let* ((keyword-list '(lisp-font-lock-keywords t t t nil nil nil "&allow-other-keys"))
         (spec (if (eq indentation 'gdl-object-style) `((1 t ,keyword-list) (0 t 2)) indentation)))
    `(put ',name 'lisp-indent-hook ',spec)))

(defun gdl:define-indents ()
  (defindent define-object gdl-object-style)
  (defindent define-view (like define-object))
  (defindent define-format (like define-object))
  (defindent defpart (like define-object))
  (defindent defwriter (like define-object))
  (defindent defcompanion (like define-object)))

(gdl:define-indents)

;; 3.4. Some handy global keybindings

(defun gdl:global-keys ()
  (global-set-key "\M-p" 'fi:pop-input)
  (global-set-key "\M-n" 'fi:push-input)
  (global-set-key "\C-xy" '(lambda() (interactive) (other-window -1)))
  ;;
  ;; Use C-j for newline-and-indent. If you really like it, you can bind
  ;; it to [Enter] by uncommenting the following line (from
  ;; http://emacswiki.org/emacs/AutoIndentation).
  ;;
  ;;(global-set-key (kbd "C-m") 'newline-and-indent)
Dave Cooper's avatar
Dave Cooper committed
98
  )
Dave Cooper's avatar
Dave Cooper committed
99

100 101 102 103 104 105
(gdl:global-keys)

;; 3.5. Font

(defun gdl:set-font ()
  (interactive)
Dave Cooper's avatar
Dave Cooper committed
106
  (let ((font-size *default-font-size*)) ;; (/ (display-mm-height) 16)
107 108 109
    (set-frame-font
     (format 
      (case system-type
110 111
	(darwin  "-*-Courier New-normal-normal-normal-*-%s-*-*-*-m-0-iso10646-1" ;; -apple-Courier_New-medium-normal-normal-*-%s-*-*-*-m-0-iso10646-1"
		 )
112 113
	;;(windows-nt "-outline-Courier New-normal-normal-normal-mono-%s-*-*-*-c-*-iso8859-1")
	(windows-nt "-outline-Consolas-normal-r-normal-normal-14-97-96-96-c-*-utf8")
114 115
	(gnu/linux "-bitstream-Courier 10 Pitch-normal-normal-normal-*-%s-*-*-*-m-0-iso10646-1"))
      font-size))))
116

Dave Cooper's avatar
Dave Cooper committed
117
(ignore-errors (gdl:set-font))
118

119

120 121 122 123
;; 3.6. Miscellania

(show-paren-mode t)

124

125 126 127 128 129 130 131 132 133 134
;; Use M-x clear-kill-ring in case you have too much garbage in the
;; kill ring
;;
(defun clear-kill-ring () (interactive) (setq kill-ring nil))


;; 4.  SLIME SETUP
;;
;; 4.1. Some synonyms

Dave Cooper's avatar
Dave Cooper committed
135
(defun gendl (&optional exe) (interactive) 
Dave Cooper's avatar
Dave Cooper committed
136
  (add-hook 'slime-connected-hook 'load-and-or-start-gendl t)
Dave Cooper's avatar
Dave Cooper committed
137 138 139
  (add-to-list 'auto-mode-alist '("\\.cl\\'" . lisp-mode))
  (add-to-list 'auto-mode-alist '("\\.gdl\\'" . lisp-mode))
  (add-to-list 'auto-mode-alist '("\\.gendl\\'" . lisp-mode))
Dave Cooper's avatar
Dave Cooper committed
140 141 142 143
  (with-temp-buffer (cd *gendl-home*) (slime exe)))

(defun gdl () (interactive) (gendl 'gdl))
(defun agdl8 () (interactive) (gendl 'agdl8))
Dave Cooper's avatar
Dave Cooper committed
144
(defun agdl () (interactive) (gendl 'agdl))
145
(defun glime () (interactive) (gendl))
146 147 148 149

(defun gdl-quit () (interactive) (slime-quit-lisp))
(defun gq () (interactive) (gdl-quit))
(defun gendl-quit () (interactive) (gdl-quit))
Dave Cooper's avatar
Dave Cooper committed
150 151 152
(defun quit-gendl () (interactive) (gdl-quit))
(defun quit-gdl () (interactive) (gdl-quit))

153 154


155
;; 4.2. Locate Common Lisp / Locate SLIME
156 157
;;
;; Where is our Common Lisp implementation? Where is slime-helper.el?
Dave Cooper's avatar
Dave Cooper committed
158 159 160 161
;;
;; If you don't have slime loaded yet, and/or you don't have 
;; slime-lisp-implementations set, then please make a file
;; .configure-glime.el in your home directory which sets
162
;; correct slime-lisp-implementations and quicklisp-slime-helper
Dave Cooper's avatar
Dave Cooper committed
163
;;
164 165
;; Loading the latter means we can load slime-autoloads.el (which
;; enables SLIME itself).
Dave Cooper's avatar
Dave Cooper committed
166 167
;;
;;
168 169

(defun configure-slime ()
170
  (setq quicklisp-slime-helper nil)
Dave Cooper's avatar
Dave Cooper committed
171 172 173 174 175 176 177 178
  (let ((built-in-config (concat *gendl-home* "emacs/configure-glime.el"))
	(home-config "~/.configure-glime.el"))
    (let ((config-file (if (file-exists-p built-in-config) built-in-config home-config)))
      (when (file-exists-p config-file) (load-file config-file))
      ;;
      ;; path-to-quicklisp-helper should have been set by config-file,
      ;; or slime must already be set up.
      ;;
179
      (when (file-exists-p quicklisp-slime-helper)
Dave Cooper's avatar
Dave Cooper committed
180
	(load-file quicklisp-slime-helper)))))
181

182 183 184 185 186 187 188 189 190

(configure-slime)
(require 'slime-autoloads)


;; 4.3. Configure SLIME

(eval-after-load "slime"
  '(progn
191
    (slime-setup '(slime-fancy slime-banner slime-tramp))
192
    (add-hook 'slime-connected-hook 'set-slime-shortcuts)
193
    (add-hook 'slime-connected-hook 'customise-slime)
194
    (add-hook 'slime-repl-mode-hook 'remove-dos-eol)
Dave Cooper's avatar
Dave Cooper committed
195
    (add-hook 'slime-connected-hook 'load-user-emacs-glime)))
196

Dave Cooper's avatar
Dave Cooper committed
197 198 199 200 201 202 203


(defun load-base-ql ()
  (slime-repl)
  (insert "(load (merge-pathnames \".load-base-ql.lisp\" (user-homedir-pathname)))")
  (slime-repl-return))

204
(defvar gdl-startup-string nil)
Dave Cooper's avatar
Dave Cooper committed
205

206

207
(setq gdl-startup-string 
Dave Cooper's avatar
Dave Cooper committed
208 209
  (format 
   "(progn (unless (find-package :gendl)
210
	    (let ((load-file (probe-file (merge-pathnames \".load-gendl.lisp\" (user-homedir-pathname)))))
Dave Cooper's avatar
Dave Cooper committed
211
	      (load load-file)))
212

Dave Cooper's avatar
Dave Cooper committed
213
	  (let ((gendl-loaded? (find-package :gendl)) (genworks-gdl-loaded? (find-package :genworks-gdl)))
214 215
            (when (or gendl-loaded? genworks-gdl-loaded?)
              (funcall (symbol-function (read-from-string \"uiop:setup-temporary-directory\"))))
216
	    (cond (genworks-gdl-loaded? (funcall (symbol-function (read-from-string \"gdl:start-gdl!\"))))
217 218
		  (gendl-loaded? (funcall (symbol-function (read-from-string \"gendl:start-gendl!\"))))
		  (t (format t  \"~%%~%%***~%%Gendl or GDL is not loaded and did not load successfully 
219
  from .load-gendl.lisp in your home directory.~%%***~%%~%%\"))))
220 221
	  (when (find-package :gendl) (in-package :gdl-user))
         (when (find-package :gwl) (funcall (read-from-string \"gwl:announce-server-port\"))))" *gendl-home*))
Dave Cooper's avatar
Dave Cooper committed
222 223


224 225 226 227 228
;;
;; DAP -- user can also setq this in ~/.emacs-gdl
;;
(defvar user-startup-string "")

Dave Cooper's avatar
Dave Cooper committed
229
(defun load-and-or-start-gendl ()
230
  (setq slime-enable-evaluate-in-emacs t)
231
  (slime-repl)
Dave Cooper's avatar
Dave Cooper committed
232
  (insert gdl-startup-string)
233
  (slime-repl-return)
234 235 236 237 238 239 240 241 242
  (end-of-buffer)

  ;;
  ;; DAP  -- Added to support user-startup-string
  ;;
  (slime-repl-return)
  (insert user-startup-string)
  (slime-repl-return)
  )
243

Dave Cooper's avatar
Dave Cooper committed
244 245


246 247 248 249 250 251
(defun set-slime-shortcuts ()
  "Set keybindings for switching to slime buffers"
  (interactive)
  (global-set-key "\C-x&" '(lambda()(interactive) (switch-to-buffer (slime-repl-buffer))))
  (global-set-key "\C-x*" '(lambda()(interactive) (switch-to-buffer "*inferior-lisp*"))))

252 253 254
(defun customise-slime ()
  (setq slime-autodoc-use-multiline-p t))

255 256 257 258 259 260 261 262 263
(defun remove-dos-eol ()
  "Do not show ^M in files containing mixed UNIX and DOS line endings."
  (interactive)
  (setq buffer-display-table (make-display-table))
  (aset buffer-display-table ?\^M []))


;; 4.4. Prior to SLIME

Dave Cooper's avatar
Dave Cooper committed
264 265


Dave Cooper's avatar
Dave Cooper committed
266
(defun prior-to-glime ()
267
  (find-file (concat *gendl-home* "emacs/README.txt"))
268
  (toggle-read-only)
269
  (let ((frame-title "Genworks® GDL Interactive Authoring Environment"))
270
    (modify-frame-parameters nil (list (cons 'name frame-title))))
271
  (setq inhibit-splash-screen t)
Dave Cooper's avatar
Dave Cooper committed
272 273
  (cd "~/"))

274

Dave Cooper's avatar
Dave Cooper committed
275
(defun load-user-emacs-glime ()
276 277 278 279 280 281 282 283 284
  (dolist (file (list "~/.emacs-glime" "~/.emacs-glime.el"))
    (when (file-exists-p file) (load-file file))))

(defun load-user-emacs-gendl ()
  (dolist (file (list "~/.emacs-gendl" "~/.emacs-gdl" 
		      "~/.emacs-gendl.el" "~/.emacs-gdl.el"))
    (when (file-exists-p file) (load-file file))))


Dave Cooper's avatar
Dave Cooper committed
285

286

287 288 289 290 291 292 293
(ignore-errors 
  (require 'package)
  ;; Add the original Emacs Lisp Package Archive
  (add-to-list 'package-archives
	       '("elpa" . "http://tromey.com/elpa/"))
  ;; Add the user-contributed repository
  (add-to-list 'package-archives
294 295 296 297 298 299
	       '("marmalade" . "http://marmalade-repo.org/packages/"))

  (add-to-list 'package-archives
	       '("melpa" . "http://melpa.milkbox.net/packages/") t)
  
  )
300 301


302 303
;; 5.  MAKE IT HAPPEN

Dave Cooper's avatar
Dave Cooper committed
304
(prior-to-glime)
Dave Cooper's avatar
Dave Cooper committed
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334

;;
;; FLAG -- conditionalize based on running slime or ELI
;;
;;(glime)

(defvar *eli-init* (concat *gendl-home* "program/eli/fi-site-init.el"))


(when (file-exists-p *eli-init*)

  (defun get-executable (exe-name)

      (let* ((info (assoc exe-name slime-lisp-implementations )))
	(replace-regexp-in-string 
	 "/program/program/" "/program/"
	 (case system-type 
	   (windows-nt
	    (concat (file-name-directory (first (second info)))
		    (replace-regexp-in-string "\\\\" "/" (second (second info)))))
	   ((darwin gnu/linux)
	    (first (second info)))))))


  (defvar gdl:*gdl-toplevel-base* "*gdl toplevel*")


  (defun agdl8e () (interactive)
    (gdl-devo (get-executable 'agdl8)))

335 336 337
  (defun agdle () (interactive)
     (gdl-devo (get-executable 'agdl)))
  
Dave Cooper's avatar
Dave Cooper committed
338
  (defun gdle () (interactive)
339
    (gdl-devo (get-executable 'gdl)))
Dave Cooper's avatar
Dave Cooper committed
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359

  (defun gdl-devo (executable) 
    (interactive)
    (load-file *eli-init*)
	  
    (setq gdl:*gdl-toplevel* 
	  (concat gdl:*gdl-toplevel-base*
		  (if (equalp (subseq (file-name-sans-extension (file-name-nondirectory executable))
				      0 1) "a")
		      "(ANSI)" "(modern)")))
    (fi:common-lisp gdl:*gdl-toplevel* *gendl-home* executable nil)


    (global-set-key "\C-x&" '(lambda()(interactive) (switch-to-buffer gdl:*gdl-toplevel*)))

    (switch-to-buffer gdl:*gdl-toplevel*)
    (end-of-buffer)
    (goto-char (point-max))
    (insert gdl-startup-string)
    (fi:inferior-lisp-newline)
360 361 362 363 364 365 366 367 368 369
    (end-of-buffer)


    ;;
    ;; DAP - Added to support user-startup-string
    ;;
    (end-of-buffer)
    (goto-char (point-max))
    (insert user-startup-string)
    (fi:inferior-lisp-newline)
Dave Cooper's avatar
Dave Cooper committed
370
    (end-of-buffer)))
371

372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

(defun timestamp ()
  (insert (format-time-string "%Y-%m-%dT%H:%M:%S" (current-time))))

;;
;; See http://pomodorotechnique.com/
;;
(defun pomodoro ()
  (timestamp)
  (insert (format-time-string ";%Y-%m-%dT%H:%M:%S;" 
			      (time-add (current-time) (seconds-to-time (* 25 60))))))
(global-set-key "\C-t" '(lambda() (interactive) (pomodoro)))

(defun post-pomodoro ()
  (insert (format-time-string "%Y-%m-%dT%H:%M:%S" 
			      (time-subtract (current-time) (seconds-to-time (* 25 60)))))
  (insert (format-time-string ";%Y-%m-%dT%H:%M:%S;" (current-time))))

(global-set-key "\M-t" '(lambda() (interactive) (post-pomodoro)))



Dave Cooper's avatar
Dave Cooper committed
394
;;
395
;; Establish input method for I.A.S.T diacritics
Dave Cooper's avatar
Dave Cooper committed
396
;;
397 398 399 400 401 402 403
(let ((file (concat *gendl-home* "emacs/sa-translit.el"))) 
  (when (file-exists-p file)
    (load-file file)
    (register-input-method
     "sa-translit" "Sanskrit Transliteration" 'quail-use-package
     "sa-translit" "Converts Harvard-Kyoto and ITRANS scheme to IAST diacritics."
     file)))
Dave Cooper's avatar
Dave Cooper committed
404

405
(maximize-frame)
Dave Cooper's avatar
Dave Cooper committed
406

407
(load-user-emacs-gendl)
408

409 410


411 412 413 414 415 416 417 418 419 420 421 422 423 424 425

;;(defun mac-switch-meta nil 
;;  "switch meta between Option and Command"
;;  (interactive)
;;  (if (eq mac-option-modifier nil)
;;      (progn
;;	(setq mac-option-modifier 'meta)
;;	(setq mac-command-modifier 'control))
;;    (progn 
;;      (setq mac-option-modifier nil)
;;      (setq mac-command-modifier 'meta))))

(defun mac-switch-meta nil
  "make option key behave as meta"
  (setq mac-option-modifier 'meta))
426

427 428
(when (eql system-type 'darwin)
  (mac-switch-meta))
429 430


431

432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459
;; A.  REFERENCES
;;
;;
;; B.  HISTORY
;;
;;
;; C.  COPYRIGHT
;;
;; Copyright 2013 Genworks International
;;
;; This source file is part of the General-purpose Declarative
;; Language project (GDL).
;;
;; This source file contains free software: you can redistribute it
;; and/or modify it under the terms of the GNU Affero General Public
;; License as published by the Free Software Foundation, either
;; version 3 of the License, or (at your option) any later version.
;;
;; This source file 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
;; Affero General Public License for more details.
;;
;; You should have received a copy of the GNU Affero General Public
;; License along with this source file.  If not, see
;; <http://www.gnu.org/licenses/>.