Answer: Emacs and Slime startup script

in emacs •  7 years ago  (edited)

Question:
https://stackoverflow.com/questions/50141371/

Cannot answer on Stack Overflow:

Stack Overflow requires external JavaScript from another domain, which is blocked or failed to load.

Alternatively I give an answer here, hope it works for you:

(defun emacs-and-slime-startup-script (directory package)
  "https://stackoverflow.com/questions/50141371/"
  (interactive
   (list (read-directory-name "Directory:")
         (read-string "Package:")))
  (let ((package (cond ((null package)
                        (error "Require a package."))
                       (t (let ((package (car
                                          (read-from-string package))))
                            (cl-typecase package
                              (keyword package)
                              (symbol (car
                                       (read-from-string
                                        (format ":%s" package))))))))))
    ;; M-x slime to start Slime
    (cl-case (length slime-net-processes)
      (0 (slime))
      (1 nil)
      (t (error "Too many SLIME connections.")))
    (when (zerop (length slime-net-processes))
      (loop
       (if (>= (length slime-net-processes) 1)
           (return
            (message "SLIME succeed loaded."))
         (sleep-for 1))))
    ;; (ql:quickload 'myproject)
    (slime-eval-with-transcript
     `(swank:interactive-eval-region
       ,(format "%S"
                `(unless (find-package ,package)
                   (ql:quickload ,package)))))
    (loop
     (if (cl-member (upcase (subseq (format "%s" package)
                                    1))
                    (slime-eval
                     `(swank:list-all-package-names t))
                    :test (function equal))
         (return
          (message "Package %s succeed loaded." package))
       (sleep-for 1)))
    ;; +p myproject to switch the current package in the repl
    (slime-repl-set-package package)
    (slime-repl)
    ;; M-x cd to a working directory
    (cd directory)
    (slime-cd directory)))
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!