This repository has been archived on 2022-12-11. You can view files and clone it, but cannot push or open issues or pull requests.
dot-files/.emacs.d/config/lispy.el

136 lines
5.1 KiB
EmacsLisp

;; (C) Copyright Collin J. Doering 2014
;;
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;;
;; This program 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 General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;; File: lispy.el
;; Author: Collin J. Doering <collin.doering@rekahsoft.ca>
;; Date: Oct 22, 2014
;; Set default lisp program
(setq inferior-lisp-program "/usr/bin/sbcl")
;; Since there is no support for the kawa implementation of scheme
(defun run-kawa ()
"Run Kawa Scheme in an Emacs buffer."
(interactive)
(require 'cmuscheme) ;; Built-in
(let ((scheme-program-name "/usr/bin/kawa"))
(run-scheme scheme-program-name)))
;; Set usable lisp implementations
(setq slime-lisp-implementations
'((sbcl ("/usr/bin/sbcl" ""))
(clisp ("/usr/bin/clisp" "-K base"))
(clojure ("/usr/bin/clj" ""))))
;; Function to start and/or connect to slime
(defun start-slime ()
(interactive)
(unless (slime-connected-p)
(save-excursion (slime))))
;; Setup slime mode *TODO* drop in slime from ELPA
(add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/")
(require 'slime) ;; AUR: emacs-slime-cvs
(slime-setup '(slime-fancy))
;; Setup swank-clojure-mode
(add-to-list 'load-path "/usr/share/emacs/site-lisp/swank-clojure")
(require 'swank-clojure) ;; ELPA
(add-hook 'clojure-mode-hook
'(lambda ()
(define-key clojure-mode-map "\C-c\C-e" 'lisp-eval-last-sexp)
(define-key clojure-mode-map "\C-x\C-e" 'lisp-eval-last-sexp)))
;; TODO: functionality needs to be re-written; assoc library obsolete
;; (eval-after-load "slime"
;; `(progn
;; (require 'assoc) ;; Built-in (OBSOLETE)
;; (setq swank-clojure-classpath
;; (list "/usr/share/clojure/clojure.jar"
;; "/usr/share/clojure/clojure-contrib.jar"
;; "/usr/share/emacs/site-lisp/swank-clojure/src"))
;; (aput 'slime-lisp-implementations 'clojure
;; (list (swank-clojure-cmd) :init 'swank-clojure-init))))
;; Setup enhanced scheme/racket mode consisting of geiser, quack and paredit
;; Setup geiser
(require 'geiser) ;; ELPA
;; Setup auto-completion for geiser (ELPA)
(require 'ac-geiser)
(add-hook 'geiser-mode-hook 'ac-geiser-setup)
(add-hook 'geiser-repl-mode-hook 'ac-geiser-setup)
(eval-after-load "auto-complete"
'(add-to-list 'ac-modes 'geiser-repl-mode))
;; Make struct stand out in scheme-mode for racket
(defun racket-faces ()
(font-lock-add-keywords nil
'(("(struct \\(\\sw+\\)" 1 font-lock-function-name-face)
("(\\(struct\\)" 1 font-lock-keyword-face)
("(\\\\)" 1 font-lock-function-name-face))))
(add-hook 'scheme-mode-hook 'racket-faces)
(add-hook 'geiser-repl-mode-hook 'racket-faces)
;; Setup scribble mode (custom .el from ~/.emacs.d/site-lisp-extra)
;; See: http://www.neilvandyke.org/scribble-emacs/
(require 'scribble)
;; Setup quack
(require 'quack) ;; ELPA
;; Setup paredit
(require 'paredit) ;; ELPA
(defvar lispy-langs-hooks '(lisp-mode-hook lisp-interaction-mode-hook emacs-lisp-mode-hook scheme-mode-hook c-mode-hook c++-mode-hook python-mode-hook geiser-repl-mode-hook))
;; Apply paredit-mode to modes listed in lispy-langs-hooks
(activate-mode-with-hooks (lambda () (paredit-mode 1)) lispy-langs-hooks)
;; Highlight sexp's in lispy languages
(activate-mode-with-hooks (lambda () (highlight-sexp-mode)) lispy-langs-hooks)
;; Paredit binds to C-j globally and thus disables the binding to
;; eval-print-last-sexp in emacs-lisp-mode (e.g *scratch*, etc..)
(add-hook 'emacs-lisp-mode-hook
'(lambda ()
(define-key emacs-lisp-mode-map "\C-xj" 'eval-print-last-sexp)))
;; Match paren's in given modes [to apply globally do (show-paren-mode 1)]
(activate-mode-with-hooks (lambda () (show-paren-mode)) lispy-langs-hooks)
;; Highlight paren's near point
(require 'highlight-parentheses)
(activate-mode-with-hooks (lambda () (highlight-parentheses-mode)) lispy-langs-hooks)
;; Setup rainbow-delimiters
(require 'rainbow-delimiters) ;; ELPA
(activate-mode-with-hooks 'rainbow-delimiters-mode-enable lispy-langs-hooks)
;;(global-rainbow-delimiters-mode) ;; breaks font coloring in erc for some reason?
;; upcomming functionallity: toggle paredit-mode due to annoying things like wrapping parens when a mistake is made
;; known issue..if paredit-mode is turned on when there are unbalanced parens an error is reported
(defun toggle-paredit-mode ()
(let ((active-minor-modes (list)))
(mapatoms (lambda (sym)
(when (and (symbolp sym) (assq sym minor-mode-alist) (symbol-value sym))
(push sym active-minor-modes))))
(if (member 'paredit-mode active-minor-modes) (paredit-mode -1) (paredit-mode 1))))
(setq geiser-repl-use-other-window nil)
(setq geiser-active-implementations '(racket guile))