Skip to content

Commit

Permalink
whitespace cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
3b committed Apr 4, 2012
1 parent 74f51df commit 9371b0e
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 75 deletions.
18 changes: 9 additions & 9 deletions slime-proxy.el
Expand Up @@ -27,7 +27,7 @@
;; FIXME: use a per-buffer variable instead of a per-connection variable ;; FIXME: use a per-buffer variable instead of a per-connection variable
(let* ((slime-dispatching-connection (slime-proxy-connection))) (let* ((slime-dispatching-connection (slime-proxy-connection)))
(slime-connection-proxy-output-buffer))) (slime-connection-proxy-output-buffer)))



(defun slime-proxy-connection () (defun slime-proxy-connection ()
"Returns the most relevant proxy connection." "Returns the most relevant proxy connection."
Expand Down Expand Up @@ -66,7 +66,7 @@ launch a REPL for the proxy."
;; now create the swank-side proxy listener ;; now create the swank-side proxy listener
(slime-eval-async (slime-eval-async
`(swank:create-proxy-listener ,(slime-channel.id channel) ,target) `(swank:create-proxy-listener ,(slime-channel.id channel) ,target)
(slime-rcurry (slime-rcurry
(lambda (result channel) (lambda (result channel)
(let ((slime-dispatching-connection (slime-connection))) (let ((slime-dispatching-connection (slime-connection)))
(destructuring-bind (remote thread-id package prompt) result (destructuring-bind (remote thread-id package prompt) result
Expand Down Expand Up @@ -122,7 +122,7 @@ launch a REPL for the proxy."
(slime-send `(:emacs-channel-send (slime-send `(:emacs-channel-send
,slime-proxy-most-recent-channel-id ,slime-proxy-most-recent-channel-id
(:proxy (:emacs-rex ,form ,package ,thread ,id))) ) (:proxy (:emacs-rex ,form ,package ,thread ,id))) )

;; wrap the continuation to execute in the proxy's environment ;; wrap the continuation to execute in the proxy's environment
(lexical-let* ((original continuation) (lexical-let* ((original continuation)
(wrapped (lambda (result) (wrapped (lambda (result)
Expand All @@ -131,17 +131,17 @@ launch a REPL for the proxy."
(funcall original result)))))) (funcall original result))))))
(push (cons id wrapped) (push (cons id wrapped)
(slime-rex-continuations))) (slime-rex-continuations)))
;(message "adjusted continuations (added %i for %s): %s" ;(message "adjusted continuations (added %i for %s): %s"
; id (slime-connection) (mapcar 'car (slime-rex-continuations))) ; id (slime-connection) (mapcar 'car (slime-rex-continuations)))
(slime-recompute-modelines))) (slime-recompute-modelines)))
((:buffer-first-change) ((:buffer-first-change)
nil) nil)
((:operator-arglist ) ((:operator-arglist )
(message "slime-proxy ignorning slime: %s" event) (message "slime-proxy ignorning slime: %s" event)
nil) nil)
;;; fixme dont have proxy-event caught in two places. Use ;;; fixme dont have proxy-event caught in two places. Use
;;; only the one below, and get rid of the if/else separating ;;; only the one below, and get rid of the if/else separating
;;; these. ;;; these.
((:proxy-event wrapped-event package prompt-string) ((:proxy-event wrapped-event package prompt-string)
(case wrapped-event (case wrapped-event
(:new-package (:new-package
Expand Down Expand Up @@ -198,14 +198,14 @@ launch a REPL for the proxy."


(defun slime-show-arglist-ps () (defun slime-show-arglist-ps ()
(let ((op (slime-operator/form-before-point))) (let ((op (slime-operator/form-before-point)))
(when op (when op
(slime-eval-async `(swank:operator-arglist ,op ,(slime-current-package)) (slime-eval-async `(swank:operator-arglist ,op ,(slime-current-package))
(lambda (arglist) (lambda (arglist)
(when arglist (when arglist
(slime-message "%s" arglist))))))) (slime-message "%s" arglist)))))))


(defun slime-operator/form-before-point () (defun slime-operator/form-before-point ()
(ignore-errors (ignore-errors
(save-excursion (save-excursion
(backward-up-list 1) (backward-up-list 1)
(down-list 1) (down-list 1)
Expand Down
38 changes: 19 additions & 19 deletions swank-proxy-implementation.lisp
Expand Up @@ -37,11 +37,11 @@ evaluated by PROXY-EVAL-FOR-EMACS."))
;; by default, simply call the continuation and return :async ;; by default, simply call the continuation and return :async
(format t "unknown proxy-eval command ~s or proxy target ~s~%" (cons op args) proxy-target) (format t "unknown proxy-eval command ~s or proxy target ~s~%" (cons op args) proxy-target)
#++(when cont #++(when cont
(funcall cont nil nil)) (funcall cont nil nil))
:async :async
#+nil #+nil
:pass :pass
(format nil "unknown proxy-eval command ~s or proxy target ~s~%" op proxy-target)) (format nil "unknown proxy-eval command ~s or proxy target ~s~%" op proxy-target))


(defmacro define-proxy-fun (name target (&rest args) &body body) (defmacro define-proxy-fun (name target (&rest args) &body body)
"Defines a method for proxy-eval with NAME and TARGET as eql "Defines a method for proxy-eval with NAME and TARGET as eql
Expand All @@ -52,8 +52,8 @@ lambda-list to destructure whatever remaining parameters are passed to
proxy-eval. " proxy-eval. "
(let ((rest (gensym))) (let ((rest (gensym)))
`(defmethod proxy-eval ((op (eql ',name)) (target (eql ',target)) continuation &rest ,rest) `(defmethod proxy-eval ((op (eql ',name)) (target (eql ',target)) continuation &rest ,rest)
(destructuring-bind (,args) ,rest (destructuring-bind (,args) ,rest
,@body)))) ,@body))))


(defgeneric proxy-eval-form (form target continuation) (defgeneric proxy-eval-form (form target continuation)
(:documentation "")) (:documentation ""))
Expand Down Expand Up @@ -89,7 +89,7 @@ form, uses PROXY-EVAL-FORM"
;; fixme what about the not-okay case? ;; fixme what about the not-okay case?
(with-dynamic-bindings-for-proxy-eval () (with-dynamic-bindings-for-proxy-eval ()
(run-hook *pre-reply-hook*) (run-hook *pre-reply-hook*)
;(format t "About to send to emacs: ~A~%" result) ;(format t "About to send to emacs: ~A~%" result)
(send-to-emacs `(:return ,thread (send-to-emacs `(:return ,thread
,(if ok ,(if ok
`(:ok ,result) `(:ok ,result)
Expand All @@ -100,7 +100,7 @@ form, uses PROXY-EVAL-FORM"
(let (ok result) (let (ok result)
(unwind-protect (unwind-protect
(with-dynamic-bindings-for-proxy-eval () (with-dynamic-bindings-for-proxy-eval ()
;; APPLY would be cleaner than EVAL. ;; APPLY would be cleaner than EVAL.
;; (setq result (apply (car form) (cdr form))) ;; (setq result (apply (car form) (cdr form)))
(setq result (setq result
(with-slime-interrupts (proxy-eval-form form (channel-target channel) (with-slime-interrupts (proxy-eval-form form (channel-target channel)
Expand All @@ -109,7 +109,7 @@ form, uses PROXY-EVAL-FORM"
(when (eql result :pass) (when (eql result :pass)
(setf result (setf result
(eval-for-emacs form *buffer-package* id)))) (eval-for-emacs form *buffer-package* id))))

(when (not (eq result :async)) (when (not (eq result :async))
(cont ok result)))))))) (cont ok result))))))))


Expand All @@ -123,16 +123,16 @@ form, uses PROXY-EVAL-FORM"
#+nil(format t "proxy ~s~%" (list channel args)) #+nil(format t "proxy ~s~%" (list channel args))
(case (car args) (case (car args)
(:emacs-rex (:emacs-rex
(destructuring-bind (form package thread id &rest r) (cdr args) (destructuring-bind (form package thread id &rest r) (cdr args)
(declare (ignore r)) (declare (ignore r))
;;(format t "form ~s~% package ~s~% id ~S~%" form package id) ;;(format t "form ~s~% package ~s~% id ~S~%" form package id)
(proxy-eval-for-emacs form channel thread package id) (proxy-eval-for-emacs form channel thread package id)
#++(let ((swank-backend::*proxy-interfaces* (make-hash-table))) #++(let ((swank-backend::*proxy-interfaces* (make-hash-table)))
(eval-for-emacs form package id)))))) (eval-for-emacs form package id))))))




;; SPAWN-PROXY-THREAD and CREATE-PROXY-LISTENER set up the swank-proxy ;; SPAWN-PROXY-THREAD and CREATE-PROXY-LISTENER set up the swank-proxy
;; thread that listens in on SWANK events and ;; thread that listens in on SWANK events and
(defgeneric proxy-create-channel (target &key remote) (defgeneric proxy-create-channel (target &key remote)
(:documentation "Returns an instance of a proxy-channel connected to (:documentation "Returns an instance of a proxy-channel connected to
the given remote instance. the given remote instance.
Expand Down Expand Up @@ -195,7 +195,7 @@ backend. Returns the thread of the swank proxy server "
(maybe-setf *swank-proxy-thread* (maybe-setf *swank-proxy-thread*
(bordeaux-threads:make-thread (bordeaux-threads:make-thread
(lambda () (lambda ()
(unwind-protect (unwind-protect
(run-swank-proxy-loop channel emacs-connection) (run-swank-proxy-loop channel emacs-connection)
(when (eql *swank-proxy-channel* channel) (when (eql *swank-proxy-channel* channel)
(setf *swank-proxy-channel* nil)))) (setf *swank-proxy-channel* nil))))
Expand All @@ -210,10 +210,10 @@ backend. Returns the thread of the swank proxy server "
(with-top-level-restart (connection (go start)) (with-top-level-restart (connection (go start))
(with-connection (connection) (with-connection (connection)
(loop (loop
(destructure-case (wait-for-event `(:emacs-channel-send . _)) (destructure-case (wait-for-event `(:emacs-channel-send . _))
((:emacs-channel-send c (selector &rest args)) ((:emacs-channel-send c (selector &rest args))
(assert (eq c channel)) (assert (eq c channel))
(channel-send channel selector args)))))))) (channel-send channel selector args))))))))




;;; eval-and-grab-output ;;; eval-and-grab-output
Expand Down
95 changes: 48 additions & 47 deletions wsproxy.lisp
Expand Up @@ -30,7 +30,7 @@
(defun active-client-limit-ip (client) (defun active-client-limit-ip (client)
(if *allowed-active-client-ip* (if *allowed-active-client-ip*
(string= (clws:client-host client) (string= (clws:client-host client)
*allowed-active-client-ip*) *allowed-active-client-ip*)
t)) t))


;; hook for validating 'active' clients ;; hook for validating 'active' clients
Expand Down Expand Up @@ -104,7 +104,7 @@ to do with swank proxy."
`("MESSAGE" `("MESSAGE"
,message ,message
,@(when image ,@(when image
(list "IMG" image)))) (list "IMG" image))))
s)))) s))))


