(require 'font-lock)
(require 'lisp-mode)
(load-library "inf-lisp")
(load-library "cl-indent")
(transient-mark-mode t)
(show-paren-mode 1)
(defun openlisp-eval-sexp (&optional and-go)
"Send the next sexp to the inferior Lisp process.
Prefix argument means switch to the Lisp buffer afterwards."
(interactive "P")
(lisp-eval-region (point) (scan-sexps (point) 1) and-go))
(defun openlisp-eval-buffer (&optional and-go)
"Evaluate entire buffer."
(interactive "P")
(lisp-eval-region (point-min) (point-max) and-go))
(defun openlisp-macroexpand-region (start end &optional and-go)
"Macroexpand the current region in the inferior Lisp process.
Prefix argument means switch to the Lisp buffer afterwards."
(interactive "r\nP")
(comint-send-string
(inferior-lisp-proc)
(format "(macroexpand-1 (quote %s))\n"
(buffer-substring-no-properties start end)))
(if and-go
(switch-to-lisp t)))
(defun openlisp-macroexpand-sexp (&optional and-go)
"Macroexpand the next sexp in the inferior Lisp process.
Prefix argument means switch to the Lisp buffer afterwards."
(interactive "P")
(openlisp-macroexpand-region (point) (scan-sexps (point) 1) and-go))
(defun openlisp-debug-off (&optional and-go)
"Set debug mode off"
(interactive)
(comint-send-string
(inferior-lisp-proc)
(format "(debug nil)"))
(if and-go
(switch-to-lisp t)))
(defun openlisp-debug-on (&optional and-go)
"Set debug mode on"
(interactive)
(comint-send-string
(inferior-lisp-proc)
(format "(debug t)"))
(if and-go
(switch-to-lisp t)))
(defun openlisp-trace ()
"Trace function"
(interactive)
(let ((fn (read-from-minibuffer "Trace function: ")))
(if (not (zerop (length fn)))
(comint-send-string
(inferior-lisp-proc)
(format "(trace (quote %s))" fn)))))
(defun openlisp-untrace ()
"Untrace function"
(interactive)
(let ((fn (read-from-minibuffer "Untrace function: ")))
(if (not (zerop (length fn)))
(comint-send-string
(inferior-lisp-proc)
(format "(untrace (quote %s))" fn)))))
(defun openlisp-fib (&optional and-go)
"Call (fib 20) using OpenLisp"
(comint-send-string
(inferior-lisp-proc)
(format "(fib 20)\n"))
(if and-go
(switch-to-lisp t)))
(defun openlisp-reindent ()
"Reindent current line and mote to the next one"
(interactive)
(lisp-indent-line)
(forward-line)
(beginning-of-line))
(defun openlisp ()
"Run OpenLisp as inferior-lisp-process"
(interactive)
(setq inferior-lisp-program "c:/usr/bin/lisp -emacs")
(let ((process-connection-type t))
(run-lisp inferior-lisp-program)))
(defun openlisp-unicode ()
"Run OpenLisp as inferior-lisp-process"
(interactive)
(setq inferior-lisp-program "c:/usr/bin/lisp -unicode -utf8 -emacs")
(let ((coding-system-for-read 'utf-8)
(coding-system-for-write 'utf-8)
(coding-system-require-warning t)
(process-connection-type t))
(run-lisp inferior-lisp-program)))
(defun clisp ()
(interactive)
(setq inferior-lisp-program "c:/usr/jullien/clisp-2.47/clisp -I")
(run-lisp inferior-lisp-program))
(defun lisp-compile-file (file-name)
"Compile a Lisp file in the inferior Lisp process."
(interactive (comint-get-source
"Compile Lisp file: "
lisp-prev-l/c-dir/file
lisp-source-modes nil)) (comint-check-source file-name) (setq lisp-prev-l/c-dir/file (cons (file-name-directory file-name)
(file-name-nondirectory file-name)))
(comint-send-string (inferior-lisp-proc)
(concat "(compile-file \"" file-name "\" :cc\)\n"))
(switch-to-lisp t))
(when (fboundp 'global-font-lock-mode)
(setq font-lock-maximum-decoration t)
(global-font-lock-mode t))
(transient-mark-mode t)
(show-paren-mode 1)
(custom-set-faces
'(font-lock-builtin-face ((t (:foreground "Light Steel Blue"))))
'(font-lock-comment-face ((t (:foreground "Green" :italic t))))
'(font-lock-constant-face ((t (:foreground "Orchid"))))
'(font-lock-doc-face ((t (:foreground "Wheat3"))))
'(font-lock-doc-string-face ((t (:foreground "Wheat3"))))
'(font-lock-function-name-face ((t (:foreground "Orange" t))))
'(font-lock-keyword-face ((t (:foreground "Cyan" :bold t))))
'(font-lock-preprocessor-face ((t (:foreground "Wheat" t))))
'(font-lock-reference-face ((t (:foreground "orangered"))))
'(font-lock-string-face ((t (:foreground "Yellow"))))
'(font-lock-type-face ((t (:foreground "Grey" t nil))))
'(font-lock-variable-name-face ((t (:foreground "LightGrey" t))))
'(font-lock-warning-face ((t (:foreground "Red" t))))
'(left-margin ((t (:background "black"))) t))
(custom-set-variables
'(safe-local-variable-values
(quote ((Syntax . ANSI-Common-Lisp)
(Syntax . EmacsLisp)
(Mode . LISP)
(Package . LISP)
(Base . 10)
(Syntax . ISLISP)
(Encoding . utf-8)
(Encoding . utf-16)))))
(setq inferior-lisp-prompt "^[^>? \n]*>+:? *")
(if (eq system-type 'windows-nt)
(setq inferior-lisp-program "c:/usr/bin/lisp -emacs")
(setq inferior-lisp-program "/usr/bin/env openlisp -emacs"))
(defun openlisp-mode-hook ()
"Hook for running OpenLisp file..."
(setq tab-width 8)
(setq indent-tabs-mode nil)
(setq lisp-body-indent 3)
(setq case-fold-search t)
(setq lisp-indent-function 'common-lisp-indent-function)
(set (make-local-variable 'lisp-indent-function)
'common-lisp-indent-function)
(setq lisp-indent-maximum-backtracking 10)
t)
(add-hook 'lisp-mode-hook 'openlisp-mode-hook)
(add-hook 'lisp-interaction-mode-hook 'openlisp-mode-hook)
(defconst lisp-el-font-lock-keywords-1
(eval-when-compile
(list
(list (concat
"(\\(def\\("
"\\(inline\\|alias\\|generic\\|macro\\*?\\|method\\|"
"setf\\|subst\\*?\\|un\\*?\\|"
"ine-\\(condition\\|derived-mode\\|function\\|"
"method-combination\\|setf-expander\\|skeleton\\|widget\\|"
"\\(compiler\\|modify\\|symbol\\)-macro\\)\\)\\|"
"\\(const\\(ant\\)?\\|"
"custom\\|dynamic\\|face\\|global\\|parameter\\|var\\)\\|"
"\\(class\\|group\\|package\\|struct\\|type\\)"
"\\)\\)\\>"
"[ \t'\(]*"
"\\(\\sw+\\)?")
'(1 font-lock-keyword-face)
'(9 (cond
((match-beginning 3) font-lock-function-name-face)
((match-beginning 6) font-lock-variable-name-face)
(t font-lock-type-face))
nil
t))
'("^;;;###\\(autoload\\)\\>" 1 font-lock-warning-face prepend)
))
"Subdued level highlighting for Lisp modes.")
(defconst lisp-el-font-lock-keywords-2
(append lisp-el-font-lock-keywords-1
(eval-when-compile
(list
(cons (concat
"("
(regexp-opt
'(
"and"
"assure"
"block"
"case"
"case-using"
"catch"
"class"
"cond"
"convert"
"defclass"
"defconstant"
"defdynamic"
"defgeneric"
"defglobal"
"defmacro"
"defmethod"
"defun"
"dynamic"
"dynamic-let"
"flet"
"for"
"function"
"go"
"if"
"ignore-errors"
"labels"
"lambda"
"let"
"let*"
"or"
"progn"
"quote"
"return-from"
"setf"
"setq"
"set-dynamic"
"tagbody"
"the"
"throw"
"unwind-protect"
"while"
"with-error-output"
"with-handler"
"with-open-input-file"
"with-open-io-file"
"with-open-output-file"
"with-standard-input"
"with-standard-output"
"prog1"
"psetq"
"unless"
"when"
)
t)
"\\>")
1)
'("\\<\\(t\\|nil\\|&rest\\)\\>" 0 font-lock-keyword-face)
'("(\\(featurep\\|provide\\|require\\)\\>[ \t']*\\(\\sw+\\)?"
(1 font-lock-keyword-face)
(2 font-lock-constant-face nil t))
'("(\\(export\\|import\\|in-package\\|use-package\\)\\>[ \t']*\\(\\sw+\\)?"
(1 font-lock-keyword-face)
(2 font-lock-constant-face nil t))
'("(\\(defstruct\\|defclass\\)\\>[ \t']*\\(\\sw+\\)?"
(1 font-lock-keyword-face)
(2 font-lock-type-face nil t))
'("\\&\\sw+\\>" 0 font-lock-keyword-face)
'("\\<[<]\\sw+[>]\\>" 0 font-lock-type-face)
'("`\\(\\sw\\sw+\\)'" 1 font-lock-reference-face prepend)
'("\\<:\\sw\\sw+\\>" 0 font-lock-builtin-face)
'("\\<[-+]?[0-9]+\\>" 0 font-lock-constant-face)
'("\\<[-+]?[0-9]+\.[0-9]+\\>" 0 font-lock-constant-face)
)))
"Lisp modes.")
(setq auto-mode-alist
(append '(("\\inferior-lisp" . lisp-mode)
("\\.ll\\'" . lisp-mode)
("\\.lm\\'" . lisp-mode)
("\\.lap\\'" . lisp-mode))
auto-mode-alist))
(defvar lisp-el-font-lock-keywords lisp-el-font-lock-keywords-1
"Default expressions to highlight in Lisp modes.")
(eval-after-load "font-lock"
'(setq lisp-el-font-lock-keywords lisp-el-font-lock-keywords-2))
(defmacro defindent (operator indentation)
`(put ',operator 'common-lisp-indent-function ',indentation))
(setq lisp-indent-function 'common-lisp-indent-function)
(setq lisp-body-indent 3)
(defindent and (&rest 6))
(defindent block (7 7))
(defindent case (6 6))
(defindent case-using (6 6))
(defindent catch (7 7))
(defindent cond (6 6))
(defindent do ((&whole nil &rest) (&whole nil &rest 4)))
(defindent do* ((&whole nil &rest) (&whole nil &rest 5)))
(defindent dolist ((&whole 4 1 1) &body))
(defindent dotimes ((&whole 4 1 1) &body))
(defindent dynamic-let ((&whole 9 &rest (&whole 1 2 2)) 9))
(defindent for ((&whole nil &rest) (&whole nil &rest 5)))
(defindent if 4)
(defindent lambda ((&whole 4 1 &rest 1) 3))
(defindent let ((&whole 5 &rest (&whole 1 2 2)) 5))
(defindent let* ((&whole 6 &rest (&whole 1 2 2)) 6))
(defindent or (&rest 4))
(defindent prog1 (7 7))
(defindent progn (7 7))
(defindent tagbody lisp-indent-tagbody)
(defindent unless (8 8))
(defindent until (7 7))
(defindent unwind-protect (8 8))
(defindent when (6 6))
(defindent while (7 7))
(defindent with-client-socket ((&whole 5 1 &rest 1) 5))
(defindent with-error-output ((&whole 5 1 &rest 1) 5))
(defindent with-input-from-string ((&whole 5 1 &rest 1) 5))
(defindent with-open-input-file ((&whole 5 1 &rest 1) 5))
(defindent with-open-input-pipe ((&whole 5 1 &rest 1) 5))
(defindent with-open-io-file ((&whole 5 1 &rest 1) 5))
(defindent with-open-output-file ((&whole 5 1 &rest 1) 5))
(defindent with-output-to-string ((&whole 5 1 &rest 1) 5))
(defindent with-server-socket ((&whole 5 1 &rest 1) 5))
(defindent with-standard-intput ((&whole 5 1 &rest 1) 5))
(defindent with-standard-output ((&whole 5 1 &rest 1) 5))
(define-key lisp-mode-map "\C-x\C-e" 'openlisp-eval-sexp)
(define-key lisp-mode-map "\C-x\C-h" 'openlisp-eval-buffer)
(define-key lisp-mode-map "\C-x\C-m" 'openlisp-macroexpand-sexp)
(define-key lisp-mode-map "\C-x\C-z" 'openlisp)
(define-key lisp-mode-map [return] 'newline-and-indent)
(define-key lisp-mode-map [f4] 'openlisp-reindent)
(define-key lisp-mode-map "\C-c\C-e" 'lisp-eval-defun)
(define-key lisp-mode-map "\C-c\C-r" 'lisp-eval-region)
(define-key lisp-mode-map "\C-c\C-c" 'lisp-compile-defun)
(define-key lisp-mode-map "\C-c\C-z" 'switch-to-lisp)
(define-key lisp-mode-map "\C-c\C-l" 'lisp-load-file)
(define-key lisp-mode-map "\C-c\C-k" 'lisp-compile-file)
(global-set-key [f12] 'openlisp)
(global-set-key "\M-g" 'goto-line)
(define-key inferior-lisp-mode-map "\C-x\C-e" 'openlisp-eval-sexp)
(define-key inferior-lisp-mode-map "\C-x\C-m" 'openlisp-macroexpand-sexp)
(define-key inferior-lisp-mode-map "\C-c\C-l" 'lisp-load-file)
(define-key inferior-lisp-mode-map "\C-c\C-k" 'lisp-compile-file)
(defvar lisp-general-menu-map (make-sparse-keymap "OpenLisp")
"Keymap for main OpenLisp menu")
(define-key inferior-lisp-mode-map [menu-bar openlisp]
(cons "OpenLisp" lisp-general-menu-map))
(define-key inferior-lisp-mode-map [menu-bar openlisp debug-off]
'("Debug Off" . openlisp-debug-off))
(define-key inferior-lisp-mode-map [menu-bar openlisp debug-on]
'("Debug On" . openlisp-debug-on))
(define-key inferior-lisp-mode-map [menu-bar openlisp untrace]
'("Untrace ..." . openlisp-untrace))
(define-key inferior-lisp-mode-map [menu-bar openlisp trace]
'("Trace ..." . openlisp-trace))