diff --git a/emacs b/emacs index e3d5ed9..60c5c02 100644 --- a/emacs +++ b/emacs @@ -38,6 +38,11 @@ (require 'flymake-cursor) (add-hook 'find-file-hook 'flymake-find-file-hook) +(require 'projectile) +(setq projectile-completion-system 'grizzl) +(setq projectile-use-native-indexing t) +(setq projectile-enable-caching t) + (elpy-enable) ;call gofmt on the script when saving diff --git a/emacs.d/elpa/dash-1.5.0/dash-autoloads.el b/emacs.d/elpa/dash-1.5.0/dash-autoloads.el new file mode 100644 index 0000000..e7af8c2 --- /dev/null +++ b/emacs.d/elpa/dash-1.5.0/dash-autoloads.el @@ -0,0 +1,18 @@ +;;; dash-autoloads.el --- automatically extracted autoloads +;; +;;; Code: + + +;;;### (autoloads nil nil ("dash-pkg.el" "dash.el") (21002 9889 395401 +;;;;;; 0)) + +;;;*** + +(provide 'dash-autoloads) +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; dash-autoloads.el ends here diff --git a/emacs.d/elpa/dash-1.5.0/dash-pkg.el b/emacs.d/elpa/dash-1.5.0/dash-pkg.el new file mode 100644 index 0000000..6e14dbe --- /dev/null +++ b/emacs.d/elpa/dash-1.5.0/dash-pkg.el @@ -0,0 +1 @@ +(define-package "dash" "1.5.0" "A modern list library for Emacs" (quote nil)) diff --git a/emacs.d/elpa/dash-1.5.0/dash-pkg.elc b/emacs.d/elpa/dash-1.5.0/dash-pkg.elc new file mode 100644 index 0000000..f4530c7 Binary files /dev/null and b/emacs.d/elpa/dash-1.5.0/dash-pkg.elc differ diff --git a/emacs.d/elpa/dash-1.5.0/dash.el b/emacs.d/elpa/dash-1.5.0/dash.el new file mode 100644 index 0000000..1043c23 --- /dev/null +++ b/emacs.d/elpa/dash-1.5.0/dash.el @@ -0,0 +1,1006 @@ +;;; dash.el --- A modern list library for Emacs + +;; Copyright (C) 2012 Magnar Sveen + +;; Author: Magnar Sveen +;; Version: 1.5.0 +;; Keywords: lists + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; A modern list api for Emacs. +;; +;; See documentation on https://github.com/magnars/dash.el#functions + +;;; Code: + +(defmacro !cons (car cdr) + "Destructive: Sets CDR to the cons of CAR and CDR." + `(setq ,cdr (cons ,car ,cdr))) + +(defmacro !cdr (list) + "Destructive: Sets LIST to the cdr of LIST." + `(setq ,list (cdr ,list))) + +(defmacro --each (list &rest body) + "Anaphoric form of `-each'." + (declare (debug t)) + (let ((l (make-symbol "list"))) + `(let ((,l ,list) + (it-index 0)) + (while ,l + (let ((it (car ,l))) + ,@body) + (setq it-index (1+ it-index)) + (!cdr ,l))))) + +(put '--each 'lisp-indent-function 1) + +(defun -each (list fn) + "Calls FN with every item in LIST. Returns nil, used for side-effects only." + (--each list (funcall fn it))) + +(defmacro --each-while (list pred &rest body) + "Anaphoric form of `-each-while'." + (let ((l (make-symbol "list")) + (c (make-symbol "continue"))) + `(let ((,l ,list) + (,c t)) + (while (and ,l ,c) + (let ((it (car ,l))) + (if (not ,pred) (setq ,c nil) ,@body)) + (!cdr ,l))))) + +(put '--each-while 'lisp-indent-function 2) + +(defun -each-while (list pred fn) + "Calls FN with every item in LIST while (PRED item) is non-nil. +Returns nil, used for side-effects only." + (--each-while list (funcall pred it) (funcall fn it))) + +(defmacro --dotimes (num &rest body) + "Repeatedly executes BODY (presumably for side-effects) with `it` bound to integers from 0 through n-1." + `(let ((it 0)) + (while (< it ,num) + ,@body + (setq it (1+ it))))) + +(put '--dotimes 'lisp-indent-function 1) + +(defun -dotimes (num fn) + "Repeatedly calls FN (presumably for side-effects) passing in integers from 0 through n-1." + (--dotimes num (funcall fn it))) + +(defun -map (fn list) + "Returns a new list consisting of the result of applying FN to the items in LIST." + (mapcar fn list)) + +(defmacro --map (form list) + "Anaphoric form of `-map'." + (declare (debug t)) + `(mapcar (lambda (it) ,form) ,list)) + +(defmacro --reduce-from (form initial-value list) + "Anaphoric form of `-reduce-from'." + `(let ((acc ,initial-value)) + (--each ,list (setq acc ,form)) + acc)) + +(defun -reduce-from (fn initial-value list) + "Returns the result of applying FN to INITIAL-VALUE and the +first item in LIST, then applying FN to that result and the 2nd +item, etc. If LIST contains no items, returns INITIAL-VALUE and +FN is not called. + +In the anaphoric form `--reduce-from', the accumulated value is +exposed as `acc`." + (--reduce-from (funcall fn acc it) initial-value list)) + +(defmacro --reduce (form list) + "Anaphoric form of `-reduce'." + (let ((lv (make-symbol "list-value"))) + `(let ((,lv ,list)) + (if ,lv + (--reduce-from ,form (car ,lv) (cdr ,lv)) + (let (acc it) ,form))))) + +(defun -reduce (fn list) + "Returns the result of applying FN to the first 2 items in LIST, +then applying FN to that result and the 3rd item, etc. If LIST +contains no items, FN must accept no arguments as well, and +reduce returns the result of calling FN with no arguments. If +LIST has only 1 item, it is returned and FN is not called. + +In the anaphoric form `--reduce', the accumulated value is +exposed as `acc`." + (if list + (-reduce-from fn (car list) (cdr list)) + (funcall fn))) + +(defun -reduce-r-from (fn initial-value list) + "Replace conses with FN, nil with INITIAL-VALUE and evaluate +the resulting expression. If LIST is empty, INITIAL-VALUE is +returned and FN is not called. + +Note: this function works the same as `-reduce-from' but the +operation associates from right instead of from left." + (if (not list) initial-value + (funcall fn (car list) (-reduce-r-from fn initial-value (cdr list))))) + +(defmacro --reduce-r-from (form initial-value list) + "Anaphoric version of `-reduce-r-from'." + `(-reduce-r-from (lambda (&optional it acc) ,form) ,initial-value ,list)) + +(defun -reduce-r (fn list) + "Replace conses with FN and evaluate the resulting expression. +The final nil is ignored. If LIST contains no items, FN must +accept no arguments as well, and reduce returns the result of +calling FN with no arguments. If LIST has only 1 item, it is +returned and FN is not called. + +The first argument of FN is the new item, the second is the +accumulated value. + +Note: this function works the same as `-reduce' but the operation +associates from right instead of from left." + (cond + ((not list) (funcall fn)) + ((not (cdr list)) (car list)) + (t (funcall fn (car list) (-reduce-r fn (cdr list)))))) + +(defmacro --reduce-r (form list) + "Anaphoric version of `-reduce-r'." + `(-reduce-r (lambda (&optional it acc) ,form) ,list)) + +(defmacro --filter (form list) + "Anaphoric form of `-filter'." + (let ((r (make-symbol "result"))) + `(let (,r) + (--each ,list (when ,form (!cons it ,r))) + (nreverse ,r)))) + +(defun -filter (pred list) + "Returns a new list of the items in LIST for which PRED returns a non-nil value. + +Alias: `-select'" + (--filter (funcall pred it) list)) + +(defalias '-select '-filter) +(defalias '--select '--filter) + +(defmacro --remove (form list) + "Anaphoric form of `-remove'." + (declare (debug t)) + `(--filter (not ,form) ,list)) + +(defun -remove (pred list) + "Returns a new list of the items in LIST for which PRED returns nil. + +Alias: `-reject'" + (--remove (funcall pred it) list)) + +(defalias '-reject '-remove) +(defalias '--reject '--remove) + +(defmacro --keep (form list) + "Anaphoric form of `-keep'." + (let ((r (make-symbol "result")) + (m (make-symbol "mapped"))) + `(let (,r) + (--each ,list (let ((,m ,form)) (when ,m (!cons ,m ,r)))) + (nreverse ,r)))) + +(defun -keep (fn list) + "Returns a new list of the non-nil results of applying FN to the items in LIST." + (--keep (funcall fn it) list)) + +(defmacro --map-when (pred rep list) + "Anaphoric form of `-map-when'." + (let ((r (make-symbol "result"))) + `(let (,r) + (--each ,list (!cons (if ,pred ,rep it) ,r)) + (nreverse ,r)))) + +(defmacro --map-indexed (form list) + "Anaphoric form of `-map-indexed'." + (let ((r (make-symbol "result"))) + `(let (,r) + (--each ,list + (!cons ,form ,r)) + (nreverse ,r)))) + +(defun -map-indexed (fn list) + "Returns a new list consisting of the result of (FN index item) for each item in LIST. + +In the anaphoric form `--map-indexed', the index is exposed as `it-index`." + (--map-indexed (funcall fn it-index it) list)) + +(defun -map-when (pred rep list) + "Returns a new list where the elements in LIST that does not match the PRED function +are unchanged, and where the elements in LIST that do match the PRED function are mapped +through the REP function." + (--map-when (funcall pred it) (funcall rep it) list)) + +(defalias '--replace-where '--map-when) +(defalias '-replace-where '-map-when) + +(defun -flatten (l) + "Takes a nested list L and returns its contents as a single, flat list." + (if (and (listp l) (listp (cdr l))) + (-mapcat '-flatten l) + (list l))) + +(defun -concat (&rest lists) + "Returns a new list with the concatenation of the elements in the supplied LISTS." + (apply 'append lists)) + +(defmacro --mapcat (form list) + "Anaphoric form of `-mapcat'." + (declare (debug t)) + `(apply 'append (--map ,form ,list))) + +(defun -mapcat (fn list) + "Returns the concatenation of the result of mapping FN over LIST. +Thus function FN should return a list." + (--mapcat (funcall fn it) list)) + +(defun -cons* (&rest args) + "Makes a new list from the elements of ARGS. + +The last 2 members of ARGS are used as the final cons of the +result so if the final member of ARGS is not a list the result is +a dotted list." + (let (res) + (--each + args + (cond + ((not res) + (setq res it)) + ((consp res) + (setcdr res (cons (cdr res) it))) + (t + (setq res (cons res it))))) + res)) + +(defmacro --first (form list) + "Anaphoric form of `-first'." + (let ((n (make-symbol "needle"))) + `(let (,n) + (--each-while ,list (not ,n) + (when ,form (setq ,n it))) + ,n))) + +(defun -first (pred list) + "Returns the first x in LIST where (PRED x) is non-nil, else nil. + +To get the first item in the list no questions asked, use `car'." + (--first (funcall pred it) list)) + +(defmacro --last (form list) + "Anaphoric form of `-last'." + (let ((n (make-symbol "needle"))) + `(let (,n) + (--each ,list + (when ,form (setq ,n it))) + ,n))) + +(defun -last (pred list) + "Return the last x in LIST where (PRED x) is non-nil, else nil." + (--last (funcall pred it) list)) + +(defmacro --count (pred list) + "Anaphoric form of `-count'." + (let ((r (make-symbol "result"))) + `(let ((,r 0)) + (--each ,list (when ,pred (setq ,r (1+ ,r)))) + ,r))) + +(defun -count (pred list) + "Counts the number of items in LIST where (PRED item) is non-nil." + (--count (funcall pred it) list)) + +(defun ---truthy? (val) + (not (null val))) + +(defmacro --any? (form list) + "Anaphoric form of `-any?'." + `(---truthy? (--first ,form ,list))) + +(defun -any? (pred list) + "Returns t if (PRED x) is non-nil for any x in LIST, else nil. + +Alias: `-some?'" + (--any? (funcall pred it) list)) + +(defalias '-some? '-any?) +(defalias '--some? '--any?) + +(defalias '-any-p '-any?) +(defalias '--any-p '--any?) +(defalias '-some-p '-any?) +(defalias '--some-p '--any?) + +(defmacro --all? (form list) + "Anaphoric form of `-all?'." + (let ((a (make-symbol "all"))) + `(let ((,a t)) + (--each-while ,list ,a (setq ,a ,form)) + (---truthy? ,a)))) + +(defun -all? (pred list) + "Returns t if (PRED x) is non-nil for all x in LIST, else nil. + +Alias: `-every?'" + (--all? (funcall pred it) list)) + +(defalias '-every? '-all?) +(defalias '--every? '--all?) + +(defalias '-all-p '-all?) +(defalias '--all-p '--all?) +(defalias '-every-p '-all?) +(defalias '--every-p '--all?) + +(defmacro --none? (form list) + "Anaphoric form of `-none?'." + `(--all? (not ,form) ,list)) + +(defun -none? (pred list) + "Returns t if (PRED x) is nil for all x in LIST, else nil." + (--none? (funcall pred it) list)) + +(defalias '-none-p '-none?) +(defalias '--none-p '--none?) + +(defmacro --only-some? (form list) + "Anaphoric form of `-only-some?'." + (let ((y (make-symbol "yes")) + (n (make-symbol "no"))) + `(let (,y ,n) + (--each-while ,list (not (and ,y ,n)) + (if ,form (setq ,y t) (setq ,n t))) + (---truthy? (and ,y ,n))))) + +(defun -only-some? (pred list) + "Returns `t` if there is a mix of items in LIST that matches and does not match PRED. +Returns `nil` both if all items match the predicate, and if none of the items match the predicate." + (--only-some? (funcall pred it) list)) + +(defalias '-only-some-p '-only-some?) +(defalias '--only-some-p '--only-some?) + +(defun -slice (list from &optional to) + "Return copy of LIST, starting from index FROM to index TO. +FROM or TO may be negative." + (let ((length (length list)) + (new-list nil) + (index 0)) + ;; to defaults to the end of the list + (setq to (or to length)) + ;; handle negative indices + (when (< from 0) + (setq from (mod from length))) + (when (< to 0) + (setq to (mod to length))) + + ;; iterate through the list, keeping the elements we want + (while (< index to) + (when (>= index from) + (!cons (car list) new-list)) + (!cdr list) + (setq index (1+ index))) + (nreverse new-list))) + +(defun -take (n list) + "Returns a new list of the first N items in LIST, or all items if there are fewer than N." + (let (result) + (--dotimes n + (when list + (!cons (car list) result) + (!cdr list))) + (nreverse result))) + +(defun -drop (n list) + "Returns the tail of LIST without the first N items." + (--dotimes n (!cdr list)) + list) + +(defmacro --take-while (form list) + "Anaphoric form of `-take-while'." + (let ((r (make-symbol "result"))) + `(let (,r) + (--each-while ,list ,form (!cons it ,r)) + (nreverse ,r)))) + +(defun -take-while (pred list) + "Returns a new list of successive items from LIST while (PRED item) returns a non-nil value." + (--take-while (funcall pred it) list)) + +(defmacro --drop-while (form list) + "Anaphoric form of `-drop-while'." + (let ((l (make-symbol "list"))) + `(let ((,l ,list)) + (while (and ,l (let ((it (car ,l))) ,form)) + (!cdr ,l)) + ,l))) + +(defun -drop-while (pred list) + "Returns the tail of LIST starting from the first item for which (PRED item) returns nil." + (--drop-while (funcall pred it) list)) + +(defun -split-at (n list) + "Returns a list of ((-take N LIST) (-drop N LIST)), in no more than one pass through the list." + (let (result) + (--dotimes n + (when list + (!cons (car list) result) + (!cdr list))) + (list (nreverse result) list))) + +(defun -insert-at (n x list) + "Returns a list with X inserted into LIST at position N." + (let ((split-list (-split-at n list))) + (nconc (car split-list) (cons x (cadr split-list))))) + +(defmacro --split-with (pred list) + "Anaphoric form of `-split-with'." + (let ((l (make-symbol "list")) + (r (make-symbol "result")) + (c (make-symbol "continue"))) + `(let ((,l ,list) + (,r nil) + (,c t)) + (while (and ,l ,c) + (let ((it (car ,l))) + (if (not ,pred) + (setq ,c nil) + (!cons it ,r) + (!cdr ,l)))) + (list (nreverse ,r) ,l)))) + +(defun -split-with (pred list) + "Returns a list of ((-take-while PRED LIST) (-drop-while PRED LIST)), in no more than one pass through the list." + (--split-with (funcall pred it) list)) + +(defmacro --separate (form list) + "Anaphoric form of `-separate'." + (let ((y (make-symbol "yes")) + (n (make-symbol "no"))) + `(let (,y ,n) + (--each ,list (if ,form (!cons it ,y) (!cons it ,n))) + (list (nreverse ,y) (nreverse ,n))))) + +(defun -separate (pred list) + "Returns a list of ((-filter PRED LIST) (-remove PRED LIST)), in one pass through the list." + (--separate (funcall pred it) list)) + +(defun ---partition-all-in-steps-reversed (n step list) + "Private: Used by -partition-all-in-steps and -partition-in-steps." + (when (< step 1) + (error "Step must be a positive number, or you're looking at some juicy infinite loops.")) + (let ((result nil) + (len 0)) + (while list + (!cons (-take n list) result) + (setq list (-drop step list))) + result)) + +(defun -partition-all-in-steps (n step list) + "Returns a new list with the items in LIST grouped into N-sized sublists at offsets STEP apart. +The last groups may contain less than N items." + (nreverse (---partition-all-in-steps-reversed n step list))) + +(defun -partition-in-steps (n step list) + "Returns a new list with the items in LIST grouped into N-sized sublists at offsets STEP apart. +If there are not enough items to make the last group N-sized, +those items are discarded." + (let ((result (---partition-all-in-steps-reversed n step list))) + (while (and result (< (length (car result)) n)) + (!cdr result)) + (nreverse result))) + +(defun -partition-all (n list) + "Returns a new list with the items in LIST grouped into N-sized sublists. +The last group may contain less than N items." + (-partition-all-in-steps n n list)) + +(defun -partition (n list) + "Returns a new list with the items in LIST grouped into N-sized sublists. +If there are not enough items to make the last group N-sized, +those items are discarded." + (-partition-in-steps n n list)) + +(defmacro --partition-by (form list) + "Anaphoric form of `-partition-by'." + (let ((r (make-symbol "result")) + (s (make-symbol "sublist")) + (v (make-symbol "value")) + (n (make-symbol "new-value")) + (l (make-symbol "list"))) + `(let ((,l ,list)) + (when ,l + (let* ((,r nil) + (it (car ,l)) + (,s (list it)) + (,v ,form) + (,l (cdr ,l))) + (while ,l + (let* ((it (car ,l)) + (,n ,form)) + (unless (equal ,v ,n) + (!cons (nreverse ,s) ,r) + (setq ,s nil) + (setq ,v ,n)) + (!cons it ,s) + (!cdr ,l))) + (!cons (nreverse ,s) ,r) + (nreverse ,r)))))) + +(defun -partition-by (fn list) + "Applies FN to each item in LIST, splitting it each time FN returns a new value." + (--partition-by (funcall fn it) list)) + +(defmacro --partition-by-header (form list) + "Anaphoric form of `-partition-by-header'." + (let ((r (make-symbol "result")) + (s (make-symbol "sublist")) + (h (make-symbol "header-value")) + (b (make-symbol "seen-body?")) + (n (make-symbol "new-value")) + (l (make-symbol "list"))) + `(let ((,l ,list)) + (when ,l + (let* ((,r nil) + (it (car ,l)) + (,s (list it)) + (,h ,form) + (,b nil) + (,l (cdr ,l))) + (while ,l + (let* ((it (car ,l)) + (,n ,form)) + (if (equal ,h, n) + (when ,b + (!cons (nreverse ,s) ,r) + (setq ,s nil) + (setq ,b nil)) + (setq ,b t)) + (!cons it ,s) + (!cdr ,l))) + (!cons (nreverse ,s) ,r) + (nreverse ,r)))))) + +(defun -partition-by-header (fn list) + "Applies FN to the first item in LIST. That is the header + value. Applies FN to each item in LIST, splitting it each time + FN returns the header value, but only after seeing at least one + other value (the body)." + (--partition-by-header (funcall fn it) list)) + +(defmacro --group-by (form list) + "Anaphoric form of `-group-by'." + (let ((l (make-symbol "list")) + (v (make-symbol "value")) + (k (make-symbol "key")) + (r (make-symbol "result"))) + `(let ((,l ,list) + ,r) + ;; Convert `list' to an alist and store it in `r'. + (while ,l + (let* ((,v (car ,l)) + (it ,v) + (,k ,form) + (kv (assoc ,k ,r))) + (if kv + (setcdr kv (cons ,v (cdr kv))) + (push (list ,k ,v) ,r)) + (setq ,l (cdr ,l)))) + ;; Reverse lists in each group. + (let ((rest ,r)) + (while rest + (let ((kv (car rest))) + (setcdr kv (nreverse (cdr kv)))) + (setq rest (cdr rest)))) + ;; Reverse order of keys. + (nreverse ,r)))) + +(defun -group-by (fn list) + "Separate LIST into an alist whose keys are FN applied to the +elements of LIST. Keys are compared by `equal'." + (--group-by (funcall fn it) list)) + +(defun -interpose (sep list) + "Returns a new list of all elements in LIST separated by SEP." + (let (result) + (when list + (!cons (car list) result) + (!cdr list)) + (while list + (setq result (cons (car list) (cons sep result))) + (!cdr list)) + (nreverse result))) + +(defun -interleave (&rest lists) + "Returns a new list of the first item in each list, then the second etc." + (let (result) + (while (-none? 'null lists) + (--each lists (!cons (car it) result)) + (setq lists (-map 'cdr lists))) + (nreverse result))) + +(defmacro --zip-with (form list1 list2) + "Anaphoric form of `-zip-with'. + +The elements in list1 is bound as `it`, the elements in list2 as `other`." + (let ((r (make-symbol "result")) + (l1 (make-symbol "list1")) + (l2 (make-symbol "list2"))) + `(let ((,r nil) + (,l1 ,list1) + (,l2 ,list2)) + (while (and ,l1 ,l2) + (let ((it (car ,l1)) + (other (car ,l2))) + (!cons ,form ,r) + (!cdr ,l1) + (!cdr ,l2))) + (nreverse ,r)))) + +(defun -zip-with (fn list1 list2) + "Zip the two lists LIST1 and LIST2 using a function FN. This +function is applied pairwise taking as first argument element of +LIST1 and as second argument element of LIST2 at corresponding +position. + +The anaphoric form `--zip-with' binds the elements from LIST1 as `it`, +and the elements from LIST2 as `other`." + (--zip-with (funcall fn it other) list1 list2)) + +(defun -zip (list1 list2) + "Zip the two lists together. Return the list where elements +are cons pairs with car being element from LIST1 and cdr being +element from LIST2. The length of the returned list is the +length of the shorter one." + (-zip-with 'cons list1 list2)) + +(defun -partial (fn &rest args) + "Takes a function FN and fewer than the normal arguments to FN, +and returns a fn that takes a variable number of additional ARGS. +When called, the returned function calls FN with ARGS first and +then additional args." + (apply 'apply-partially fn args)) + +(defun -rpartial (fn &rest args) + "Takes a function FN and fewer than the normal arguments to FN, +and returns a fn that takes a variable number of additional ARGS. +When called, the returned function calls FN with the additional +args first and then ARGS. + +Requires Emacs 24 or higher." + `(closure (t) (&rest args) + (apply ',fn (append args ',args)))) + +(defun -applify (fn) + "Changes an n-arity function FN to a 1-arity function that +expects a list with n items as arguments" + (apply-partially 'apply fn)) + +(defmacro -> (x &optional form &rest more) + "Threads the expr through the forms. Inserts X as the second +item in the first form, making a list of it if it is not a list +already. If there are more forms, inserts the first form as the +second item in second form, etc." + (cond + ((null form) x) + ((null more) (if (listp form) + `(,(car form) ,x ,@(cdr form)) + (list form x))) + (:else `(-> (-> ,x ,form) ,@more)))) + +(defmacro ->> (x form &rest more) + "Threads the expr through the forms. Inserts X as the last item +in the first form, making a list of it if it is not a list +already. If there are more forms, inserts the first form as the +last item in second form, etc." + (if (null more) + (if (listp form) + `(,(car form) ,@(cdr form) ,x) + (list form x)) + `(->> (->> ,x ,form) ,@more))) + +(defmacro --> (x form &rest more) + "Threads the expr through the forms. Inserts X at the position +signified by the token `it' in the first form. If there are more +forms, inserts the first form at the position signified by `it' +in in second form, etc." + (if (null more) + (if (listp form) + (--map-when (eq it 'it) x form) + (list form x)) + `(--> (--> ,x ,form) ,@more))) + +(put '-> 'lisp-indent-function 1) +(put '->> 'lisp-indent-function 1) +(put '--> 'lisp-indent-function 1) + +(defmacro -when-let (var-val &rest body) + "If VAL evaluates to non-nil, bind it to VAR and execute body. +VAR-VAL should be a (VAR VAL) pair." + (let ((var (car var-val)) + (val (cadr var-val))) + `(let ((,var ,val)) + (when ,var + ,@body)))) + +(defmacro -when-let* (vars-vals &rest body) + "If all VALS evaluate to true, bind them to their corresponding + VARS and execute body. VARS-VALS should be a list of (VAR VAL) + pairs (corresponding to bindings of `let*')." + (if (= (length vars-vals) 1) + `(-when-let ,(car vars-vals) + ,@body) + `(-when-let ,(car vars-vals) + (-when-let* ,(cdr vars-vals) + ,@body)))) + +(defmacro --when-let (val &rest body) + "If VAL evaluates to non-nil, bind it to `it' and execute +body." + `(let ((it ,val)) + (when it + ,@body))) + +(defmacro -if-let (var-val then &optional else) + "If VAL evaluates to non-nil, bind it to VAR and do THEN, +otherwise do ELSE. VAR-VAL should be a (VAR VAL) pair." + (let ((var (car var-val)) + (val (cadr var-val))) + `(let ((,var ,val)) + (if ,var ,then ,else)))) + +(defmacro -if-let* (vars-vals then &optional else) + "If all VALS evaluate to true, bind them to their corresponding + VARS and do THEN, otherwise do ELSE. VARS-VALS should be a list + of (VAR VAL) pairs (corresponding to the bindings of `let*')." + (let ((first-pair (car vars-vals)) + (rest (cdr vars-vals))) + (if (= (length vars-vals) 1) + `(-if-let ,first-pair ,then ,else) + `(-if-let ,first-pair + (-if-let* ,rest ,then ,else) + ,else)))) + +(defmacro --if-let (val then &optional else) + "If VAL evaluates to non-nil, bind it to `it' and do THEN, +otherwise do ELSE." + `(let ((it ,val)) + (if it ,then ,else))) + +(put '-when-let 'lisp-indent-function 1) +(put '-when-let* 'lisp-indent-function 1) +(put '--when-let 'lisp-indent-function 1) +(put '-if-let 'lisp-indent-function 1) +(put '-if-let* 'lisp-indent-function 1) +(put '--if-let 'lisp-indent-function 1) + +(defun -distinct (list) + "Return a new list with all duplicates removed. +The test for equality is done with `equal', +or with `-compare-fn' if that's non-nil. + +Alias: `-uniq'" + (let (result) + (--each list (unless (-contains? result it) (!cons it result))) + (nreverse result))) + +(defun -union (list list2) + "Return a new list containing the elements of LIST1 and elements of LIST2 that are not in LIST1. +The test for equality is done with `equal', +or with `-compare-fn' if that's non-nil." + (let (result) + (--each list (!cons it result)) + (--each list2 (unless (-contains? result it) (!cons it result))) + (nreverse result))) + +(defalias '-uniq '-distinct) + +(defun -intersection (list list2) + "Return a new list containing only the elements that are members of both LIST and LIST2. +The test for equality is done with `equal', +or with `-compare-fn' if that's non-nil." + (--filter (-contains? list2 it) list)) + +(defun -difference (list list2) + "Return a new list with only the members of LIST that are not in LIST2. +The test for equality is done with `equal', +or with `-compare-fn' if that's non-nil." + (--filter (not (-contains? list2 it)) list)) + +(defvar -compare-fn nil + "Tests for equality use this function or `equal' if this is nil. +It should only be set using dynamic scope with a let, like: +(let ((-compare-fn =)) (-union numbers1 numbers2 numbers3)") + +(defun -contains? (list element) + "Return whether LIST contains ELEMENT. +The test for equality is done with `equal', +or with `-compare-fn' if that's non-nil." + (not + (null + (cond + ((null -compare-fn) (member element list)) + ((eq -compare-fn 'eq) (memq element list)) + ((eq -compare-fn 'eql) (memql element list)) + (t + (let ((lst list)) + (while (and lst + (not (funcall -compare-fn element (car lst)))) + (setq lst (cdr lst))) + lst)))))) + +(defalias '-contains-p '-contains?) + +(defun -sort (predicate list) + "Sort LIST, stably, comparing elements using PREDICATE. +Returns the sorted list. LIST is NOT modified by side effects. +PREDICATE is called with two elements of LIST, and should return non-nil +if the first element should sort before the second." + (sort (copy-sequence list) predicate)) + +(defmacro --sort (form list) + "Anaphoric form of `-sort'." + (declare (debug t)) + `(-sort (lambda (it other) ,form) ,list)) + +(defun -repeat (n x) + "Return a list with X repeated N times. +Returns nil if N is less than 1." + (let (ret) + (--dotimes n (!cons x ret)) + ret)) + +(defun -sum (list) + "Return the sum of LIST." + (apply '+ list)) + +(defun -product (list) + "Return the product of LIST." + (apply '* list)) + +(eval-after-load "lisp-mode" + '(progn + (let ((new-keywords '( + "--each" + "-each" + "--each-while" + "-each-while" + "--dotimes" + "-dotimes" + "-map" + "--map" + "--reduce-from" + "-reduce-from" + "--reduce" + "-reduce" + "--reduce-r-from" + "-reduce-r-from" + "--reduce-r" + "-reduce-r" + "--filter" + "-filter" + "-select" + "--select" + "--remove" + "-remove" + "-reject" + "--reject" + "--keep" + "-keep" + "-flatten" + "-concat" + "--mapcat" + "-mapcat" + "--first" + "-first" + "--any?" + "-any?" + "-some?" + "--some?" + "-any-p" + "--any-p" + "-some-p" + "--some-p" + "--all?" + "-all?" + "-every?" + "--every?" + "-all-p" + "--all-p" + "-every-p" + "--every-p" + "--none?" + "-none?" + "-none-p" + "--none-p" + "-only-some?" + "--only-some?" + "-only-some-p" + "--only-some-p" + "-take" + "-drop" + "--take-while" + "-take-while" + "--drop-while" + "-drop-while" + "-split-at" + "-insert-at" + "--split-with" + "-split-with" + "-partition" + "-partition-in-steps" + "-partition-all" + "-partition-all-in-steps" + "-interpose" + "-interleave" + "--zip-with" + "-zip-with" + "-zip" + "--map-indexed" + "-map-indexed" + "--map-when" + "-map-when" + "--replace-where" + "-replace-where" + "-partial" + "-rpartial" + "->" + "->>" + "-->" + "-when-let" + "-when-let*" + "--when-let" + "-if-let" + "-if-let*" + "--if-let" + "-distinct" + "-intersection" + "-difference" + "-contains?" + "-contains-p" + "-repeat" + "-cons*" + "-sum" + "-product" + )) + (special-variables '( + "it" + "it-index" + "acc" + "other" + ))) + (font-lock-add-keywords 'emacs-lisp-mode `((,(concat "\\<" (regexp-opt special-variables 'paren) "\\>") + 1 font-lock-variable-name-face)) 'append) + (font-lock-add-keywords 'emacs-lisp-mode `((,(concat "(\\s-*" (regexp-opt new-keywords 'paren) "\\>") + 1 font-lock-keyword-face)) 'append)) + (--each (buffer-list) + (with-current-buffer it + (when (and (eq major-mode 'emacs-lisp-mode) + (boundp 'font-lock-mode) + font-lock-mode) + (font-lock-refresh-defaults)))))) + +(provide 'dash) +;;; dash.el ends here diff --git a/emacs.d/elpa/dash-1.5.0/dash.elc b/emacs.d/elpa/dash-1.5.0/dash.elc new file mode 100644 index 0000000..06a3f6e Binary files /dev/null and b/emacs.d/elpa/dash-1.5.0/dash.elc differ diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl-autoloads.el b/emacs.d/elpa/grizzl-0.1.1/grizzl-autoloads.el new file mode 100644 index 0000000..58c39db --- /dev/null +++ b/emacs.d/elpa/grizzl-0.1.1/grizzl-autoloads.el @@ -0,0 +1,85 @@ +;;; grizzl-autoloads.el --- automatically extracted autoloads +;; +;;; Code: + + +;;;### (autoloads (grizzl-result-strings grizzl-result-count grizzl-search +;;;;;; grizzl-make-index) "grizzl-core" "grizzl-core.el" (21002 +;;;;;; 10325 0 0)) +;;; Generated autoloads from grizzl-core.el + +(autoload 'grizzl-make-index "grizzl-core" "\ +Makes an index from the list STRINGS for use with `grizzl-search'. + +If :PROGRESS-FN is given as a keyword argument, it is called repeatedly +with integers N and TOTAL. + +If :CASE-SENSITIVE is specified as a non-nil keyword argument, the index +will be created case-sensitive, otherwise it will be case-insensitive. + +\(fn STRINGS &rest OPTIONS)" nil nil) + +(autoload 'grizzl-search "grizzl-core" "\ +Fuzzy searches for TERM in INDEX prepared with `grizzl-make-index'. + +OLD-RESULT may be specified as an existing search result to increment from. +The result can be read with `grizzl-result-strings'. + +\(fn TERM INDEX &optional OLD-RESULT)" nil nil) + +(autoload 'grizzl-result-count "grizzl-core" "\ +Returns the number of matches present in RESULT. + +\(fn RESULT)" nil nil) + +(autoload 'grizzl-result-strings "grizzl-core" "\ +Returns the ordered list of matched strings in RESULT, using INDEX. + +If the :START option is specified, results are read from the given offset. +If the :END option is specified, up to :END results are returned. + +\(fn RESULT INDEX &rest OPTIONS)" nil nil) + +;;;*** + +;;;### (autoloads (grizzl-set-selection-1 grizzl-set-selection+1 +;;;;;; grizzl-selected-result grizzl-completing-read) "grizzl-read" +;;;;;; "grizzl-read.el" (21002 10325 0 0)) +;;; Generated autoloads from grizzl-read.el + +(autoload 'grizzl-completing-read "grizzl-read" "\ +Performs a completing-read in the minibuffer using INDEX to fuzzy search. +Each key pressed in the minibuffer filters down the list of matches. + +\(fn PROMPT INDEX)" nil nil) + +(autoload 'grizzl-selected-result "grizzl-read" "\ +Get the selected string from INDEX in a `grizzl-completing-read'. + +\(fn INDEX)" nil nil) + +(autoload 'grizzl-set-selection+1 "grizzl-read" "\ +Move the selection up one row in `grizzl-completing-read'. + +\(fn)" t nil) + +(autoload 'grizzl-set-selection-1 "grizzl-read" "\ +Move the selection down one row in `grizzl-completing-read'. + +\(fn)" t nil) + +;;;*** + +;;;### (autoloads nil nil ("grizzl-pkg.el" "grizzl.el") (21002 10325 +;;;;;; 472906 0)) + +;;;*** + +(provide 'grizzl-autoloads) +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; grizzl-autoloads.el ends here diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl-core.el b/emacs.d/elpa/grizzl-0.1.1/grizzl-core.el new file mode 100644 index 0000000..8c59b8b --- /dev/null +++ b/emacs.d/elpa/grizzl-0.1.1/grizzl-core.el @@ -0,0 +1,226 @@ +;;; grizzl-core.el --- Fast fuzzy search index for Emacs. + +;; Copyright © 2013 Chris Corbyn +;; +;; Author: Chris Corbyn +;; URL: https://github.com/d11wtq/grizzl +;; Version: 0.1.1 +;; Keywords: convenience, usability + +;; This file is NOT part of GNU Emacs. + +;;; --- License + +;; Licensed under the same terms as Emacs. + +;;; --- Commentary + +;; Grizzl provides a fuzzy completion framework for general purpose +;; use in Emacs Lisp projects. +;; +;; grizzl-core.el provides the underlying data structures and sesrch +;; algorithm without any UI attachment. At the core, a fuzzy search +;; index is created from a list of strings, using `grizzl-make-index'. +;; A fuzzy search term is then used to get a result from this index +;; with `grizzl-search'. Because grizzl considers the usage of a +;; fuzzy search index to operate in real-time as a user enters a +;; search term in the minibuffer, the framework optimizes for this use +;; case. Any result can be passed back into `grizzl-search' as a hint +;; to continue searching. The search algorithm is able to understand +;; insertions and deletions and therefore minimizes the work it needs +;; to do in this case. The intended use here is to collect a result +;; on each key press and feed that result into the search for the next +;; key press. Once a search is complete, the matched strings are then +;; read, using `grizzl-result-strings'. The results are ordered on the +;; a combination of the Levenshtein Distance and a character-proximity +;; scoring calculation. This means shorter strings are favoured, but +;; adjacent letters are more heavily favoured. +;; +;; It is assumed that the index will be re-used across multiple +;; searches on larger sets of data. +;; +;; + +(eval-when-compile + (require 'cl-lib)) + +;;; --- Public Functions + +;;;###autoload +(defun grizzl-make-index (strings &rest options) + "Makes an index from the list STRINGS for use with `grizzl-search'. + +If :PROGRESS-FN is given as a keyword argument, it is called repeatedly +with integers N and TOTAL. + +If :CASE-SENSITIVE is specified as a non-nil keyword argument, the index +will be created case-sensitive, otherwise it will be case-insensitive." + (let ((lookup-table (make-hash-table)) + (total-strs (length strings)) + (case-sensitive (plist-get options :case-sensitive)) + (progress-fn (plist-get options :progress-fn)) + (string-data (vconcat (mapcar (lambda (s) + (cons s (length s))) + strings)))) + (reduce (lambda (list-offset str) + (grizzl-index-insert str list-offset lookup-table + :case-sensitive case-sensitive) + (when progress-fn + (funcall progress-fn (1+ list-offset) total-strs)) + (1+ list-offset)) + strings + :initial-value 0) + (maphash (lambda (char str-map) + (maphash (lambda (list-offset locations) + (puthash list-offset (reverse locations) str-map)) + str-map)) lookup-table) + `((case-sensitive . ,case-sensitive) + (lookup-table . ,lookup-table) + (string-data . ,string-data)))) + +;;;###autoload +(defun grizzl-search (term index &optional old-result) + "Fuzzy searches for TERM in INDEX prepared with `grizzl-make-index'. + +OLD-RESULT may be specified as an existing search result to increment from. +The result can be read with `grizzl-result-strings'." + (let* ((cased-term (if (grizzl-index-case-sensitive-p index) + term + (downcase term))) + (result (grizzl-rewind-result cased-term index old-result)) + (matches (copy-hash-table (grizzl-result-matches result))) + (from-pos (length (grizzl-result-term result))) + (remainder (substring cased-term from-pos)) + (lookup-table (grizzl-lookup-table index))) + (reduce (lambda (acc-res ch) + (let ((sub-table (gethash ch lookup-table))) + (if (not sub-table) + (clrhash matches) + (grizzl-search-increment sub-table matches)) + (grizzl-cons-result cased-term matches acc-res))) + remainder + :initial-value result))) + +;;;###autoload +(defun grizzl-result-count (result) + "Returns the number of matches present in RESULT." + (hash-table-count (grizzl-result-matches result))) + +;;;###autoload +(defun grizzl-result-strings (result index &rest options) + "Returns the ordered list of matched strings in RESULT, using INDEX. + +If the :START option is specified, results are read from the given offset. +If the :END option is specified, up to :END results are returned." + (let* ((matches (grizzl-result-matches result)) + (strings (grizzl-index-strings index)) + (loaded '()) + (start (plist-get options :start)) + (end (plist-get options :end))) + (maphash (lambda (string-offset char-offset) + (push string-offset loaded)) + matches) + (let* ((ordered (sort loaded + (lambda (a b) + (< (cadr (gethash a matches)) + (cadr (gethash b matches)))))) + (best (if (or start end) + (delete-if-not 'identity + (subseq ordered (or start 0) end)) + ordered))) + (mapcar (lambda (n) + (car (elt strings n))) + best)))) + +;;; --- Private Functions + +(defun grizzl-cons-result (term matches results) + "Build a new result for TERM and hash-table MATCHES consed with RESULTS." + (cons (cons term matches) results)) + +(defun grizzl-rewind-result (term index result) + "Adjusts RESULT according to TERM, ready for a new search." + (if result + (let* ((old-term (grizzl-result-term result)) + (new-len (length term)) + (old-len (length old-term))) + (if (and (>= new-len old-len) + (string-equal old-term (substring term 0 old-len))) + result + (grizzl-rewind-result term index (cdr result)))) + (grizzl-cons-result "" (grizzl-base-matches index) nil))) + +(defun grizzl-base-matches (index) + "Returns the full set of matches in INDEX, with an out-of-bound offset." + (let ((matches (make-hash-table))) + (reduce (lambda (n s-len) + (puthash n (list -1 0 (cdr s-len)) matches) + (1+ n)) + (grizzl-index-strings index) + :initial-value 0) + matches)) + +(defun grizzl-result-term (result) + "Returns the search term used to find the matches in RESULT." + (car (car result))) + +(defun grizzl-result-matches (result) + "Returns the internal hash used to track the matches in RESULT." + (cdar result)) + +(defun grizzl-index-insert (string list-offset index &rest options) + "Inserts STRING at LIST-OFFSET into INDEX." + (let ((case-sensitive (plist-get options :case-sensitive))) + (reduce (lambda (char-offset cs-char) + (let* ((char (if case-sensitive + cs-char + (downcase cs-char))) + (str-map (or (gethash char index) + (puthash char (make-hash-table) index))) + (offsets (gethash list-offset str-map))) + (puthash list-offset + (cons char-offset offsets) + str-map) + (1+ char-offset))) + string + :initial-value 0))) + +(defun grizzl-lookup-table (index) + "Returns the lookup table portion of INDEX." + (cdr (assoc 'lookup-table index))) + +(defun grizzl-index-strings (index) + "Returns the vector of strings stored in INDEX." + (cdr (assoc 'string-data index))) + +(defun grizzl-index-case-sensitive-p (index) + "Predicate to test of INDEX is case-sensitive." + (cdr (assoc 'case-sensitive index))) + +(defun grizzl-search-increment (sub-table result) + "Use the search lookup table to filter already-accumulated results." + (cl-flet ((next-offset (key current sub-table) + (find-if (lambda (v) + (> v current)) + (gethash key sub-table)))) + (maphash (lambda (k v) + (let* ((oldpos (car v)) + (oldrank (cadr v)) + (len (caddr v)) + (newpos (next-offset k oldpos sub-table))) + (if newpos + (puthash k (list newpos + (grizzl-inc-rank oldrank oldpos newpos len) + len) + result) + (remhash k result)))) + result))) + +(defun grizzl-inc-rank (oldrank oldpos newpos len) + "Increment the current match distance as a new char is matched." + (let ((distance (if (< oldpos 0) 1 (- newpos oldpos)))) + (+ oldrank (* len (* distance distance))))) + +(provide 'grizzl-core) + +;;; grizzl-core.el ends here diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl-core.elc b/emacs.d/elpa/grizzl-0.1.1/grizzl-core.elc new file mode 100644 index 0000000..9d43cfd Binary files /dev/null and b/emacs.d/elpa/grizzl-0.1.1/grizzl-core.elc differ diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl-pkg.el b/emacs.d/elpa/grizzl-0.1.1/grizzl-pkg.el new file mode 100644 index 0000000..e296607 --- /dev/null +++ b/emacs.d/elpa/grizzl-0.1.1/grizzl-pkg.el @@ -0,0 +1,3 @@ +(define-package "grizzl" "0.1.1" + "Fuzzy Search Library & Completing Read" + '((cl-lib "0.1"))) diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl-pkg.elc b/emacs.d/elpa/grizzl-0.1.1/grizzl-pkg.elc new file mode 100644 index 0000000..225cc6f Binary files /dev/null and b/emacs.d/elpa/grizzl-0.1.1/grizzl-pkg.elc differ diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl-read.el b/emacs.d/elpa/grizzl-0.1.1/grizzl-read.el new file mode 100644 index 0000000..e08a2c2 --- /dev/null +++ b/emacs.d/elpa/grizzl-0.1.1/grizzl-read.el @@ -0,0 +1,186 @@ +;;; grizzl-read.el --- A fuzzy completing-read backed by grizzl. + +;; Copyright © 2013 Chris Corbyn +;; +;; Author: Chris Corbyn +;; URL: https://github.com/d11wtq/grizzl +;; Version: 0.1.1 +;; Keywords: convenience, usability + +;; This file is NOT part of GNU Emacs. + +;;; --- License + +;; Licensed under the same terms as Emacs. + +;;; --- Commentary + +;; grizzl-read.el provides an implementation of the built-in Emacs +;; completing-read function, except it is backed by the grizzl fuzzy +;; search index. The goals are similar to ido-mode and helm, but grizzl +;; is heavily optimized for large data-sets, and as-such uses a +;; persistent fuzzy search index in its algorithm. +;; +;; The indexing and searching algorithm itself is defined in grizzl-core.el +;; with grizzl-read.el simply wrapping the search in a minibuffer with a +;; minor-mode defined. +;; +;; ---- Usage +;; +;; Call `grizzl-completing-read' with an index returned by +;; `grizzl-make-index': +;; +;; (defvar *index* (grizzl-make-index '("one" "two" "three"))) +;; (grizzl-completing-read "Number: " index) +;; +;; When the user hits ENTER, either one of the strings is returned on +;; success, or nil of nothing matched. +;; +;; The arrow keys can be used to navigate within the results. +;; + +(eval-when-compile + (require 'cl-lib)) + +;;; --- Configuration Variables + +(defvar *grizzl-read-max-results* 10 + "The maximum number of results to show in `grizzl-completing-read'.") + +;;; --- Runtime Processing Variables + +(defvar *grizzl-current-result* nil + "The search result in `grizzl-completing-read'.") + +(defvar *grizzl-current-selection* 0 + "The selected offset in `grizzl-completing-read'.") + +;;; --- Minor Mode Definition + +(defvar *grizzl-keymap* (make-sparse-keymap) + "Internal keymap used by the minor-mode in `grizzl-completing-read'.") + +(define-key *grizzl-keymap* (kbd "") 'grizzl-set-selection+1) +(define-key *grizzl-keymap* (kbd "C-p") 'grizzl-set-selection+1) +(define-key *grizzl-keymap* (kbd "") 'grizzl-set-selection-1) +(define-key *grizzl-keymap* (kbd "C-n") 'grizzl-set-selection-1) + +(define-minor-mode grizzl-mode + "Toggle the internal mode used by `grizzl-completing-read'." + nil + " Grizzl" + *grizzl-keymap*) + +;;; --- Public Functions + +;;;###autoload +(defun grizzl-completing-read (prompt index) + "Performs a completing-read in the minibuffer using INDEX to fuzzy search. +Each key pressed in the minibuffer filters down the list of matches." + (minibuffer-with-setup-hook + (lambda () + (setq *grizzl-current-result* nil) + (setq *grizzl-current-selection* 0) + (grizzl-mode 1) + (lexical-let* + ((hookfun (lambda () + (setq *grizzl-current-result* + (grizzl-search (minibuffer-contents) + index + *grizzl-current-result*)) + (grizzl-display-result index prompt))) + (exitfun (lambda () + (grizzl-mode -1) + (remove-hook 'post-command-hook hookfun t)))) + (add-hook 'minibuffer-exit-hook exitfun nil t) + (add-hook 'post-command-hook hookfun nil t))) + (read-from-minibuffer ">>> ") + (grizzl-selected-result index))) + +;;;###autoload +(defun grizzl-selected-result (index) + "Get the selected string from INDEX in a `grizzl-completing-read'." + (elt (grizzl-result-strings *grizzl-current-result* index + :start 0 + :end *grizzl-read-max-results*) + (grizzl-current-selection))) + +;;;###autoload +(defun grizzl-set-selection+1 () + "Move the selection up one row in `grizzl-completing-read'." + (interactive) + (grizzl-move-selection 1)) + +;;;###autoload +(defun grizzl-set-selection-1 () + "Move the selection down one row in `grizzl-completing-read'." + (interactive) + (grizzl-move-selection -1)) + +;;; --- Private Functions + +(defun grizzl-move-selection (delta) + "Move the selection by DELTA rows in `grizzl-completing-read'." + (setq *grizzl-current-selection* (+ (grizzl-current-selection) delta)) + (when (not (= (grizzl-current-selection) *grizzl-current-selection*)) + (beep))) + +(defun grizzl-display-result (index prompt) + "Renders a series of overlays to list the matches in the result." + (let* ((matches (grizzl-result-strings *grizzl-current-result* index + :start 0 + :end *grizzl-read-max-results*))) + (delete-all-overlays) + (overlay-put (make-overlay (point-min) (point-min)) + 'before-string + (format "%s\n%s\n" + (mapconcat 'identity + (grizzl-map-format-matches matches) + "\n") + (grizzl-format-prompt-line prompt))) + (set-window-text-height nil (max 3 (+ 2 (length matches)))))) + +(defun grizzl-map-format-matches (matches) + "Convert the set of string MATCHES into propertized text objects." + (if (= 0 (length matches)) + (list (propertize "-- NO MATCH --" 'face 'outline-3)) + (cdr (reduce (lambda (acc str) + (let* ((idx (car acc)) + (lst (cdr acc)) + (sel (= idx (grizzl-current-selection)))) + (cons (1+ idx) + (cons (grizzl-format-match str sel) lst)))) + matches + :initial-value '(0))))) + +(defun grizzl-format-match (match-str selected) + "Default match string formatter in `grizzl-completing-read'. + +MATCH-STR is the string in the selection list and SELECTED is non-nil +if this is the current selection." + (let ((margin (if selected "> " " ")) + (face (if selected 'diredp-symlink 'default))) + (propertize (format "%s%s" margin match-str) 'face face))) + +(defun grizzl-format-prompt-line (prompt) + "Returns a string to render a full-width prompt in `grizzl-completing-read'." + (let* ((count (grizzl-result-count *grizzl-current-result*)) + (match-info (format " (%d candidate%s) ---- *-" + count (if (= count 1) "" "s")))) + (concat (propertize (format "-*%s *-" prompt) 'face 'modeline-inactive) + (propertize " " + 'face 'modeline-inactive + 'display `(space :align-to (- right + ,(1+ (length match-info))))) + (propertize match-info 'face 'modeline-inactive)))) + +(defun grizzl-current-selection () + "Get the currently selected index in `grizzl-completing-read'." + (let ((max-selection + (min (1- *grizzl-read-max-results*) + (1- (grizzl-result-count *grizzl-current-result*))))) + (max 0 (min max-selection *grizzl-current-selection*)))) + +(provide 'grizzl-read) + +;;; grizzl-read.el ends here diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl-read.elc b/emacs.d/elpa/grizzl-0.1.1/grizzl-read.elc new file mode 100644 index 0000000..bd96873 Binary files /dev/null and b/emacs.d/elpa/grizzl-0.1.1/grizzl-read.elc differ diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl.el b/emacs.d/elpa/grizzl-0.1.1/grizzl.el new file mode 100644 index 0000000..e60212c --- /dev/null +++ b/emacs.d/elpa/grizzl-0.1.1/grizzl.el @@ -0,0 +1,26 @@ +;;; grizzl.el --- Fast fuzzy search index for Emacs. + +;; Copyright © 2013 Chris Corbyn +;; +;; Author: Chris Corbyn +;; URL: https://github.com/d11wtq/grizzl +;; Version: 0.1.1 +;; Keywords: convenience, usability + +;; This file is NOT part of GNU Emacs. + +;;; --- License + +;; Licensed under the same terms as Emacs. + +;;; --- Commentary + +;; This package is broken into separate files. +;; + +(require 'grizzl-core) +(require 'grizzl-read) + +(provide 'grizzl) + +;;; grizzl.el ends here diff --git a/emacs.d/elpa/grizzl-0.1.1/grizzl.elc b/emacs.d/elpa/grizzl-0.1.1/grizzl.elc new file mode 100644 index 0000000..0db5e59 Binary files /dev/null and b/emacs.d/elpa/grizzl-0.1.1/grizzl.elc differ diff --git a/emacs.d/elpa/projectile-0.9.2/projectile-autoloads.el b/emacs.d/elpa/projectile-0.9.2/projectile-autoloads.el new file mode 100644 index 0000000..dc2b1ae --- /dev/null +++ b/emacs.d/elpa/projectile-0.9.2/projectile-autoloads.el @@ -0,0 +1,52 @@ +;;; projectile-autoloads.el --- automatically extracted autoloads +;; +;;; Code: + + +;;;### (autoloads (projectile-global-mode projectile-mode) "projectile" +;;;;;; "projectile.el" (21002 9890 0 0)) +;;; Generated autoloads from projectile.el + +(autoload 'projectile-mode "projectile" "\ +Minor mode to assist project management and navigation. + +\\{projectile-mode-map} + +\(fn &optional ARG)" t nil) + +(defvar projectile-global-mode nil "\ +Non-nil if Projectile-Global mode is enabled. +See the command `projectile-global-mode' for a description of this minor mode. +Setting this variable directly does not take effect; +either customize it (see the info node `Easy Customization') +or call the function `projectile-global-mode'.") + +(custom-autoload 'projectile-global-mode "projectile" nil) + +(autoload 'projectile-global-mode "projectile" "\ +Toggle Projectile mode in all buffers. +With prefix ARG, enable Projectile-Global mode if ARG is positive; +otherwise, disable it. If called from Lisp, enable the mode if +ARG is omitted or nil. + +Projectile mode is enabled in all buffers where +`projectile-on' would do it. +See `projectile-mode' for more information on Projectile mode. + +\(fn &optional ARG)" t nil) + +;;;*** + +;;;### (autoloads nil nil ("projectile-pkg.el") (21002 9890 671493 +;;;;;; 0)) + +;;;*** + +(provide 'projectile-autoloads) +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; projectile-autoloads.el ends here diff --git a/emacs.d/elpa/projectile-0.9.2/projectile-pkg.el b/emacs.d/elpa/projectile-0.9.2/projectile-pkg.el new file mode 100644 index 0000000..9d4df7e --- /dev/null +++ b/emacs.d/elpa/projectile-0.9.2/projectile-pkg.el @@ -0,0 +1 @@ +(define-package "projectile" "0.9.2" "Manage and navigate projects in Emacs easily" (quote ((s "1.0.0") (dash "1.0.0")))) diff --git a/emacs.d/elpa/projectile-0.9.2/projectile-pkg.elc b/emacs.d/elpa/projectile-0.9.2/projectile-pkg.elc new file mode 100644 index 0000000..8124c40 Binary files /dev/null and b/emacs.d/elpa/projectile-0.9.2/projectile-pkg.elc differ diff --git a/emacs.d/elpa/projectile-0.9.2/projectile.el b/emacs.d/elpa/projectile-0.9.2/projectile.el new file mode 100644 index 0000000..98da514 --- /dev/null +++ b/emacs.d/elpa/projectile-0.9.2/projectile.el @@ -0,0 +1,1015 @@ +;;; projectile.el --- Manage and navigate projects in Emacs easily + +;; Copyright © 2011-2013 Bozhidar Batsov + +;; Author: Bozhidar Batsov +;; URL: https://github.com/bbatsov/projectile +;; Keywords: project, convenience +;; Version: 0.9.2 +;; Package-Requires: ((s "1.0.0") (dash "1.0.0")) + +;; This file is NOT part of GNU Emacs. + +;;; License: + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. +;; +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: +;; +;; This library provides easy project management and navigation. The +;; concept of a project is pretty basic - just a folder containing +;; special file. Currently git, mercurial and bazaar repos are +;; considered projects by default. If you want to mark a folder +;; manually as a project just create an empty .projectile file in +;; it. See the README for more details. +;; +;;; Code: + +;; requires +(require 'cl) +(require 'easymenu) +(require 'thingatpt) +(require 's) +(require 'dash) +(require 'grep) + +(defgroup projectile nil + "Manage and navigate projects easily." + :group 'tools + :group 'convenience) + +(defconst projectile-current-version "0.9.1" + "The current Projectile version.") + +(defcustom projectile-use-native-indexing (eq system-type 'windows-nt) + "Use native Emacs Lisp project indexing." + :group 'projectile + :type 'boolean) + +(defcustom projectile-enable-caching projectile-use-native-indexing + "Enable project files caching." + :group 'projectile + :type 'boolean) + +(defcustom projectile-require-project-root t + "Require the presence of a project root to operate when true. +Otherwise consider the current directory the project root." + :group 'projectile + :type 'boolean) + +(defcustom projectile-completion-system 'ido + "The completion system to be used by Projectile." + :group 'projectile + :type 'symbol + :options '(ido grizzl default)) + +(defcustom projectile-ack-function 'ack-and-a-half + "The ack function to use." + :group 'projectile + :type 'symbol + :options '(ack-and-a-half default)) + +(defcustom projectile-keymap-prefix (kbd "C-c p") + "Projectile keymap prefix." + :group 'projectile + :type 'string) + +(defcustom projectile-cache-file + (expand-file-name "projectile.cache" user-emacs-directory) + "The name of Projectile's cache file." + :group 'projectile + :type 'string) + +(defcustom projectile-tags-command "ctags -Re %s %s" + "The command Projectile's going to use to generate a TAGS file." + :group 'projectile + :type 'string) + +;; variables +(defvar projectile-project-root-files + '(".projectile" "project.clj" ".git" ".hg" ".fslckout" ".bzr" "_darcs" + "rebar.config" "pom.xml" "build.sbt" "Gemfile" "Makefile") + "A list of files considered to mark the root of a project.") + +(defvar projectile-globally-ignored-files + '("TAGS") + "A list of files globally ignored by projectile.") + +(defvar projectile-globally-ignored-directories + '(".idea" ".eunit" ".git" ".hg" ".fslckout" ".bzr" "_darcs") + "A list of directories globally ignored by projectile.") + +(defvar projectile-find-file-hook nil + "Hooks run when a file is opened with `projectile-find-file'.") + +(defvar projectile-find-dir-hook nil + "Hooks run when a directory is opened with `projectile-find-dir'.") + +(defun projectile-serialize (data filename) + "Serialize DATA to FILENAME. + +The saved data can be restored with `projectile-unserialize'." + (when (file-writable-p filename) + (with-temp-file filename + (insert (prin1-to-string data))))) + +(defun projectile-unserialize (filename) + "Read data serialized by `projectile-serialize' from FILENAME." + (when (file-exists-p filename) + (with-temp-buffer + (insert-file-contents filename) + (read (buffer-string))))) + +(defvar projectile-projects-cache + (or (projectile-unserialize projectile-cache-file) + (make-hash-table :test 'equal)) + "A hashmap used to cache project file names to speed up related operations.") + +(defvar projectile-known-projects nil + "List of locations where we have previously seen projects. +The list of projects is ordered by the time they have been accessed.") + +(defcustom projectile-known-projects-file + (expand-file-name "projectile-bookmarks.eld" + user-emacs-directory) + "Name and location of the Projectile's known projects file." + :group 'projectile + :type 'string) + +(defun projectile-version () + "Reports the version of Projectile in use." + (interactive) + (message "Projectile (version %s) 2011-2013 Bozhidar Batsov " + projectile-current-version)) + +(defun projectile-invalidate-cache (arg) + "Remove the current project's files from `projectile-projects-cache'. + +With a prefix argument ARG prompts for the name of the project whose cache +to invalidate." + (interactive "P") + (let ((project-root + (if arg + (completing-read "Remove cache for: " + (projectile-hash-keys projectile-projects-cache)) + (projectile-project-root)))) + (remhash project-root projectile-projects-cache) + (projectile-serialize-cache) + (message "Invalidated Projectile cache for %s." + (propertize project-root 'face 'font-lock-keyword-face)))) + +(defun projectile-cache-project (project files) + "Cache PROJECTs FILES. +The cache is created both in memory and on the hard drive." + (when projectile-enable-caching + (puthash project files projectile-projects-cache) + (projectile-serialize-cache))) + +(defun projectile-project-root () + "Retrieves the root directory of a project if available. +The current directory is assumed to be the project's root otherwise." + (let ((project-root + (or (->> projectile-project-root-files + (--map (locate-dominating-file default-directory it)) + (-remove #'null) + (car) + (projectile-expand-file-name)) + (if projectile-require-project-root + (error "You're not into a project") + default-directory)))) + project-root)) + +(defun projectile-expand-file-name (file-name) + "A thin wrapper around `expand-file-name' that handles nil. +Expand FILE-NAME using `default-directory'." + (when file-name + (expand-file-name file-name))) + +(defun projectile-project-p () + "Check if we're in a project." + (condition-case nil + (projectile-project-root) + (error nil))) + +(defun projectile-project-name () + "Return project name." + (let ((project-root + (condition-case nil + (projectile-project-root) + (error default-directory)))) + (file-name-nondirectory (directory-file-name project-root)))) + +(defun projectile-get-project-directories () + "Get the list of project directories that are of interest to the user." + (-map (lambda (subdir) (concat (projectile-project-root) subdir)) + (or (car (projectile-parse-dirconfig-file)) '("")))) + +(defun projectile-dir-files (directory) + "List the files in DIRECTORY and in its sub-directories. +Files are returned as relative paths to the project root." + ;; check for a cache hit first if caching is enabled + (let ((files-list (and projectile-enable-caching + (gethash directory projectile-projects-cache))) + (root (projectile-project-root))) + ;; cache disabled or cache miss + (or files-list + (if projectile-use-native-indexing + (projectile-dir-files-native root directory) + ;; use external tools to get the project files + (projectile-dir-files-external root directory))))) + +(defun projectile-dir-files-native (root directory) + "Get the files for ROOT under DIRECTORY using just Emacs Lisp." + (message "Projectile is indexing %s. This may take a while." + (propertize directory 'face 'font-lock-keyword-face)) + ;; we need the files with paths relative to the project root + (-map (lambda (file) (s-chop-prefix root file)) + (projectile-index-directory directory (projectile-patterns-to-ignore)))) + +(defun projectile-dir-files-external (root directory) + "Get the files for ROOT under DIRECTORY using external tools." + (let ((default-directory directory) + (files-list nil)) + (setq files-list (-map (lambda (f) + (s-chop-prefix root (expand-file-name f directory))) + (projectile-get-repo-files))) + files-list)) + +(defun projectile-file-cached-p (file project) + "Check if FILE is already in PROJECT cache." + (member file (gethash project projectile-projects-cache))) + +(defun projectile-cache-current-file () + "Add the currently visited file to the cache." + (interactive) + (let* ((current-project (projectile-project-root)) + (current-file (file-relative-name (buffer-file-name (current-buffer)) current-project))) + (unless (projectile-file-cached-p current-file current-project) + (puthash current-project + (cons current-file (gethash current-project projectile-projects-cache)) + projectile-projects-cache) + (projectile-serialize-cache) + (message "File %s added to project %s cache." current-file current-project)))) + +;; cache opened files automatically to reduce the need for cache invalidation +(defun projectile-cache-files-find-file-hook () + "Function for caching files with `find-file-hook'." + (when (and (projectile-project-p) projectile-enable-caching) + (projectile-cache-current-file))) + +(defun projectile-cache-projects-find-file-hook () + "Function for caching projects with `find-file-hook'." + (when (projectile-project-p) + (projectile-add-known-project (projectile-project-root)) + (projectile-save-known-projects))) + +(defcustom projectile-git-command "git ls-files -zco --exclude-standard" + "Command used by projectile to get the files in a git project." + :group 'projectile + :type 'string) + +(defcustom projectile-hg-command "hg locate -0 -I ." + "Command used by projectile to get the files in a hg project." + :group 'projectile + :type 'string) + +(defcustom projectile-fossil-command "fossil ls" + "Command used by projectile to get the files in a fossil project." + :group 'projectile + :type 'string) + +(defcustom projectile-bzr-command "bzr ls --versioned -0" + "Command used by projectile to get the files in a bazaar project." + :group 'projectile + :type 'string) + +(defcustom projectile-darcs-command "darcs show files -0 . " + "Command used by projectile to get the files in a darcs project." + :group 'projectile + :type 'string) + +(defcustom projectile-svn-command "find . -type f -print0" + "Command used by projectile to get the files in a svn project." + :group 'projectile + :type 'string) + +(defcustom projectile-generic-command "find . -type f -print0" + "Command used by projectile to get the files in a generic project." + :group 'projectile + :type 'string) + +(defun projectile-get-ext-command () + "Determine which external command to invoke based on the project's VCS." + (let ((vcs (projectile-project-vcs))) + (cond + ((eq vcs 'git) projectile-git-command) + ((eq vcs 'hg) projectile-hg-command) + ((eq vcs 'fossil) projectile-fossil-command) + ((eq vcs 'bzr) projectile-bzr-command) + ((eq vcs 'darcs) projectile-darcs-command) + ((eq vcs 'svn) projectile-svn-command) + (t projectile-generic-command)))) + +(defun projectile-get-repo-files () + "Get a list of the files in the project." + (projectile-files-via-ext-command (projectile-get-ext-command))) + +(defun projectile-files-via-ext-command (command) + "Get a list of relative file names in the project root by executing COMMAND." + (split-string (shell-command-to-string command) "\0" t)) + +(defun projectile-index-directory (directory patterns) + "Index DIRECTORY taking into account PATTERNS. +The function calls itself recursively until all sub-directories +have been indexed." + (let (files-list) + (dolist (current-file (file-name-all-completions "" directory) files-list) + (let ((absolute-file (expand-file-name current-file directory))) + (cond + ;; check for directories that are not ignored + ((and (s-ends-with-p "/" current-file) + ;; avoid loops & ignore some well known directories + (not (-any? (lambda (file) + (string= (s-chop-suffix "/" current-file) file)) + '("." ".." ".svn" ".cvs"))) + (not (projectile-ignored-directory-p absolute-file)) + (not (and patterns + (projectile-ignored-rel-p directory + absolute-file patterns)))) + (setq files-list (append files-list + (projectile-index-directory + (expand-file-name current-file directory) + patterns)))) + ;; check for regular files that are not ignored + ((and (not (s-ends-with-p "/" current-file)) + (not (projectile-ignored-file-p absolute-file)) + (not (and patterns + (projectile-ignored-rel-p directory + absolute-file patterns)))) + (setq files-list (cons + (expand-file-name current-file directory) + files-list)))))))) + +(defun projectile-project-buffers () + "Get a list of project buffers." + (let ((project-root (projectile-project-root))) + (-filter (lambda (buffer) + (projectile-project-buffer-p buffer project-root)) + (buffer-list)))) + +(defun projectile-project-buffer-p (buffer project-root) + "Check if BUFFER is under PROJECT-ROOT." + (with-current-buffer buffer + (and (s-starts-with? project-root + (expand-file-name default-directory)) + ;; ignore hidden buffers + (not (s-starts-with? " " (buffer-name buffer)))))) + +(defun projectile-project-buffer-names () + "Get a list of project buffer names." + (-map 'buffer-name (projectile-project-buffers))) + +(defun projectile-prepend-project-name (string) + "Prepend the current project's name to STRING." + (format "[%s] %s" (projectile-project-name) string)) + +(defun projectile-switch-to-buffer () + "Switch to a project buffer." + (interactive) + (switch-to-buffer + (projectile-completing-read + "Switch to buffer: " + (projectile-project-buffer-names)))) + +(defun projectile-multi-occur () + "Do a `multi-occur' in the project's buffers." + (interactive) + (multi-occur (projectile-project-buffers) + (car (occur-read-primary-args)))) + +(defun projectile-ignored-directory-p (directory) + "Check if DIRECTORY should be ignored." + (member directory (projectile-ignored-directories))) + +(defun projectile-ignored-file-p (file) + "Check if FILE should be ignored." + (member file (projectile-ignored-files))) + +(defun projectile-ignored-rel-p (directory file patterns) + "Check if FILE should be ignored relative to DIRECTORY according to PATTERNS." + (let ((default-directory directory)) + (-any? (lambda (pattern) + (or (s-ends-with? (s-chop-suffix "/" pattern) + (s-chop-suffix "/" file)) + (member file (file-expand-wildcards pattern t)))) + patterns))) + +(defun projectile-ignored-files () + "Return list of ignored files." + (-map + 'projectile-expand-root + (append + projectile-globally-ignored-files + (projectile-project-ignored-files)))) + +(defun projectile-ignored-directories () + "Return list of ignored directories." + (-map + 'file-name-as-directory + (-map + 'projectile-expand-root + (append + projectile-globally-ignored-directories + (projectile-project-ignored-directories))))) + +(defun projectile-project-ignored-files () + "Return list of project ignored files." + (-remove 'file-directory-p (projectile-project-ignored))) + +(defun projectile-project-ignored-directories () + "Return list of project ignored directories." + (-filter 'file-directory-p (projectile-project-ignored))) + +(defun projectile-paths-to-ignore () + "Return a list of ignored project paths." + (-map (lambda (pattern) + (s-chop-prefix "/" pattern)) + (-filter (lambda (pattern) + (s-starts-with? "/" pattern)) + (cdr (projectile-parse-dirconfig-file))))) + +(defun projectile-patterns-to-ignore () + "Return a list of relative file patterns." + (-remove (lambda (pattern) + (s-starts-with? "/" pattern)) + (cdr (projectile-parse-dirconfig-file)))) + +(defun projectile-project-ignored () + "Return list of project ignored files/directories." + (let ((paths (projectile-paths-to-ignore)) + (default-directory (projectile-project-root))) + (apply 'append + (-map + (lambda (pattern) + (file-expand-wildcards pattern t)) + paths)))) + +(defun projectile-dirconfig-file () + "Return the absolute path to the project's dirconfig file." + (expand-file-name ".projectile" (projectile-project-root))) + +(defun projectile-parse-dirconfig-file () + "Parse project ignore file and return directories to ignore and keep. + +The return value will be a cons, the car being the list of +directories to keep, and the cdr being the list of files or +directories to ignore. + +Strings starting with + will be added to the list of directories +to keep, and strings starting with - will be added to the list of +directories to ignore. For backward compatibility, without a +prefix the string will be assumed to be an ignore string." + (let ((dirconfig-file (projectile-dirconfig-file))) + (when (file-exists-p dirconfig-file) + (with-temp-buffer + (insert-file-contents-literally dirconfig-file) + (let* ((split-string-default-separators "[\r\n]") + (strings (-map 's-trim (delete "" (split-string (buffer-string))))) + (separated-vals (--separate (s-starts-with? "+" it) strings))) + (flet ((strip-prefix (s) (s-chop-prefixes '("-" "+") s))) + (cons (-map 'strip-prefix (first separated-vals)) + (-map 'strip-prefix (second separated-vals))))))))) + +(defun projectile-expand-root (name) + "Expand NAME to project root. + +Never use on many files since it's going to recalculate the +project-root for every file." + (expand-file-name name (projectile-project-root))) + +(defun projectile-completing-read (prompt choices) + "Present a project tailored PROMPT with CHOICES." + (let ((prompt (projectile-prepend-project-name prompt))) + (cond + ((eq projectile-completion-system 'ido) + (ido-completing-read prompt choices)) + ((eq projectile-completion-system 'default) + (completing-read prompt choices)) + ((eq projectile-completion-system 'grizzl) + (if (and (fboundp 'grizzl-completing-read) + (fboundp 'grizzl-make-index)) + (grizzl-completing-read prompt (grizzl-make-index choices)) + (user-error "Please install grizzl from \ +https://github.com/d11wtq/grizzl"))) + (t (funcall projectile-completion-system prompt choices))))) + +(defun projectile-current-project-files () + "Return a list of files for the current project." + (let ((files (and projectile-enable-caching + (gethash (projectile-project-root) projectile-projects-cache)))) + ;; nothing is cached + (unless files + (setq files (-mapcat 'projectile-dir-files + (projectile-get-project-directories))) + ;; cache the resulting list of files + (when projectile-enable-caching + (projectile-cache-project (projectile-project-root) files))) + files)) + +(defun projectile-current-project-dirs () + "Return a list of dirs for the current project." + (-remove 'null (-distinct + (-map 'file-name-directory + (projectile-current-project-files))))) + +(defun projectile-hash-keys (hash) + "Return a list of all HASH keys." + (let (allkeys) + (maphash (lambda (k v) (setq allkeys (cons k allkeys))) hash) + allkeys)) + +(defun projectile-find-file (arg) + "Jump to a project's file using completion. + +With a prefix ARG invalidates the cache first." + (interactive "P") + (when arg + (projectile-invalidate-cache nil)) + (let ((file (projectile-completing-read "Find file: " + (projectile-current-project-files)))) + (find-file (expand-file-name file (projectile-project-root))) + (run-hooks 'projectile-find-file-hook))) + +(defun projectile-find-dir (arg) + "Jump to a project's file using completion. + +With a prefix ARG invalidates the cache first." + (interactive "P") + (when arg + (projectile-invalidate-cache nil)) + (let ((dir (projectile-completing-read "Find dir: " + (projectile-current-project-dirs)))) + (dired (expand-file-name dir (projectile-project-root))) + (run-hooks 'projectile-find-dir-hook))) + +(defun projectile-find-test-file (arg) + "Jump to a project's test file using completion. + +With a prefix ARG invalidates the cache first." + (interactive "P") + (when arg + (projectile-invalidate-cache nil)) + (let ((file (projectile-completing-read "Find test file: " + (projectile-current-project-files)))) + (find-file (expand-file-name file (projectile-project-root))))) + +(defvar projectile-test-files-suffices '("_test" "_spec" "Test" "-test") + "Some common suffices of test files.") + +(defun projectile-test-files (files) + "Return only the test FILES." + (-filter 'projectile-test-file-p files)) + +(defun projectile-test-file-p (file) + "Check if FILE is a test file." + (-any? (lambda (suffix) + (s-ends-with? suffix (file-name-sans-extension file))) + projectile-test-files-suffices)) + +(defvar projectile-rails-rspec '("Gemfile" "app" "lib" "db" "config" "spec")) +(defvar projectile-rails-test '("Gemfile" "app" "lib" "db" "config" "test")) +(defvar projectile-symfony '("composer.json" "app" "src" "vendor")) +(defvar projectile-ruby-rspec '("Gemfile" "lib" "spec")) +(defvar projectile-ruby-test '("Gemfile" "lib" "test")) +(defvar projectile-maven '("pom.xml")) +(defvar projectile-lein '("project.clj")) +(defvar projectile-rebar '("rebar")) +(defvar projectile-make '("Makefile")) + +(defun projectile-project-type () + "Determine the project's type based on its structure." + (let ((project-root (projectile-project-root))) + (cond + ((projectile-verify-files projectile-rails-rspec) 'rails-rspec) + ((projectile-verify-files projectile-rails-test) 'rails-test) + ((projectile-verify-files projectile-ruby-rspec) 'ruby-rspec) + ((projectile-verify-files projectile-ruby-test) 'ruby-test) + ((projectile-verify-files projectile-symfony) 'symfony) + ((projectile-verify-files projectile-maven) 'maven) + ((projectile-verify-files projectile-lein) 'lein) + ((projectile-verify-files projectile-rebar) 'rebar) + ((projectile-verify-files projectile-make) 'make) + (t 'generic)))) + +(defun projectile-verify-files (files) + "Check whether all FILES exist in the current project." + (-all? 'projectile-verify-file files)) + +(defun projectile-verify-file (file) + "Check whether FILE exists in the current project." + (file-exists-p (projectile-expand-root file))) + +(defun projectile-project-vcs () + "Determine the VCS used by the project if any." + (let ((project-root (projectile-project-root))) + (cond + ((file-exists-p (expand-file-name ".git" project-root)) 'git) + ((file-exists-p (expand-file-name ".hg" project-root)) 'hg) + ((file-exists-p (expand-file-name ".fossil" project-root)) 'fossil) + ((file-exists-p (expand-file-name ".bzr" project-root)) 'bzr) + ((file-exists-p (expand-file-name "_darcs" project-root)) 'darcs) + ((file-exists-p (expand-file-name ".svn" project-root)) 'svn) + ((locate-dominating-file project-root ".git") 'git) + ((locate-dominating-file project-root ".hg") 'hg) + ((locate-dominating-file project-root ".fossil") 'fossil) + ((locate-dominating-file project-root ".bzr") 'bzr) + ((locate-dominating-file project-root "_darcs") 'darcs) + ((locate-dominating-file project-root ".svn") 'svn) + (t 'none)))) + +(defun projectile-toggle-between-implemenation-and-test () + "Toggle between an implementation file and its test file." + (interactive) + (if (projectile-test-file-p (buffer-file-name)) + ;; find the matching impl file + (let ((impl-file (projectile-find-matching-file (buffer-file-name)))) + (if impl-file + (find-file (projectile-expand-root impl-file)) + (error "No matching source file found"))) + ;; find the matching test file + (let ((test-file (projectile-find-matching-test (buffer-file-name)))) + (if test-file + (find-file (projectile-expand-root test-file)) + (error "No matching test file found"))))) + +(defun projectile-test-suffix (project-type) + "Find test files suffix based on PROJECT-TYPE." + (cond + ((member project-type '(rails-rspec ruby-rspec)) "_spec") + ((member project-type '(rails-test ruby-test lein)) "_test") + ((member project-type '(maven symfony)) "Test") + (t (error "Project type not supported!")))) + +(defun projectile-find-matching-test (file) + "Compute the name of the test matching FILE." + (let ((basename (file-name-nondirectory (file-name-sans-extension file))) + (extension (file-name-extension file)) + (test-suffix (projectile-test-suffix (projectile-project-type)))) + (-first (lambda (current-file) + (s-equals? (file-name-nondirectory (file-name-sans-extension current-file)) + (concat basename test-suffix))) + (projectile-current-project-files)))) + +(defun projectile-find-matching-file (test-file) + "Compute the name of a file matching TEST-FILE." + (let ((basename (file-name-nondirectory (file-name-sans-extension test-file))) + (extension (file-name-extension test-file)) + (test-suffix (projectile-test-suffix (projectile-project-type)))) + (-first (lambda (current-file) + (s-equals? (concat (file-name-nondirectory (file-name-sans-extension current-file)) test-suffix) + basename)) + (projectile-current-project-files)))) + +(defun projectile-grep () + "Perform rgrep in the project." + (interactive) + (let ((roots (projectile-get-project-directories)) + (search-regexp (if (and transient-mark-mode mark-active) + (buffer-substring (region-beginning) (region-end)) + (read-string (projectile-prepend-project-name "Grep for: ") + (projectile-symbol-at-point))))) + (dolist (root-dir roots) + (require 'grep) + ;; paths for find-grep should relative and without trailing / + (let ((grep-find-ignored-directories (union (-map (lambda (dir) (s-chop-suffix "/" (s-chop-prefix root-dir dir))) + (cdr (projectile-ignored-directories))) grep-find-ignored-directories)) + (grep-find-ignored-files (union (-map (lambda (file) (s-chop-prefix root-dir file)) (projectile-ignored-files)) grep-find-ignored-files))) + (grep-compute-defaults) + (rgrep search-regexp "* .*" root-dir))))) + +(defun projectile-ack () + "Run an `ack-and-a-half' search in the project." + (interactive) + (let ((ack-and-a-half-arguments + (-map + (lambda (path) + (concat "--ignore-dir=" (file-name-nondirectory (directory-file-name path)))) + (projectile-ignored-directories)))) + (call-interactively projectile-ack-function))) + +(defun projectile-tags-exclude-patterns () + "Return a string with exclude patterns for ctags." + (mapconcat (lambda (pattern) (format "--exclude=%s" pattern)) + (projectile-project-ignored-directories) " ")) + +(defun projectile-regenerate-tags () + "Regenerate the project's etags." + (interactive) + (let* ((project-root (projectile-project-root)) + (tags-exclude (projectile-tags-exclude-patterns)) + (default-directory project-root)) + (shell-command (format projectile-tags-command tags-exclude project-root)) + (visit-tags-table project-root))) + +(defun projectile-replace () + "Replace a string in the project using `tags-query-replace'." + (interactive) + (let* ((old-text (read-string + (projectile-prepend-project-name "Replace: ") + (projectile-symbol-at-point))) + (new-text (read-string + (projectile-prepend-project-name + (format "Replace %s with: " old-text))))) + (tags-query-replace old-text new-text nil '(-map 'projectile-expand-root (projectile-current-project-files))))) + +(defun projectile-symbol-at-point () + "Get the symbol at point and strip its properties." + (substring-no-properties (or (thing-at-point 'symbol) ""))) + +(defun projectile-kill-buffers () + "Kill all project buffers." + (interactive) + (let* ((buffers (projectile-project-buffer-names)) + (question + (format + "Are you sure you want to kill %d buffer(s) for '%s'? " + (length buffers) + (projectile-project-name)))) + (if (yes-or-no-p question) + (mapc 'kill-buffer buffers)))) + +(defun projectile-dired () + "Opens dired at the root of the project." + (interactive) + (dired (projectile-project-root))) + +(defun projectile-recentf () + "Show a list of recently visited files in a project." + (interactive) + (if (boundp 'recentf-list) + (find-file (projectile-expand-root (projectile-completing-read "Recently visited files: " (projectile-recentf-files))))) + (message "recentf is not enabled")) + +(defun projectile-recentf-files () + "Return a list of recently visited files in a project." + (if (boundp 'recentf-list) + (let ((project-root (projectile-project-root))) + (->> recentf-list + (-filter (lambda (file) (s-starts-with-p project-root file))) + (-map (lambda (file) (s-chop-prefix project-root file))))) + nil)) + +(defun projectile-serialize-cache () + "Serializes the memory cache to the hard drive." + (projectile-serialize projectile-projects-cache projectile-cache-file)) + +(defvar projectile-rails-compile-cmd "bundle exec rails server") +(defvar projectile-ruby-compile-cmd "bundle exec rake build") +(defvar projectile-ruby-test-cmd "bundle exec rake test") +(defvar projectile-ruby-rspec-cmd "bundle exec rspec") +(defvar projectile-symfony-compile-cmd "app/console server:run") +(defvar projectile-symfony-test-cmd "phpunit -c app ") +(defvar projectile-maven-compile-cmd "mvn clean install") +(defvar projectile-maven-test-cmd "mvn test") +(defvar projectile-lein-compile-cmd "lein compile") +(defvar projectile-lein-test-cmd "lein test") +(defvar projectile-rebar-compile-cmd "rebar") +(defvar projectile-rebar-test-cmd "rebar eunit") +(defvar projectile-make-compile-cmd "make") +(defvar projectile-make-test-cmd "make test") + +(defvar projectile-compilation-cmd-map + (make-hash-table :test 'equal) + "A mapping between projects and the last compilation command used on them.") +(defvar projectile-test-cmd-map + (make-hash-table :test 'equal) + "A mapping between projects and the last test command used on them.") + +(defun projectile-default-compilation-command (project-type) + "Retrieve default compilation command for PROJECT-TYPE." + (cond + ((member project-type '(rails-rspec rails-test)) projectile-rails-compile-cmd) + ((member project-type '(ruby-rspec ruby-test)) projectile-ruby-compile-cmd) + ((eq project-type 'symfony) projectile-symfony-compile-cmd) + ((eq project-type 'lein) projectile-lein-compile-cmd) + ((eq project-type 'make) projectile-make-compile-cmd) + ((eq project-type 'rebar) projectile-rebar-compile-cmd) + ((eq project-type 'maven) projectile-maven-compile-cmd) + (t projectile-make-compile-cmd))) + +(defun projectile-default-test-command (project-type) + "Retrieve default test command for PROJECT-TYPE." + (cond + ((member project-type '(rails-rspec ruby-rspec)) projectile-ruby-rspec-cmd) + ((member project-type '(rails-test ruby-test)) projectile-ruby-test-cmd) + ((eq project-type 'symfony) projectile-symfony-test-cmd) + ((eq project-type 'lein) projectile-lein-test-cmd) + ((eq project-type 'make) projectile-make-test-cmd) + ((eq project-type 'rebar) projectile-rebar-test-cmd) + ((eq project-type 'maven) projectile-maven-test-cmd) + (t projectile-make-test-cmd))) + +(defun projectile-compilation-command (project) + "Retrieve the compilation command for PROJECT." + (or (gethash project projectile-compilation-cmd-map) + (projectile-default-compilation-command (projectile-project-type)))) + +(defun projectile-test-command (project) + "Retrieve the compilation command for PROJECT." + (or (gethash project projectile-test-cmd-map) + (projectile-default-test-command (projectile-project-type)))) + +(defun projectile-compile-project () + "Run project compilation command." + (interactive) + (let* ((project-root (projectile-project-root)) + (compilation-cmd (compilation-read-command (projectile-compilation-command project-root))) + (default-directory project-root)) + (puthash project-root compilation-cmd projectile-compilation-cmd-map) + (compilation-start compilation-cmd))) + +;; TODO - factor this duplication out +(defun projectile-test-project () + "Run project test command." + (interactive) + (let* ((project-root (projectile-project-root)) + (test-cmd (compilation-read-command (projectile-test-command project-root))) + (default-directory project-root)) + (puthash project-root test-cmd projectile-test-cmd-map) + (compilation-start test-cmd))) + +(defun projectile-switch-project () + "Switch to a project we have seen before." + (interactive) + (let* ((project-to-switch + (projectile-completing-read "Switch to which project: " + projectile-known-projects)) + (default-directory project-to-switch)) + (projectile-find-file nil) + (let ((project-switched project-to-switch)) + (run-hooks 'projectile-switch-project-hook)))) + +(defvar projectile-switch-project-hook nil + "Hooks run when project is switched. + +The path to the opened project is available as PROJECT-SWITCHED") + +(defun projectile-clear-known-projects () + "Clear both `projectile-known-projects' and `projectile-known-projects-file'." + (interactive) + (setq projectile-known-projects nil) + (projectile-save-known-projects)) + +(defun projectile-remove-known-project () + "Remove a projected from the list of known projects." + (interactive) + (let ((project-to-remove + (projectile-completing-read "Switch to which project: " + projectile-known-projects))) + (setq projectile-known-projects + (--reject (string= project-to-remove it) projectile-known-projects)) + (projectile-save-known-projects) + (message "Project %s removed from the list of known projects." project-to-remove))) + +(defun projectile-add-known-project (project-root) + "Add PROJECT-ROOT to the list of known projects." + (setq projectile-known-projects + (-distinct + (cons (abbreviate-file-name project-root) projectile-known-projects)))) + +(defun projectile-load-known-projects () + "Load saved projects from `projectile-known-projects-file'. +Also set `projectile-known-projects'." + (setq projectile-known-projects + (projectile-unserialize projectile-known-projects-file))) + +;; load the known projects +(projectile-load-known-projects) + +(defun projectile-save-known-projects () + "Save PROJECTILE-KNOWN-PROJECTS to PROJECTILE-KNOWN-PROJECTS-FILE." + (projectile-serialize projectile-known-projects projectile-known-projects-file)) + +(defvar projectile-mode-map + (let ((map (make-sparse-keymap))) + (let ((prefix-map (make-sparse-keymap))) + (define-key prefix-map (kbd "f") 'projectile-find-file) + (define-key prefix-map (kbd "T") 'projectile-find-test-file) + (define-key prefix-map (kbd "t") 'projectile-toggle-between-implemenation-and-test) + (define-key prefix-map (kbd "g") 'projectile-grep) + (define-key prefix-map (kbd "b") 'projectile-switch-to-buffer) + (define-key prefix-map (kbd "o") 'projectile-multi-occur) + (define-key prefix-map (kbd "r") 'projectile-replace) + (define-key prefix-map (kbd "i") 'projectile-invalidate-cache) + (define-key prefix-map (kbd "R") 'projectile-regenerate-tags) + (define-key prefix-map (kbd "k") 'projectile-kill-buffers) + (define-key prefix-map (kbd "d") 'projectile-find-dir) + (define-key prefix-map (kbd "D") 'projectile-dired) + (define-key prefix-map (kbd "e") 'projectile-recentf) + (define-key prefix-map (kbd "a") 'projectile-ack) + (define-key prefix-map (kbd "c") 'projectile-compile-project) + (define-key prefix-map (kbd "p") 'projectile-test-project) + (define-key prefix-map (kbd "z") 'projectile-cache-current-file) + (define-key prefix-map (kbd "s") 'projectile-switch-project) + + (define-key map projectile-keymap-prefix prefix-map)) + map) + "Keymap for Projectile mode.") + +(defun projectile-add-menu () + "Add Projectile's menu under Tools." + (easy-menu-add-item nil '("Tools") + '("Projectile" + ["Find file" projectile-find-file] + ["Switch to buffer" projectile-switch-to-buffer] + ["Kill project buffers" projectile-kill-buffers] + ["Recent files" projectile-recentf] + "--" + ["Open project in dired" projectile-dired] + ["Find in project (grep)" projectile-grep] + ["Find in project (ack)" projectile-ack] + ["Replace in project" projectile-replace] + ["Multi-occur in project" projectile-multi-occur] + "--" + ["Invalidate cache" projectile-invalidate-cache] + ["Regenerate etags" projectile-regenerate-tags] + "--" + ["Compile project" projectile-compile-project] + ["Test project" projectile-test-project] + "--" + ["About" projectile-version]) + "Search Files (Grep)...") + + (easy-menu-add-item nil '("Tools") '("--") "Search Files (Grep)...")) + +(defun projectile-remove-menu () + "Remove Projectile's menu." + (easy-menu-remove-item nil '("Tools") "Projectile") + (easy-menu-remove-item nil '("Tools") "--")) + +;;; define minor mode + +;;;###autoload +(define-minor-mode projectile-mode + "Minor mode to assist project management and navigation. + +\\{projectile-mode-map}" + :lighter " Projectile" + :keymap projectile-mode-map + :group 'projectile + (if projectile-mode + ;; on start + (projectile-add-menu) + ;; on stop + (projectile-remove-menu))) + +;;;###autoload +(define-globalized-minor-mode projectile-global-mode + projectile-mode + projectile-on) + +(defun projectile-on () + "Enable Projectile minor mode." + (projectile-mode 1)) + +(defun projectile-off () + "Disable Projectile minor mode." + (projectile-mode -1)) + +(defun projectile-global-on () + "Enable Projectile global minor mode." + (add-hook 'find-file-hook 'projectile-cache-files-find-file-hook) + (add-hook 'find-file-hook 'projectile-cache-projects-find-file-hook) + (add-hook 'projectile-find-dir-hook 'projectile-cache-projects-find-file-hook)) + +(defun projectile-global-off () + "Disable Projectile global minor mode." + (remove-hook 'find-file-hook 'projectile-cache-files-find-file-hook) + (remove-hook 'find-file-hook 'projectile-cache-projects-find-file-hook)) + +(defadvice projectile-global-mode (after projectile-setup-hooks activate) + "Add/remove `find-file-hook' functions within `projectile-global-mode'." + (if projectile-global-mode + (projectile-global-on) + (projectile-global-off))) + +(provide 'projectile) + +;; Local Variables: +;; byte-compile-warnings: (not cl-functions) +;; End: + +;;; projectile.el ends here diff --git a/emacs.d/elpa/projectile-0.9.2/projectile.elc b/emacs.d/elpa/projectile-0.9.2/projectile.elc new file mode 100644 index 0000000..fd7f36f Binary files /dev/null and b/emacs.d/elpa/projectile-0.9.2/projectile.elc differ diff --git a/emacs.d/elpa/s-1.6.1/s-autoloads.el b/emacs.d/elpa/s-1.6.1/s-autoloads.el new file mode 100644 index 0000000..c971a1d --- /dev/null +++ b/emacs.d/elpa/s-1.6.1/s-autoloads.el @@ -0,0 +1,18 @@ +;;; s-autoloads.el --- automatically extracted autoloads +;; +;;; Code: + + +;;;### (autoloads nil nil ("s-pkg.el" "s.el") (21002 9889 830403 +;;;;;; 0)) + +;;;*** + +(provide 's-autoloads) +;; Local Variables: +;; version-control: never +;; no-byte-compile: t +;; no-update-autoloads: t +;; coding: utf-8 +;; End: +;;; s-autoloads.el ends here diff --git a/emacs.d/elpa/s-1.6.1/s-pkg.el b/emacs.d/elpa/s-1.6.1/s-pkg.el new file mode 100644 index 0000000..9dfc82e --- /dev/null +++ b/emacs.d/elpa/s-1.6.1/s-pkg.el @@ -0,0 +1 @@ +(define-package "s" "1.6.1" "The long lost Emacs string manipulation library." (quote nil)) diff --git a/emacs.d/elpa/s-1.6.1/s-pkg.elc b/emacs.d/elpa/s-1.6.1/s-pkg.elc new file mode 100644 index 0000000..1c831c0 Binary files /dev/null and b/emacs.d/elpa/s-1.6.1/s-pkg.elc differ diff --git a/emacs.d/elpa/s-1.6.1/s.el b/emacs.d/elpa/s-1.6.1/s.el new file mode 100644 index 0000000..31f322e --- /dev/null +++ b/emacs.d/elpa/s-1.6.1/s.el @@ -0,0 +1,532 @@ +;;; s.el --- The long lost Emacs string manipulation library. + +;; Copyright (C) 2012 Magnar Sveen + +;; Author: Magnar Sveen +;; Version: 1.6.1 +;; Keywords: strings + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with this program. If not, see . + +;;; Commentary: + +;; The long lost Emacs string manipulation library. +;; +;; See documentation on https://github.com/magnars/s.el#functions + +;;; Code: + +(defun s-trim-left (s) + "Remove whitespace at the beginning of S." + (if (string-match "\\`[ \t\n\r]+" s) + (replace-match "" t t s) + s)) + +(defun s-trim-right (s) + "Remove whitespace at the end of S." + (if (string-match "[ \t\n\r]+\\'" s) + (replace-match "" t t s) + s)) + +(defun s-trim (s) + "Remove whitespace at the beginning and end of S." + (s-trim-left (s-trim-right s))) + +(defun s-collapse-whitespace (s) + "Convert all adjacent whitespace characters to a single space." + (replace-regexp-in-string "[ \t\n\r]+" " " s)) + +(defun s-split (separator s &optional omit-nulls) + "Split S into substrings bounded by matches for regexp SEPARATOR. +If OMIT-NULLS is t, zero-length substrings are omitted. + +This is a simple wrapper around the built-in `split-string'." + (split-string s separator omit-nulls)) + +(defun s-lines (s) + "Splits S into a list of strings on newline characters." + (s-split "\\(\r\n\\|[\n\r]\\)" s)) + +(defun s-join (separator strings) + "Join all the strings in STRINGS with SEPARATOR in between." + (mapconcat 'identity strings separator)) + +(defun s-concat (&rest strings) + "Join all the string arguments into one string." + (apply 'concat strings)) + +(defun s-prepend (prefix s) + "Concatenate PREFIX and S." + (concat prefix s)) + +(defun s-append (suffix s) + "Concatenate S and SUFFIX." + (concat s suffix)) + +(defun s-repeat (num s) + "Make a string of S repeated NUM times." + (let (ss) + (while (> num 0) + (setq ss (cons s ss)) + (setq num (1- num))) + (apply 'concat ss))) + +(defun s-chop-suffix (suffix s) + "Remove SUFFIX if it is at end of S." + (let ((pos (- (length suffix)))) + (if (and (>= (length s) (length suffix)) + (string= suffix (substring s pos))) + (substring s 0 pos) + s))) + +(defun s-chop-suffixes (suffixes s) + "Remove SUFFIXES one by one in order, if they are at the end of S." + (while suffixes + (setq s (s-chop-suffix (car suffixes) s)) + (setq suffixes (cdr suffixes))) + s) + +(defun s-chop-prefix (prefix s) + "Remove PREFIX if it is at the start of S." + (let ((pos (length prefix))) + (if (and (>= (length s) (length prefix)) + (string= prefix (substring s 0 pos))) + (substring s pos) + s))) + +(defun s-chop-prefixes (prefixes s) + "Remove PREFIXES one by one in order, if they are at the start of S." + (while prefixes + (setq s (s-chop-prefix (car prefixes) s)) + (setq prefixes (cdr prefixes))) + s) + +(defun s-shared-start (s1 s2) + "Returns the longest prefix S1 and S2 have in common." + (let ((search-length (min (length s1) (length s2))) + (i 0)) + (while (and (< i search-length) + (= (aref s1 i) (aref s2 i))) + (setq i (1+ i))) + (substring s1 0 i))) + +(defun s-shared-end (s1 s2) + "Returns the longest suffix S1 and S2 have in common." + (let* ((l1 (length s1)) + (l2 (length s2)) + (search-length (min l1 l2)) + (i 0)) + (while (and (< i search-length) + (= (aref s1 (- l1 i 1)) (aref s2 (- l2 i 1)))) + (setq i (1+ i))) + ;; If I is 0, then it means that there's no common suffix between + ;; S1 and S2. + ;; + ;; However, since (substring s (- 0)) will return the whole + ;; string, `s-shared-end' should simply return the empty string + ;; when I is 0. + (if (zerop i) + "" + (substring s1 (- i))))) + +(defun s-chomp (s) + "Remove one trailing `\\n`, `\\r` or `\\r\\n` from S." + (s-chop-suffixes '("\n" "\r") s)) + +(defun s-truncate (len s) + "If S is longer than LEN, cut it down and add ... at the end." + (if (> (length s) len) + (format "%s..." (substring s 0 (- len 3))) + s)) + +(defun s-word-wrap (len s) + "If S is longer than LEN, wrap the words with newlines." + (with-temp-buffer + (insert s) + (let ((fill-column len)) + (fill-region (point-min) (point-max))) + (buffer-substring-no-properties (point-min) (point-max)))) + +(defun s-center (len s) + "If S is shorter than LEN, pad it with spaces so it is centered." + (let ((extra (max 0 (- len (length s))))) + (concat + (make-string (ceiling extra 2) ? ) + s + (make-string (floor extra 2) ? )))) + +(defun s-pad-left (len padding s) + "If S is shorter than LEN, pad it with PADDING on the left." + (let ((extra (max 0 (- len (length s))))) + (concat (make-string extra (string-to-char padding)) + s))) + +(defun s-pad-right (len padding s) + "If S is shorter than LEN, pad it with PADDING on the left." + (let ((extra (max 0 (- len (length s))))) + (concat s + (make-string extra (string-to-char padding))))) + +(defun s-left (len s) + "Returns up to the LEN first chars of S." + (if (> (length s) len) + (substring s 0 len) + s)) + +(defun s-right (len s) + "Returns up to the LEN last chars of S." + (let ((l (length s))) + (if (> l len) + (substring s (- l len) l) + s))) + +(defun s-ends-with? (suffix s &optional ignore-case) + "Does S end with SUFFIX? + +If IGNORE-CASE is non-nil, the comparison is done without paying +attention to case differences. + +Alias: `s-suffix?'" + (let ((start-pos (- (length s) (length suffix)))) + (and (>= start-pos 0) + (eq t (compare-strings suffix nil nil + s start-pos nil ignore-case))))) + +(defalias 's-ends-with-p 's-ends-with?) + +(defun s-starts-with? (prefix s &optional ignore-case) + "Does S start with PREFIX? + +If IGNORE-CASE is non-nil, the comparison is done without paying +attention to case differences. + +Alias: `s-prefix?'. This is a simple wrapper around the built-in +`string-prefix-p'." + (string-prefix-p prefix s ignore-case)) + +(defalias 's-starts-with-p 's-starts-with?) + +(defalias 's-suffix? 's-ends-with?) +(defalias 's-prefix? 's-starts-with?) +(defalias 's-suffix-p 's-ends-with?) +(defalias 's-prefix-p 's-starts-with?) + +(defun s--truthy? (val) + (not (null val))) + +(defun s-contains? (needle s &optional ignore-case) + "Does S contain NEEDLE? + +If IGNORE-CASE is non-nil, the comparison is done without paying +attention to case differences." + (let ((case-fold-search ignore-case)) + (s--truthy? (string-match-p (regexp-quote needle) s)))) + +(defalias 's-contains-p 's-contains?) + +(defun s-equals? (s1 s2) + "Is S1 equal to S2? + +This is a simple wrapper around the built-in `string-equal'." + (string-equal s1 s2)) + +(defalias 's-equals-p 's-equals?) + +(defun s-less? (s1 s2) + "Is S1 less than S2? + +This is a simple wrapper around the built-in `string-lessp'." + (string-lessp s1 s2)) + +(defalias 's-less-p 's-less?) + +(defun s-matches? (regexp s &optional start) + "Does REGEXP match S? +If START is non-nil the search starts at that index. + +This is a simple wrapper around the built-in `string-match-p'." + (s--truthy? (string-match-p regexp s start))) + +(defalias 's-matches-p 's-matches?) + +(defun s-blank? (s) + "Is S nil or the empty string?" + (or (null s) (string= "" s))) + +(defun s-lowercase? (s) + "Are all the letters in S in lower case?" + (let ((case-fold-search nil)) + (not (string-match-p "[[:upper:]]" s)))) + +(defun s-uppercase? (s) + "Are all the letters in S in upper case?" + (let ((case-fold-search nil)) + (not (string-match-p "[[:lower:]]" s)))) + +(defun s-mixedcase? (s) + "Are there both lower case and upper case letters in S?" + (let ((case-fold-search nil)) + (s--truthy? + (and (string-match-p "[[:lower:]]" s) + (string-match-p "[[:upper:]]" s))))) + +(defun s-capitalized? (s) + "In S, is the first letter upper case, and all other letters lower case?" + (let ((case-fold-search nil)) + (s--truthy? + (string-match-p "^[A-ZÆØÅ][^A-ZÆØÅ]*$" s)))) + +(defun s-numeric? (s) + "Is S a number?" + (s--truthy? + (string-match-p "^[0-9]+$" s))) + +(defun s-replace (old new s) + "Replaces OLD with NEW in S." + (replace-regexp-in-string (regexp-quote old) new s t t)) + +(defun s--aget (alist key) + (cdr (assoc key alist))) + +(defun s-replace-all (replacements s) + "REPLACEMENTS is a list of cons-cells. Each `car` is replaced with `cdr` in S." + (replace-regexp-in-string (regexp-opt (mapcar 'car replacements)) + (lambda (it) (s--aget replacements it)) + s)) + +(defun s-downcase (s) + "Convert S to lower case. + +This is a simple wrapper around the built-in `downcase'." + (downcase s)) + +(defun s-upcase (s) + "Convert S to upper case. + +This is a simple wrapper around the built-in `upcase'." + (upcase s)) + +(defun s-capitalize (s) + "Convert the first word's first character to upper case and the rest to lower case in S." + (concat (upcase (substring s 0 1)) (downcase (substring s 1)))) + +(defun s-titleize (s) + "Convert each word's first character to upper case and the rest to lower case in S. + +This is a simple wrapper around the built-in `capitalize'." + (capitalize s)) + +(defmacro s-with (s form &rest more) + "Threads S through the forms. Inserts S as the last item +in the first form, making a list of it if it is not a list +already. If there are more forms, inserts the first form as the +last item in second form, etc." + (if (null more) + (if (listp form) + `(,(car form) ,@(cdr form) ,s) + (list form s)) + `(s-with (s-with ,s ,form) ,@more))) + +(put 's-with 'lisp-indent-function 1) + +(defun s-index-of (needle s &optional ignore-case) + "Returns first index of NEEDLE in S, or nil. + +If IGNORE-CASE is non-nil, the comparison is done without paying +attention to case differences." + (let ((case-fold-search ignore-case)) + (string-match-p (regexp-quote needle) s))) + +(defun s-reverse (s) ;; from org-babel-reverse-string + "Return the reverse of S." + (apply 'string (nreverse (string-to-list s)))) + +(defun s-match-strings-all (regex string) + "Return a list of matches for REGEX in STRING. + +Each element itself is a list of matches, as per +`match-string'. Multiple matches at the same position will be +ignored after the first." + (let ((all-strings ()) + (i 0)) + (while (and (< i (length string)) + (string-match regex string i)) + (setq i (1+ (match-beginning 0))) + (let (strings + (num-matches (/ (length (match-data)) 2)) + (match 0)) + (while (/= match num-matches) + (push (match-string match string) strings) + (setq match (1+ match))) + (push (nreverse strings) all-strings))) + (nreverse all-strings))) + +(defun s-match (regexp s &optional start) + "When the given expression matches the string, this function returns a list +of the whole matching string and a string for each matched subexpressions. +If it did not match the returned value is an empty list (nil). + +When START is non-nil the search will start at that index." + (save-match-data + (if (string-match regexp s start) + (let ((match-data-list (match-data)) + result) + (while match-data-list + (let* ((beg (car match-data-list)) + (end (cadr match-data-list)) + (subs (if (and beg end) (substring s beg end) nil))) + (setq result (cons subs result)) + (setq match-data-list + (cddr match-data-list)))) + (nreverse result))))) + +(defun s-slice-at (regexp s) + "Slices S up at every index matching REGEXP." + (save-match-data + (let (i) + (setq i (string-match regexp s 1)) + (if i + (cons (substring s 0 i) + (s-slice-at regexp (substring s i))) + (list s))))) + +(defun s-split-words (s) + "Split S into list of words." + (s-split + "[^A-Za-z0-9]+" + (let ((case-fold-search nil)) + (replace-regexp-in-string "\\([a-z]\\)\\([A-Z]\\)" "\\1 \\2" s)) + t)) + +(defun s--mapcar-head (fn-head fn-rest list) + "Like MAPCAR, but applies a different function to the first element." + (if list + (cons (funcall fn-head (car list)) (mapcar fn-rest (cdr list))))) + +(defun s-lower-camel-case (s) + "Convert S to lowerCamelCase." + (s-join "" (s--mapcar-head 'downcase 'capitalize (s-split-words s)))) + +(defun s-upper-camel-case (s) + "Convert S to UpperCamelCase." + (s-join "" (mapcar 'capitalize (s-split-words s)))) + +(defun s-snake-case (s) + "Convert S to snake_case." + (s-join "_" (mapcar 'downcase (s-split-words s)))) + +(defun s-dashed-words (s) + "Convert S to dashed-words." + (s-join "-" (mapcar 'downcase (s-split-words s)))) + +(defun s-capitalized-words (s) + "Convert S to Capitalized Words." + (let ((words (s-split-words s))) + (s-join " " (cons (capitalize (car words)) (mapcar 'downcase (cdr words)))))) + +(defun s-titleized-words (s) + "Convert S to Titleized Words." + (s-join " " (mapcar 's-titleize (s-split-words s)))) + + +;; Errors for s-format +(progn + (put 's-format-resolve + 'error-conditions + '(error s-format s-format-resolve)) + (put 's-format-resolve + 'error-message + "Cannot resolve a template to values")) + +(defun s-format (template replacer &optional extra) + "Format TEMPLATE with the function REPLACER. + +REPLACER takes an argument of the format variable and optionally +an extra argument which is the EXTRA value from the call to +`s-format'. + +Several standard `s-format' helper functions are recognized and +adapted for this: + + (s-format \"${name}\" 'gethash hash-table) + (s-format \"${name}\" 'aget alist) + (s-format \"$0\" 'elt sequence) + +The REPLACER function may be used to do any other kind of +transformation." + (let ((saved-match-data (match-data))) + (unwind-protect + (replace-regexp-in-string + "\\$\\({\\([^}]+\\)}\\|[0-9]+\\)" + (lambda (md) + (let ((var + (let ((m (match-string 2 md))) + (if m m + (string-to-number (match-string 1 md))))) + (replacer-match-data (match-data))) + (unwind-protect + (let ((v + (cond + ((eq replacer 'gethash) + (funcall replacer var extra)) + ((eq replacer 'aget) + (funcall 's--aget extra var)) + ((eq replacer 'elt) + (funcall replacer extra var)) + (t + (set-match-data saved-match-data) + (if extra + (funcall replacer var extra) + (funcall replacer var)))))) + (if v v (signal 's-format-resolve md))) + (set-match-data replacer-match-data)))) template + ;; Need literal to make sure it works + t t) + (set-match-data saved-match-data)))) + +(defvar s-lex-value-as-lisp nil + "If `t' interpolate lisp values as lisp. + +`s-lex-format' inserts values with (format \"%S\").") + +(defun s-lex-fmt|expand (fmt) + "Expand FMT into lisp." + (list 's-format fmt (quote 'aget) + (append '(list) + (mapcar + (lambda (matches) + (list + 'cons + (cadr matches) + `(format + (if s-lex-value-as-lisp "%S" "%s") + ,(intern (cadr matches))))) + (s-match-strings-all "${\\([^}]+\\)}" fmt))))) + +(defmacro s-lex-format (format-str) + "`s-format` with the current environment. + +FORMAT-STR may use the `s-format' variable reference to refer to +any variable: + + (let ((x 1)) + (s-lex-format \"x is: ${x}\")) + +The values of the variables are interpolated with \"%s\" unless +the variable `s-lex-value-as-lisp' is `t' and then they are +interpolated with \"%S\"." + (s-lex-fmt|expand format-str)) + +(provide 's) +;;; s.el ends here diff --git a/emacs.d/elpa/s-1.6.1/s.elc b/emacs.d/elpa/s-1.6.1/s.elc new file mode 100644 index 0000000..9c73d61 Binary files /dev/null and b/emacs.d/elpa/s-1.6.1/s.elc differ