(defun log-to-active (res message &key image) (defun log-to-active (res message &key image)
Expand Down Expand Up @@ -165,22 +165,23 @@ variable. If not set, \"/swank\" or any resource starting with


(defun valid-data-url (string) (defun valid-data-url (string)
(labels ((base64chars (start) (labels ((base64chars (start)
(loop for i from start below (length string) (loop
for c = (aref string i) for i from start below (length string)
;; a-z A-Z 0-9 _- for c = (aref string i)
always (or (char<= #\a c #\z) ;; a-z A-Z 0-9 _-
(char<= #\A c #\Z) always (or (char<= #\a c #\z)
(char<= #\0 c #\9) (char<= #\A c #\Z)
;; not sure exactly which set of (char<= #\0 c #\9)
;; characters is valid, possibly should ;; not sure exactly which set of
;; at least reject whitespace? ;; characters is valid, possibly should
(char= c #\_) ;; at least reject whitespace?
(char= c #\-) (char= c #\_)
(char= c #\/) (char= c #\-)
(char= c #\+) (char= c #\/)
(char= c #\=) (char= c #\+)
(char= c #\space) (char= c #\=)
(char= c #\linefeed)))) (char= c #\space)
(char= c #\linefeed))))
(try-type (type) (try-type (type)
(and (alexandria:starts-with-subseq type string) (and (alexandria:starts-with-subseq type string)
(base64chars (length type))))) (base64chars (length type)))))
Expand Down Expand Up @@ -233,21 +234,21 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
(log-to-active res (format nil "image [~s]" (position client (resource-clients res))) :image message)) (log-to-active res (format nil "image [~s]" (position client (resource-clients res))) :image message))
((eql client (active-client res)) ((eql client (active-client res))
(let* ((string-for-emacs (format nil "[~s] ~s~%" (position client (resource-clients res)) message)) (let* ((string-for-emacs (format nil "[~s] ~s~%" (position client (resource-clients res)) message))
(r (ignore-errors (yason:parse message))) (r (ignore-errors (yason:parse message)))
(result (when (and r (hash-table-p r)) (gethash "RESULT" r))) (result (when (and r (hash-table-p r)) (gethash "RESULT" r)))
(id (when (and r (hash-table-p r)) (gethash "ID" r))) (id (when (and r (hash-table-p r)) (gethash "ID" r)))
(err (when (and r (hash-table-p r)) (gethash "ERROR" r)))) (err (when (and r (hash-table-p r)) (gethash "ERROR" r))))
#++(format t "got frame ~s (~s)~%" data s) #++(format t "got frame ~s (~s)~%" data s)
(splog "got response ~s . ~s / ~s~%" result id err) (splog "got response ~s . ~s / ~s~%" result id err)
(if id (if id
(let ((cont (gethash id *continuations*))) (let ((cont (gethash id *continuations*)))
(if cont (if cont
(if err (if err
(funcall cont nil err) (funcall cont nil err)
(funcall cont t result)) (funcall cont t result))
#++(format t "got cont id ~s but no cont?~%" id)) #++(format t "got cont id ~s but no cont?~%" id))
(remhash id *continuations*)) (remhash id *continuations*))
(swank::send-to-emacs `(:write-string ,string-for-emacs :proxy))))) (swank::send-to-emacs `(:write-string ,string-for-emacs :proxy)))))
(t (t
(let* ((string-for-emacs (format nil "[~s] ~s~%" (position client (resource-clients res)) message))) (let* ((string-for-emacs (format nil "[~s] ~s~%" (position client (resource-clients res)) message)))
(log-to-active res string-for-emacs) (log-to-active res string-for-emacs)
Expand Down Expand Up @@ -330,20 +331,20 @@ okay or not, and (2) the result."
(maybe-kill *swank-proxy-ws-thread* ) (maybe-kill *swank-proxy-ws-thread* )
(maybe-kill *swank-proxy-resource-thread*) (maybe-kill *swank-proxy-resource-thread*)


(let ((con swank::*emacs-connection*)) (let ((con swank::*emacs-connection*))
(maybe-setf *swank-proxy-ws-thread* (maybe-setf *swank-proxy-ws-thread*
(bordeaux-threads:make-thread (bordeaux-threads:make-thread
(lambda () (lambda ()
(swank::with-connection (con) (swank::with-connection (con)
(ws:run-server port))) (ws:run-server port)))
:name "swank-proxy websockets server")) :name "swank-proxy websockets server"))


(maybe-setf *swank-proxy-resource-thread* (maybe-setf *swank-proxy-resource-thread*
(bordeaux-threads:make-thread (bordeaux-threads:make-thread
(lambda () (lambda ()
(swank::with-connection (con) (swank::with-connection (con)
(run-swank-proxy-resource-server))) (run-swank-proxy-resource-server)))
:name "swank-proxy resource handler")))) :name "swank-proxy resource handler"))))
(list *swank-proxy-ws-thread* *swank-proxy-resource-thread*)) (list *swank-proxy-ws-thread* *swank-proxy-resource-thread*))


(defun run-swank-proxy-resource-server () (defun run-swank-proxy-resource-server ()
Expand Down

0 comments on commit 9371b0e

Please sign in to comment.