My personal .emacs.d folder

curry-gist.el 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. ;;; Curry, rcurry, compose, pretty-curry-compose, all from:
  2. ;;; https://gist.github.com/eschulte/6167923
  3. (defsubst curry (function &rest arguments)
  4. (lexical-let ((function function)
  5. (arguments arguments))
  6. (lambda (&rest more) (apply function (append arguments more)))))
  7. (defsubst rcurry (function &rest arguments)
  8. (lexical-let ((function function)
  9. (arguments arguments))
  10. (lambda (&rest more) (apply function (append more arguments)))))
  11. (defsubst compose (function &rest more-functions)
  12. (cl-reduce (lambda (f g)
  13. (lexical-let ((f f) (g g))
  14. (lambda (&rest arguments)
  15. (funcall f (apply g arguments)))))
  16. more-functions
  17. :initial-value function))
  18. ;;; compact display
  19. ;; (defun pretty-curry-compose ()
  20. ;; (mapc (lambda (pair)
  21. ;; (let ((regexp (car pair))
  22. ;; (symbol (cdr pair)))
  23. ;; (font-lock-add-keywords 'emacs-lisp-mode
  24. ;; `((,regexp
  25. ;; (0 (progn (compose-region (match-beginning 1) (match-end 1)
  26. ;; ,symbol)
  27. ;; nil)))))))
  28. ;; '(("(\\(compose\\)[ \t\n\r]" . ?\∘)
  29. ;; ("(\\(curry\\)[ \t\n\r]" . ?\»)
  30. ;; ("(\\(rcurry\\)[ \t\n\r]" . ?\«))))
  31. ;; (add-to-list 'emacs-lisp-mode-hook 'pretty-curry-compose)
  32. ;;; color these functions like keywords
  33. (font-lock-add-keywords 'emacs-lisp-mode
  34. '(("(\\(compose\\)[ \t\n\r]" 1 font-lock-keyword-face)
  35. ("(\\(curry\\)[ \t\n\r]" 1 font-lock-keyword-face)
  36. ("(\\(rcurry\\)[ \t\n\r]" 1 font-lock-keyword-face)))