Wednesday, February 23, 2011

Lisp on Windows

Here is the description of the easiest (from my point of view) way of using Common Lisp on Windows, current version.


Unfortunately, it is impossible just to install everything, some additional tricks are necessary.

Here is the recipe:
  1. Install LispCabinet, SBCL version. I use "portable" installation. The only difference from usual one is that "portable" version does not use registry and does not use environment variables (I hope. I did not check!).
  2. Download the auto-indent-mode.el into LispCabinet\cabinet\site\.emacs.d\
    Well, I am not 100% sure in the path, but I hope it is right. Anyway, place the file in the folder where Emacs can find it.
  3. Add the following code into asdf-init.lisp (please find the file yourself. And sorry for absolute paths):
    (format t "-------------------------------- START --------------------------------~%")
    
     (defvar *lisp-dirs* "d:/Paul.revised/git.repos/github/")
    
    (dolist (dir-candidate (directory (concatenate 'string *lisp-dirs* "*/")))
      (let ((asd-candidate (merge-pathnames "*.asd" dir-candidate)))
        (when (and (directory dir-candidate)
                   (not (member (namestring dir-candidate)
                                (mapcar #'(lambda (x)
                                                  (when (pathnamep x)
                                                  (namestring x)))
                                        asdf:*central-registry*)
                                :test #'equal)))
              (progn
                  (format t "PUSHED directory: ~a~%" dir-candidate)
                  (pushnew dir-candidate asdf:*central-registry*)))))
    
    (format t "--------------------------------- END ---------------------------------~%")
  4. Here is .emacs file. Use it as it is or take any part of it. Before using it please execute "M-x package-list-packages" and install at least paren-mode and highlight-parentheses-mode:
    ;; A lot of settings are taken from the site http://rigidus.ru/articles
    
    
    (custom-set-variables
     ;; custom-set-variables was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     '(column-number-mode t)
     '(glasses-face (quote default))
     '(hl-paren-colors (quote ("MediumSpringGreen" "red1"
                               "DodgerBlue" "yellow1" "magenta"
                               "orange1" "orange4")))
     '(indent-tabs-mode nil)
     '(scroll-bar-mode nil))
    
    (custom-set-faces
     ;; custom-set-faces was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     '(hl-paren-face ((t (:foreground "gray35"))) t))
    
    (defface paren-face
      '((((class color) (background dark))
         (:foreground "grey35"))
        (((class color) (background light))
         (:foreground "grey80")))
      "Face used to dim parentheses.")
    
    (defun parenhook ()
      (font-lock-add-keywords nil '(("(\\|)" . 'paren-face))))
    
    (add-hook 'emacs-lisp-mode-hook
        (lambda () (paredit-mode +1)))
    (add-hook 'lisp-mode-hook
        (lambda () (paredit-mode +1)))
    (add-hook 'lisp-interaction-mode-hook
        (lambda () (paredit-mode +1)))
    
    (add-hook 'emacs-lisp-mode-hook #'parenhook)
    (add-hook 'lisp-mode-hook #'parenhook)
    (add-hook 'slime-lisp-mode-hook #'parenhook)
    (add-hook 'inferior-lisp-mode-hook #'parenhook)
    
    (require 'highlight-parentheses)
    (add-hook 'lisp-mode-hook (highlight-parentheses-mode))
    (define-globalized-minor-mode global-highlight-parentheses-mode
      highlight-parentheses-mode highlight-parentheses-mode)
    
    (global-highlight-parentheses-mode)
    
    (autoload 'paredit-mode "paredit"
      "Minor mode for pseudo-structurally editing Lisp code." t)
    ;; Comment function
    (defun comment-or-uncomment-this (&optional lines)
      (interactive "P")
      (if mark-active
          (if (< (mark) (point))
              (comment-or-uncomment-region (mark) (point))
            (comment-or-uncomment-region (point) (mark)))
        (comment-or-uncomment-region
         (line-beginning-position)
         (line-end-position lines))))
    
    (global-set-key (kbd "C-;") 'comment-or-uncomment-this)
    
    (defun save-point-and-switch ()
      "Save current point to register 0 and go
    to the previously saved position"
      (interactive)
      (let (temp)
        (setq temp (point-marker))
        (when (not (equal (get-register 0) nil))
          (jump-to-register 0))
        (set-register 0 temp)))
    
    (global-set-key (kbd "\e\e/") 'save-point-and-switch)
    (global-set-key (kbd "\e\e?") 'save-point-only)
    
    (color-theme-zenburn)
    
    (require 'auto-complete-config)
    (ac-config-default)
    
    (setq auto-indent-on-visit-file t)
    (require 'auto-indent-mode)
    (auto-indent-global-mode)
    
  5. Download Quicklisp and follow instructions. It just works. Somehow...

My Blog List