Skip to content

Instantly share code, notes, and snippets.

@verma
Created January 15, 2015 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save verma/e4d533565624ae1de3b2 to your computer and use it in GitHub Desktop.
Save verma/e4d533565624ae1de3b2 to your computer and use it in GitHub Desktop.
;; 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