;; rep-mode ;; uses the following rep-pipe script in ~/bin: ;; #!/bin/bash ;; exec rep "$0" "$@" ;; !# ;; (let ((text (make-string-output-stream))) ;; (copy-stream standard-input text) ;; (eval (read-from-string ;; (concat "(progn" (get-output-stream-string text) ")")))) (defun rep-eval-buffer () "Evaluate the buffer with rep" (interactive) (shell-command-on-region (point-min) (point-max) "rep-pipe")) ;;(defun rep-eval-buffer () ;; "Evaluate the buffer with rep" ;; (interactive) ;; (save-buffer) ;; (shell-command (concat "rep " (buffer-name)))) (defun rep-compile-buffer () "Compile the buffer with rep" (interactive) (save-buffer) (shell-command (concat "rep compiler -f compile-batch " (buffer-name)))) (defvar rep-font-lock-keywords ;; TODO see regexp-opt.el for an explanation of `eval-when-compile' ;; and research the effects for a bit. (eval-when-compile (list '("(\\(def\\w+\\)\\>\\s-+\\((?\\)\\(\\w+\\)\\>" (1 font-lock-keyword-face) (3 font-lock-function-name-face)) ;; '("(\\(define\\(-\\w+\\)?\\)\\>\\s-+\\\((?\\)\\(\\w+\\)\\>" ;; (1 font-lock-keyword-face) (4 font-lock-function-name-face)) ;; '("(\\(def\\w+\\)\\>\\s-+\\(\\w+\\)" ;; (1 font-lock-keyword-face) (2 font-lock-function-name-face)) (cons (concat "(\\(" (regexp-opt ;; FIXME make a sensible list with keywords indicating: ;; control structure, rep-specific keywords, specials '("case" "cond" "else" "if" "lambda" "let" "letrec" "let*" "do" "and" "or" "progn" "prog1" "while" "when" "unless" "autoload" "catch" "throw" "signal" "eval" "map" "mapcar" "mapc" "dolist" "funcall" "apply" "break" "step" "backtrace" "error" "load" "require" "provide" "open" "export" "access" "declare" "unwind-protect" "condition-case")) "\\)\\>") 1) '("#!\\(optional\\|rest\\|key\\)" (0 font-lock-type-face)) '("#:\\w+" (0 font-lock-type-face))))) (define-derived-mode rep-mode lisp-mode "rep" ;; see font-lock.el for details ;;(put 'rep-mode 'font-lock-defaults 'lisp-mode) ;; the xemacs-way ;; (put 'rep-mode ;; 'font-lock-defaults ;; '(rep-font-lock-keywords ;; nil nil ;; ;; setting for lisp-mode, from font-lock.el: ;; ((?: . "w") (?- . "w") (?* . "w") (?+ . "w") (?. . "w") (?< . "w") ;; (?> . "w") (?= . "w") (?! . "w") (?? . "w") (?$ . "w") (?% . "w") ;; (?_ . "w") (?& . "w") (?~ . "w") (?^ . "w") (?/ . "w")) ;; beginning-of-defun ;; (font-lock-comment-start-regexp . ";"))) (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '((rep-font-lock-keywords) nil nil ((":-*+.<>=!?$%_&~^/" . "w")) beginning-of-defun (font-lock-comment-start-regexp . ";"))) ;; (setq font-lock-defaults '(dsssl-font-lock-keywords ;; nil t (("+-*/.<>=!?$%_&~^:" . "w")) ;; beginning-of-defun ;; (font-lock-comment-start-regexp . ";") ;; (font-lock-mark-block-function . mark-defun))) (define-key rep-mode-map [(control c) (control c)] 'comment-region) (define-key rep-mode-map [(control c) c] 'rep-compile-buffer) (define-key rep-mode-map [(control c) e] 'rep-eval-buffer) (define-key rep-mode-map [(meta return)] 'rep-eval-buffer)) (require 'inf-lisp) (define-derived-mode rep-inferior-mode inferior-lisp-mode "rep-inf" nil ;;(make-local-variable 'inferior-lisp-prompt) ;;(setq inferior-lisp-prompt sawfish-comint-prompt) (setq lisp-describe-sym-command ",de %s\n") (setq lisp-function-doc-command ",de %s\n") (setq lisp-var-doc-command ",de %s\n")) (defun rep () "Run the rep client as an inferior lisp." (interactive) ;; TODO: How to set lisp-*-command variables for this particular ;; instantiation of the inferior lisp buffer? (unless (comint-check-proc "*rep*") (set-buffer (make-comint "rep" "rep")) (rep-inferior-mode)) (setq inferior-lisp-buffer "*rep*") (pop-to-buffer "*rep*"))