Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
alfons haffmans
committed
Jan 2, 2011
1 parent
bd399e8
commit 9a95c79
Showing
14 changed files
with
213 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
|
@@ -4,4 +4,5 @@ | ||
*.abcl | *.abcl | ||
*.lx64fsl | *.lx64fsl | ||
*.fasl | *.fasl | ||
*.ht | *.ht | ||
*.alias |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,48 @@ | |||
(in-package :cl-twit-repl) | |||
|
|||
(defvar *alias-registry* (make-hash-table :test 'equal)) | |||
(defvar *alias-file-name* "cl-twit-repl.alias") | |||
|
|||
(defun alias-file () | |||
(default-access-path "alias/" *alias-file-name*)) | |||
|
|||
(defmacro testit (x y) | |||
`(destructuring-bind (name (&rest args) &rest body) ',y | |||
(format nil "(defun ~S (&rest args) (apply (~S ~S ~S ) args)) " ',x name args (car body)))) | |||
|
|||
(defmacro construct-alias-func (x y) | |||
`(if (listp ,y) | |||
(progn | |||
(if (equal (car ,y) 'lambda) | |||
(destructuring-bind (name (&rest args) &rest body) ,y | |||
(format nil "(defun ~S (&rest args) (apply (~S ~A ~S) args)) " ,x name args (car body))) | |||
(destructuring-bind (fn &rest rest) ,y | |||
(format nil "(defun ~S (&rest args) (apply '~S ~{ ~S ~} args))" ,x fn rest)))) | |||
(format nil "(defun ~S (&rest args) (apply '~S args))" ,x ,y))) | |||
|
|||
(defmacro alias (&optional x y) | |||
`(if ',x | |||
(if ',y | |||
(eval (read (make-string-input-stream (cdr (setf (gethash ',x *alias-registry*) (cons ',y (construct-alias-func ',x ',y))))))) | |||
(car (gethash ',x *alias-registry*))) | |||
(maphash (lambda (k v) (format t "~1t~S ~20t=> ~25t~S~%" k (car v))) *alias-registry*))) | |||
|
|||
(defmacro unalias (&optional x) | |||
`(if ',x | |||
(progn (remhash ',x *alias-registry*) | |||
(fmakunbound ',x)) | |||
(progn (maphash (lambda (k v) (declare (ignore v)) (fmakunbound k)) *alias-registry*) | |||
(setf *alias-registry* (make-hash-table :test 'equal))))) | |||
|
|||
(defun dump-alias () | |||
(with-open-file (stream (alias-file) :direction :output :if-exists :supersede) | |||
(maphash (lambda (key lst) (format stream "~S~%" (list key lst))) *alias-registry*))) | |||
|
|||
(defun read-alias () | |||
(when (probe-file (alias-file)) | |||
(with-open-file (stream (alias-file) :direction :input ) | |||
(do ((line (read stream nil) (read stream nil))) | |||
((null line)) | |||
(eval (read (make-string-input-stream (cdr (setf (gethash (car line) *alias-registry*) (cadr line)))))))))) | |||
|
|||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -1,22 +1,45 @@ | |||
(in-package :cl-twit-repl) | (in-package :cl-twit-repl) | ||
|
|
||
(defun cursor () | (defvar *consumer-key* "9hOStbD2Zf7x0mUoo7cYBg" "The consumer key for cl-twit-repl, as listed on https://twitter.com/apps. Used for OAuth.") | ||
(if *twitter-user* | (defvar *consumer-secret* "PWx9ZBZS9BVbesqlkoyiPzXtucmU7jaWe4ECcC30l0" "The consumer secret for cl-twit-repl, as listed on https://twitter.com/apps. Used for OAuth.") | ||
(format t "~&~A> " (twitter-user-screen-name *twitter-user*)) | (defvar *saved-print-pprint-dispatch* () "saved version of the dispatch table") | ||
(format t "~&~A> " "not_authenticated"))) | (defvar *saved-pprint-dispatch-cons* (pprint-dispatch 'cons) "saved version of the cons pp") | ||
|
(defvar *cl-twit-repl-stream* *standard-output* "prefferred output stream for the twitter repl client") | ||
(defun cl-twit-read () | |||
(read-from-string (read-line) nil nil)) | |||
|
|
||
(defun cl-twit-eval (sexp) | (defvar *twitter-types* (list 'tweet 'cl-twitter::geo-places 'cl-twitter::geo-place 'cl-twitter::place 'cl-twitter::list-type 'cl-twitter::geo-result 'twitter-user 'search-ref 'trend-list | ||
(eval sexp)) | 'cl-twitter::rate-limit) "list of types in the twitter api for which we 're going to use the show method instead of the pp") | ||
|
|
||
(defun cl-twit-print (lst) | (defun twitterp (obj) | ||
(format t "~S" (show lst))) | (member (type-of obj) *twitter-types*)) | ||
|
|||
(defun pp-show (s o) | |||
(if (or (twitterp o) (and (consp o) (twitterp (car o))) (hash-table-p o)) | |||
(show o (or *cl-twit-repl-stream* s)) | |||
(funcall *saved-pprint-dispatch-cons* s o))) | |||
|
|||
(defun install-new-dispatchers () | |||
(mapcar (lambda (type) (set-pprint-dispatch type #'pp-show)) *twitter-types*)) | |||
|
|
||
(defun cl-twit-repl () | (defun cl-twit-repl () | ||
(cursor) | (use-package :cl-twitter) | ||
(let ((cmd (cl-twit-read))) | (unless *alias-registry* (setf *alias-registry* (make-hash-table :test 'equal))) | ||
(unless (and (consp cmd) (eq (car cmd ) 'quit)) | (read-alias) | ||
(cl-twit-print (cl-twit-eval cmd)) | (when (null *saved-print-pprint-dispatch*) (setf *saved-print-pprint-dispatch* (copy-pprint-dispatch))) | ||
(cl-twit-repl)))) | (set-pprint-dispatch 'cons #'pp-show) | ||
(set-pprint-dispatch 'hash-table #'pp-show) | |||
(install-new-dispatchers) | |||
(unless (probe-file (access-file)) (repl-authenticate-user)) | |||
(cl-twitter::with-error-handler (:verbose nil) | |||
(verify-credentials))) | |||
|
|||
(defun done-twittering () | |||
(when *saved-print-pprint-dispatch* | |||
(setf *print-pprint-dispatch* *saved-print-pprint-dispatch*) | |||
(setf *saved-print-pprint-dispatch* nil)) | |||
;;order is important | |||
(when *alias-registry* (dump-alias)) | |||
(setf *alias-registry* nil) | |||
(cl-twitter::with-error-handler (:verbose nil) | |||
(end-session)) | |||
(setf *twitter-user* nil)) | |||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.