Created
January 15, 2015 20:52
-
-
Save verma/e4d533565624ae1de3b2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
;; input lines are like: | |
;; fs.truncate(path, len, callback) | |
;; fs.truncateSync(path, len) | |
;; fs.chown(path, uid, gid, callback) | |
;; fs.chownSync(path, uid, gid) | |
;; which are converted to: | |
;; (def ftruncate (core/clojureify fs.ftruncate)) | |
;; (def ftruncate-sync (core/clojureify-sync fs.ftruncateSync)) | |
;; ... | |
(defun sync? (fname) | |
(string-match "Sync$" fname)) | |
(defun bare-name (fname) | |
(substring fname 0 (sync? fname))) | |
(defun make-func-call (full fname q?) | |
(let ((pf (if (sync? fname) "-sync" "")) | |
(qpf (if q? "?" "")) | |
(bn (bare-name fname))) | |
(format "%s%s%s" bn pf qpf))) | |
(defun make-clj-call (full fname q?) | |
(let ((fn (make-func-call full fname q?)) | |
(cc (if (sync? fname) "core/clojureify-sync" "core/clojureify"))) | |
(format "(def %s (%s %s))" | |
fn cc full))) | |
(defun fix-it-up () | |
(interactive) | |
(save-excursion | |
(beginning-of-line) | |
(when (re-search-forward "[a-z]+\\.\\([a-zA-Z0-9]+\\)") | |
(let ((full (match-string 0)) | |
(fname (match-string 1))) | |
(message (make-clj-call full fname nil)))))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment