.emacs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. (custom-set-variables
  2. ;; custom-set-variables was added by Custom.
  3. ;; If you edit it by hand, you could mess it up, so be careful.
  4. ;; Your init file should contain only one such instance.
  5. ;; If there is more than one, they won't work right.
  6. '(ansi-color-faces-vector
  7. [default default default italic underline success warning error])
  8. '(ansi-color-names-vector
  9. ["black" "#d55e00" "#009e73" "#f8ec59" "#0072b2" "#cc79a7" "#56b4e9" "white"])
  10. '(custom-enabled-themes (quote (whiteboard)))
  11. '(indent-line-function (quote insert-tab) f)
  12. '(indent-tabs-mode nil)
  13. '(iread-chars 20)
  14. '(iread-delay-milliseconds 400)
  15. '(iread-delay-seconds 0)
  16. '(iread-screenlength 100)
  17. '(line-move-visual nil)
  18. '(max-lisp-eval-depth (expt 2 10))
  19. '(max-specpdl-size 34294)
  20. '(python-shell-interpreter "python3")
  21. '(send-mail-function (quote sendmail-send-it))
  22. '(shell-command-default-error-buffer (quote stderror-buffer) t)
  23. '(tab-width 5)
  24. '(tool-bar-mode nil)
  25. '(undo-outer-limit (expt 2 24))
  26. '(visible-bell t))
  27. ;; I basically never want to hit this key
  28. (global-set-key (kbd "<insert>") 'nil)
  29. (custom-set-faces
  30. ;; custom-set-faces was added by Custom.
  31. ;; If you edit it by hand, you could mess it up, so be careful.
  32. ;; Your init file should contain only one such instance.
  33. ;; If there is more than one, they won't work right.
  34. )
  35. (if (display-graphic-p)
  36. (setq initial-frame-alist
  37. '(
  38. (tool-bar-lines . 0)
  39. (width . 106)
  40. (height . 60)
  41. (background-color . "black")
  42. (foreground-color . "orange")
  43. (left . 50)
  44. (top . 50)))
  45. (setq initial-frame-alist '( (tool-bar-lines . 0))))
  46. (setq default-frame-alist initial-frame-alist)
  47. (put 'scroll-left 'disabled nil)
  48. (defun twitterablep () "is region twitterable? #elisp" (interactive) (message (if (> 140 (abs (- (point) (mark)))) "yes" "no")))
  49. (defun nullp (l)
  50. "is this null?"
  51. (equal '() l))
  52. (defun reduce (p l)
  53. "reduce function?"
  54. (if
  55. (nullp l)
  56. l
  57. (if (listp l)
  58. (if (= (length l) 1)
  59. l
  60. (if (= (length l) 2)
  61. (funcall p (car l) (car (cdr l)))
  62. (reduce p
  63. (cons
  64. (funcall p (car l)
  65. (car (cdr l)))
  66. (cdr
  67. (cdr l))))))
  68. l)
  69. ))
  70. (defun map (f l)
  71. "map function?"
  72. (if
  73. (nullp l)
  74. '()
  75. (if (listp l)
  76. (if (= 1 (length l))
  77. (list (funcall f (car l)))
  78. (if (> (length l) 1)
  79. (cons (map f (car l))
  80. (map f (cdr l)))))
  81. (funcall f l)
  82. )))
  83. (require 'dired-x)
  84. ; broken? (require ’ess-r-mode)
  85. ; (setq web-browser "/home/themusicgod1/palemooon/Pale-Moon-27.3.0_Release/obj-x86_64-unknown-linux-gnu/dist/bin/palemoon");
  86. (setq web-browser "/home/themusicgod1/tor-browser/tor-browser_en-US/Browser/runtorbrowser.sh")
  87. ; (setq web-browser "chromium-browser")
  88. (fset 'traverse-hyperlink-line
  89. (format "(shell-command \"%s '\C-e' & sleep 0.6; \")\C-x\C-e\C-f\C-p\C-k\C-d" web-browser))
  90. (fset 'unsqlize-delete
  91. "\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-d\C-s\"\C-b\C-k\C-f")
  92. (fset 'url-macro-1 "\C-d\C-d\C-d\C-n\C-d")
  93. (fset 'run-delete-sqls-in-ansi-term
  94. [C-S-down S-up (menu-bar) edit copy ?\C-x ?\C-f return ?\C-s ?T ?D ?L ?\C-m return ?\M-x ?a ?n ?s ?i ?- ?t ?e ?r ?m return return ?s ?q ?l ?i ?t ?e ?3 ? ?u ?r ?l ?s ?. ?d ?b return S-insert ?e ?x ?i ?t return ?\; return ?. ?e ?x ?i ?t return ?e ?x ?i ?t return ?\C-x ?k return ?\C-x ?k return ?\C-x ?k return C-up C-down])
  95. (fset 'twitter-macro-1
  96. [?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?f backspace ?\C-f ?a ?g ?a ?i ?n ? ?\C-e ?\C-f])
  97. (fset 'tweet
  98. [?\C-k ?\M-x ?u backspace ?u backspace ?b ?u ?f ?f ?e ?r ?- ?m ?e ?n ?u return ?\C-s ?t ?w ?i ?t ?t ?e ?r ?\C-m return S-insert return ?\C-x left ?\M-x ?b ?u ?f ?f ?e ?r ?- ?m ?e ?n ?u return ?\C-n return ?\C-d])
  99. (defun dec2hex (dec) "decimal to hex" (interactive dec2hex) (message "%x" dec))
  100. (defun hex2dec (hex) "hex to decimal" (interactive hex2dec) (message "%d" hex))
  101. (defun hex2dec1 (hex) "hex to decimal" (interactive hex2dec) (message "%d" (message "#x%x" hex)))
  102. ;; https://github.com/bard/mozrepl/wiki/Emacs-integration
  103. (add-to-list 'load-path "/home/themusicgod1/emacs")
  104. (autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t)
  105. (add-hook 'javascript-mode-hook 'javascript-custom-setup)
  106. (defun javascript-custom-setup ()
  107. (moz-minor-mode 1))
  108. ;; https://github.com/RenWenshan/emacs-moz-controller
  109. (add-to-list 'load-path "/home/themusicgod1/emacs/emacs-moz-controller")
  110. (require 'moz-controller)
  111. (fset 'firefox-macro-1
  112. "\C-cml\C-y")
  113. (fset 'moz-macro-2
  114. [?\M-x ?w ?i ?n ?d ?m ?o ?v ?e ?- ?u ?p return C-end return ?g ?B ?r ?o ?w ?s ?e ?r ?. ?g ?e ?t ?B ?r ?o ?w ?s ?e ?r ?F ?o ?r ?T ?a ?b ?\( ?g ?B ?r ?o ?w ?s ?e ?r ?. ?s ?e ?l ?e ?c ?t ?e ?d ?T ?a ?b ?\) ?. ?c ?u ?r ?r ?e ?n ?t ?U ?R ?I ?. ?s ?p ?e ?c return ?\M-x ?w ?i ?n ?d ?m ?o ?v ?e ?- ?d ?o ?w ?n return])
  115. (fset 'moz-macro-3
  116. [?\M-x ?w ?i ?n ?d ?m ?o ?v ?e ?- ?u ?p return ?\C-p home ?\C-k ?\M-x ?w ?i ?n ?d ?m ?o ?v ?e ?- ?d ?o ?w ?n return ?\C-y return ?\C-p ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-d ?\C-s ?\' backspace ?\" ?\C-b ?\C-d ?\C-f])
  117. (fset 'moz-close-tab
  118. [?\M-x ?w ?i ?n ?d ?m ?o ?v ?e ?- ?u ?p return ?g ?B ?r ?o ?w ?s ?e ?r ?. ?r ?e ?m ?o ?v ?e ?C ?r ?u ?r ?e ?n backspace backspace backspace backspace backspace ?u ?r ?r ?e ?n ?t ?T ?a ?b ?\( ?\) ?\; return ?\M-x ?w ?i ?n ?d ?m ?o ?v ?e ?- ?d ?o ?w ?n return])
  119. (global-set-key '[(f1)] 'traverse-hyperlink-line)
  120. (global-set-key '[(f2)] 'unsqlize-delete)
  121. (global-set-key '[(f3)] 'twitter-macro-1)
  122. (global-set-key '[(f4)] 'url-macro-1)
  123. (global-set-key '[(f5)] 'firefox-macro-2)
  124. (global-set-key '[(f6)] 'firefox-macro-3)
  125. (global-set-key '[(f7)] 'moz-close-tab)
  126. (defun sum (L) (reduce '+ L))
  127. (defun sizeof (L) (length L))
  128. (defun getElement (N L)
  129. "returns the Nth element of list L. 0 indexed"
  130. (if (<= N 0)
  131. (car L)
  132. (getElement (- N 1 ) (cdr L) )
  133. )
  134. )
  135. (defun listOfNfs (N f)
  136. "returns a list of N fs"
  137. (if (<= N 0)
  138. '()
  139. (cons f (listOfNfs (- N 1) f))))
  140. (defun sign (N)
  141. (if (numberp N)
  142. (if (> N 0) 1
  143. (if (< N 0) -1
  144. 0)) NaN
  145. ))
  146. (defun log2 (N) (/ (log N) (log 2)))
  147. (defun entropy (P1) (- (+ (* P1 (log2 P1)))))
  148. (defun zero? (Z)
  149. (if (numberp Z )
  150. (if (= Z 0)
  151. 1
  152. nil)
  153. nil))
  154. (defun eqv? (A B)
  155. (if (and (numberp A ) (numberp B) )
  156. (if (= A B)
  157. 1
  158. nil)
  159. nil))
  160. (defun binome
  161. (n k)
  162. (if (> k n) '(help, I'm trapped in a universe factory!)
  163. (if (zero? k) 1
  164. (if (eqv? k n) 1
  165. (+ (funcall 'binome (- n 1) k) (funcall 'binome (- n 1) (- k 1)) )
  166. )
  167. ))
  168. )
  169. (defun avg (L) (/ (sum L) (length L)))
  170. (defun positiveintegerp (n)
  171. "0+ is positive here"
  172. (if (integerp n)
  173. (if (>= n 0)
  174. 1
  175. nil)
  176. nil
  177. )
  178. )
  179. (defun ! (N)
  180. (if (positiveintegerp N)
  181. (if (= N 0)
  182. 1
  183. (if (> N 0)
  184. (* N (! (- N 1))) N))
  185. "error: incorrect data, positive integer required"))
  186. (defun do-n-times (f n x)
  187. "call function f with arity 1 on data x on itself n times, f1(f2(f...(fn(x)))). n must be positive nonzero integer"
  188. (if (> n 0)
  189. (funcall f (do-n-times f (- n 1) x))
  190. x)
  191. )
  192. (defun mf (m) (/ (- (expt 2.0 m) 1) (expt 2.0 m)))
  193. (defun nsp (P1 P2)
  194. (setq diff (abs (- P1 P2)))
  195. ;; ordinal
  196. (setq fair (string-to-int (format "%d" (/ 1.0 (entropy diff)))))
  197. ;;(message "entropy diff %d" (/ 1.0 (entropy diff)))
  198. ;;(message "fair %d" fair)
  199. ;; we want this in flips of a number
  200. (mf fair)
  201. )
  202. (defun whatprob (p) (/ (+ (- 2) (sqrt (- 4 (* 4 p ) ))) (* -2)))
  203. (defun whatprob2 (p) (- (* 2 p) (* p p)))
  204. (defun drop-1 (L) (reverse (cdr (reverse L))))
  205. (defun drop (L n)
  206. (setq err "drop requires a positive integer argument n (drop <list> N)")
  207. (if (= n 0)
  208. L
  209. (if (< n 1)
  210. (message "%s" err)
  211. (if (not (listp L))
  212. (message "%s" err)
  213. (do-n-times 'drop-1 n L)))))
  214. (defun successor (n)
  215. "successor function"
  216. (+ n 1))
  217. (defun 名单 ( &rest ns) ns)
  218. (defun *L (L1 L2 f)
  219. "takes function/binary relation f and applies it like dot product to lists L1 & L2's members"
  220. (*L-helper L1 L2 f (sizeof L1) ))
  221. (defun *L-helper (L1 L2 f N)
  222. (if (not (= N 0))
  223. (cons (funcall f (car L1) (car L2)) (*L-helper (cdr L1) (cdr L2) f (- N 1)))))
  224. (defun nCr (a b)
  225. "a choose b : a > b, (a,b) e Z+. The problem with doing it this way is a,b can get too big. at ~19 we start seeing overflows. if we ever need this, rewrite to reduce factors"
  226. (if (and (positiveintegerp a) (positiveintegerp b))
  227. (if (and (>= a b) (>= a 0) (>= b 0) (< a 19) (< b 19))
  228. (/ (! a) (* (! (- a b) ) (! b)))
  229. "error: nCr range error")
  230. "error: nCr requires positive integers"))
  231. (setq max_int (- (expt 2 61) 1))
  232. (setq e (exp 1))
  233. (setq pi (* 4 (atan 1)))
  234. (fset 'justify-hard-to-read-block
  235. [escape ?7 ?9 right C-right return C-left return end delete ? home])
  236. (defun ^ (a b)
  237. (expt a b))
  238. (defun stddev (L)
  239. "finds standard deviation of list L"
  240. (sqrt (/ (std-helper L (avg L)) (- (sizeof L) 1))))
  241. (defun std-helper (L a)
  242. "recursively goes through L, adding partial standard deviation sum as it goes"
  243. (if (nullp L)
  244. 0
  245. (+ (^ (- (car L) a) 2) (std-helper (cdr L) a))))
  246. (defun stderr (L)
  247. "standard error"
  248. (/ (stddev L) (sqrt (sizeof L)) ))
  249. (defun dot (L1 L2)
  250. ; "dot product" of L1 and L2
  251. (if (and (= (sizeof L1) 0)
  252. (= (sizeof L1) 0))
  253. '()
  254. (if (= (sizeof L1) (sizeof L2))
  255. (cons (* (car L2) (car L1))
  256. (dot (cdr L1) (cdr L2)))
  257. "lists not equal size")))
  258. (defun sumfrom1ton (N) (message "%x" (/ (* N (+ N 1)) 2)))
  259. ;; i don't remember how to use this one
  260. (defun debias (bias belief)
  261. (+ 50 (* (sign (- belief 50)) (sqrt (* (- 1 bias ) (expt (- belief 50) 2))))))