70a831232f0f

Roswell and more
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Sun, 10 Apr 2016 21:41:33 +0000
parents f453bfba01a7
children 0ab8b4c9ac2a
branches/tags (none)
files .hgignore bash_profile bin/nrepl bin/nrepl-ccl bin/nrepl-sbcl fish/config.fish lispwords roswell/clhs.ros vim/ftplugin/lisp/lispfolding.vim vim/vimrc w3m-keymap

Changes

--- a/.hgignore	Sun Apr 10 21:40:53 2016 +0000
+++ b/.hgignore	Sun Apr 10 21:41:33 2016 +0000
@@ -37,3 +37,5 @@
 fish/local.fish
 ipython/profile_default/history.sqlite
 weechat/certs/ca-bundle.crt
+
+roswell/clhs
--- a/bash_profile	Sun Apr 10 21:40:53 2016 +0000
+++ b/bash_profile	Sun Apr 10 21:41:33 2016 +0000
@@ -15,7 +15,7 @@
     fi
 }
 
-export PATH=~/bin:~/lib/dotfiles/bin:/usr/local/share/python:/usr/local/bin/:$PATH
+export PATH=~/bin:~/lib/dotfiles/bin:~/.roswell/bin:/usr/local/share/python:/usr/local/bin/:$PATH
 
 alias h='hg'
 alias g='git'
--- a/bin/nrepl	Sun Apr 10 21:40:53 2016 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,5 +0,0 @@
-#!/usr/bin/env bash
-
-set -e
-
-rlwrap sbcl --eval "(ql:quickload 'nrepl)" --eval "(nrepl:start-server)" "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/nrepl-ccl	Sun Apr 10 21:41:33 2016 +0000
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -e
+
+ccl --eval "(ql:quickload 'nrepl)" --eval "(nrepl:start-server)" "$@"
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/nrepl-sbcl	Sun Apr 10 21:41:33 2016 +0000
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -e
+
+rlwrap sbcl --eval "(ql:quickload 'nrepl)" --eval "(nrepl:start-server)" "$@"
--- a/fish/config.fish	Sun Apr 10 21:40:53 2016 +0000
+++ b/fish/config.fish	Sun Apr 10 21:41:33 2016 +0000
@@ -64,9 +64,7 @@
         end
     end
 end
-set -gx PATH "/usr/X11R6/bin"
-prepend_to_path "/usr/texbin"
-prepend_to_path "/sbin"
+set -gx PATH "/sbin"
 prepend_to_path "/usr/sbin"
 prepend_to_path "/bin"
 prepend_to_path "/usr/bin"
@@ -75,13 +73,8 @@
 prepend_to_path "/usr/local/sbin"
 prepend_to_path "/usr/local/share/npm/bin"
 prepend_to_path "$HOME/lib/dotfiles/bin"
-prepend_to_path "/opt/local/bin"
-prepend_to_path "/opt/subversion/bin"
 prepend_to_path "$HOME/lib/hg/hg"
-prepend_to_path "$HOME/Library/Haskell/bin"
-prepend_to_path "/usr/local/Cellar/ruby/1.9.3-p194/bin"
-prepend_to_path "/Applications/Postgres.app/Contents/MacOS/bin"
-prepend_to_path "$HOME/.rbenv/shims"
+prepend_to_path "$HOME/.roswell/bin"
 prepend_to_path "$HOME/bin"
 
 set BROWSER open
--- a/lispwords	Sun Apr 10 21:40:53 2016 +0000
+++ b/lispwords	Sun Apr 10 21:41:33 2016 +0000
@@ -22,8 +22,3 @@
 ; sketch
 (1 with-pen)
 (3 defsketch)
-(1 scancode-case)
-
-; my shit
-(1 vector-push-extend-all)
-
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/roswell/clhs.ros	Sun Apr 10 21:41:33 2016 +0000
@@ -0,0 +1,166 @@
+#!/bin/sh
+#|-*- mode:lisp -*-|#
+#|
+exec ros -Q -- $0 "$@"
+|#
+
+#|
+
+A Roswell script to open the HyperSpec page of a specified symbol in the default browser.
+
+Usage
+-----
+
+    $ clhs [SYMBOL]
+
+
+Installation
+------------
+
+Just download this script, give execute permission, and move to somewhere your shell can find it (assuming `~/.roswell/bin/` is in $PATH in the following example).
+
+    $ wget https://gist.githubusercontent.com/fukamachi/3510ea1609c1b52830c2/raw/clhs.ros -O clhs
+    $ chmod u+x clhs
+    $ mv clhs ~/.roswell/bin
+
+You may want to `ros build` for creating an executable file for fast execution.
+
+    $ ros build clhs.ros
+    $ mv clhs ~/.roswell/bin
+
+
+Environment variables
+---------------------
+
+    CLHS_BASE_URL:
+      The base URL of HyperSpec. The default is LispWorks'.
+
+    CLHS_OPEN_COMMAND:
+      Command name to open an URL with the default browser.
+      The default value is 'open' for Mac and 'xdg-open' for Linux.
+
+
+Copyright
+---------
+
+Copyright (c) 2015 Eitaro Fukamachi, Masatoshi Sano
+
+
+LICENSE
+-------
+
+This script is licensed under the MIT License.
+
+|#
+
+;; Loading dependencies
+(unless (find-package :uiop)
+  (ql:quickload '(:uiop) :silent t))
+
+
+;;
+;; Special variables
+
+(defparameter *clhs-base-url*
+  (or (uiop:getenv "CLHS_BASE_URL")
+      "http://www.lispworks.com/documentation/HyperSpec/"))
+
+(defparameter *clhs-cache-directory*
+  (let ((cache-dir
+          (uiop:ensure-directory-pathname (uiop:getenv "XDG_CACHE_HOME")
+                                          (merge-pathnames ".cache/" (user-homedir-pathname)))))
+    (merge-pathnames #P"clhs/" cache-dir)))
+
+(defparameter *clhs-cache-file*
+  (merge-pathnames #P"symbols-map.sexp" *clhs-cache-directory*))
+
+(defparameter *open-command*
+  (or (uiop:getenv "CLHS_OPEN_COMMAND")
+      #+darwin "open"
+      #+linux  "xdg-open"
+      #+(or windows win32) "explorer"
+      #-(or darwin linux windows win32)
+      (error "CLHS_OPEN_COMMAND is not set.")))
+
+
+;;
+;; Utilities
+
+(defun terminate (code &optional message &rest args)
+  (when message
+    (format *error-output* "~&~A~%"
+            (apply #'format nil (princ-to-string message) args)))
+  (uiop:quit code))
+
+;; Copied from Qlot
+(defmacro with-package-functions (package-designator functions &body body)
+  (let ((args (gensym "ARGS")))
+    `(flet (,@(loop for fn in functions
+                    collect `(,fn (&rest ,args)
+                                  (apply
+                                   ,(if (and (listp fn) (eq (car fn) 'setf))
+                                        `(eval `(function (setf ,(intern ,(string (cadr fn)) ,package-designator))))
+                                        `(symbol-function (intern ,(string fn) ,package-designator)))
+                                   ,args))))
+       ,@body)))
+
+(defun retrieve-url (url)
+  (with-package-functions :drakma (http-request)
+    (tagbody retry
+       (multiple-value-bind (body status)
+           (http-request url)
+         (unless (= status 200)
+           (restart-case
+               (error "Failed to retrieve ~S (Code=~A)" url status)
+             (retry-request ()
+               :report "Retry the request to URL."
+               (go retry))))
+         (return-from retrieve-url body)))))
+
+
+;;
+;; Here we go!
+
+(defun clhs-url (path)
+  (format nil "~A~A" *clhs-base-url* path))
+
+(defun retrieve-clhs-symbols-map ()
+  (ql:quickload '(:drakma :plump :clss) :silent t)
+
+  (with-package-functions :plump (parse text attribute)
+    (with-package-functions :clss (select)
+      (let ((body (retrieve-url (clhs-url "Front/X_AllSym.htm"))))
+        (map 'list
+             (lambda (a)
+               (cons (text a)
+                     (let ((path (attribute a "href")))
+                       ;; Omit "../" and URL fragment
+                       (subseq path 3 (position #\# path)))))
+             (select "a[rel=definition]" (parse body)))))))
+
+(defun clhs-symbols-map ()
+  (if (probe-file *clhs-cache-file*)
+      (uiop:read-file-form *clhs-cache-file*)
+      (let ((symbols (retrieve-clhs-symbols-map)))
+        (ensure-directories-exist *clhs-cache-file*)
+        (with-open-file (out *clhs-cache-file*
+                             :direction :output
+                             :if-does-not-exist :create)
+          (prin1 symbols out))
+        symbols)))
+
+(defun find-symbol-path (target-symbol)
+  (cdr (assoc target-symbol (clhs-symbols-map)
+              :test #'string-equal)))
+ 
+(defun main (&optional target-symbol &rest argv)
+  (declare (ignore argv))
+  (unless target-symbol
+    (terminate -1 "Usage: clhs [SYMBOL]"))
+
+  (let ((path (find-symbol-path target-symbol)))
+    (if path
+        (let ((url (clhs-url path)))
+          (format t "~&Opening ~S~%" url)
+          (uiop:run-program `(,*open-command* ,url) :ignore-error-status t :output :interactive))
+        (terminate -1 "Symbol not found: ~A" target-symbol))))
--- a/vim/ftplugin/lisp/lispfolding.vim	Sun Apr 10 21:40:53 2016 +0000
+++ b/vim/ftplugin/lisp/lispfolding.vim	Sun Apr 10 21:41:33 2016 +0000
@@ -10,9 +10,9 @@
 function! GetLispFold()
     let inline_fn_comment_re = '\v^ *;;( .*)?$'
 
-    if getline(v:lnum) =~ '^;;;; .*'
+    if getline(v:lnum) =~ '^;;;; '
         return "0"
-    elseif getline(v:lnum) =~ '^;;;.*'
+    elseif getline(v:lnum) =~ '^;;; '
         return "1"
     elseif getline(v:lnum) =~ inline_fn_comment_re
         if getline(v:lnum + 1) =~ inline_fn_comment_re
@@ -20,34 +20,15 @@
         else
             return "<2"
         endif
-    elseif getline(v:lnum) =~ '^; .*'
+    elseif getline(v:lnum) =~ '^; '
         return "0"
-    elseif getline(v:lnum) =~ '^(let.*\s'
+    elseif getline(v:lnum) =~ '^(let[*]? '
         " let over lambda
         return ">1"
-    elseif getline(v:lnum) =~ '^(defun.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(test.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(defmacro.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(defmethod.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(defgeneric.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(defparameter.*\s'
+    elseif getline(v:lnum) =~ '^(test '
         return ">1"
-    elseif getline(v:lnum) =~ '^(defconstant.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(deftype.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(defvar.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(defclass.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(defstruct.*\s'
-        return ">1"
-    elseif getline(v:lnum) =~ '^(define-.*\s'
+    elseif getline(v:lnum) =~ '^(def\S\+ '
+        " fuck it just fold everything that looks kinda deffy
         return ">1"
     elseif getline(v:lnum) =~ '^\s*$'
         let my_lispnum = v:lnum
--- a/vim/vimrc	Sun Apr 10 21:40:53 2016 +0000
+++ b/vim/vimrc	Sun Apr 10 21:41:33 2016 +0000
@@ -909,8 +909,12 @@
     hi def link replResult Debug
     hi def link replComment Comment
 endfunction "}}}
-function! OpenLispRepl() "{{{
-    NeoRepl nrepl
+function! OpenLispReplSBCL() "{{{
+    NeoRepl nrepl-sbcl
+    call HighlightLispRepl()
+endfunction "}}}
+function! OpenLispReplCCL() "{{{
+    NeoRepl nrepl-ccl
     call HighlightLispRepl()
 endfunction "}}}
 function! SetLispWords() "{{{
@@ -1040,7 +1044,8 @@
     " [s]end to repl
     " [c]lear repl
     au FileType lisp silent! call OozeMapKeys()
-    au FileType lisp nnoremap <buffer> <silent> <localleader>o :call OpenLispRepl()<cr>
+    au FileType lisp nnoremap <buffer> <silent> <localleader>os :call OpenLispReplSBCL()<cr>
+    au FileType lisp nnoremap <buffer> <silent> <localleader>oc :call OpenLispReplCCL()<cr>
     au FileType lisp nnoremap <buffer> <silent> <localleader>s :call SendToplevelLispForm()<cr>
     au FileType lisp nnoremap <buffer> <silent> <localleader>c :call NeoReplSendRaw("nil\n")<cr>:sleep 20m<cr>:call NeoReplSendRaw("")<cr>
     au FileType lisp nnoremap <buffer> gi :call IndentToplevelLispForm()<cr>
@@ -2034,6 +2039,32 @@
 let g:ackprg = 'ag --smart-case --nogroup --nocolor --column'
 
 " }}}
+" Airline {{{
+
+if !exists('g:airline_symbols')
+    let g:airline_symbols = {}
+endif
+
+let g:airline_theme='badwolf'
+
+let g:airline_theme_patch_func = 'AirlineThemePatch'
+function! AirlineThemePatch(palette)
+    if g:airline_theme == 'badwolf'
+        for colors in values(a:palette.inactive)
+            let colors[2] = 15
+        endfor
+    endif
+endfunction
+
+let g:airline_left_sep = '⮀'
+let g:airline_left_alt_sep = '⮁'
+let g:airline_right_sep = '⮂'
+let g:airline_right_alt_sep = '⮃'
+let g:airline_symbols.branch = '⭠'
+let g:airline_symbols.readonly = '⭤'
+let g:airline_symbols.linenr = '⭡'
+
+" }}}
 " Autoclose {{{
 
 nmap <Leader>x <Plug>ToggleAutoCloseMappings
@@ -2251,7 +2282,7 @@
 augroup END
 
 let NERDTreeHighlightCursorline = 1
-let NERDTreeIgnore = ['.vim$', '\~$', '.*\.pyc$', 'pip-log\.txt$', 'whoosh_index',
+let NERDTreeIgnore = ['\~$', '.*\.pyc$', 'pip-log\.txt$', 'whoosh_index',
                     \ 'xapian_index', '.*.pid', 'monitor.py', '.*-fixtures-.*.json',
                     \ '.*\.o$', 'db.db', 'tags.bak', '.*\.pdf$', '.*\.mid$',
                     \ '.*\.midi$']
@@ -2280,13 +2311,6 @@
 let g:paredit_electric_return = 1
 
 " }}}
-" Powerline {{{
-
-let g:Powerline_symbols = 'fancy'
-let g:Powerline_cache_enabled = 1
-let g:Powerline_colorscheme = 'badwolf'
-
-" }}}
 " Python-Mode {{{
 
 let g:pymode_doc = 1
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/w3m-keymap	Sun Apr 10 21:41:33 2016 +0000
@@ -0,0 +1,2 @@
+keymap  q       EXIT
+keymap  K       EXIT