clojure layer: add cider-eval-sexp-fu

This commit is contained in:
syl20bnr 2015-03-20 23:27:08 -04:00
parent 890217a6f4
commit 2fa2c620ee
3 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,20 @@
;;; extensions.el --- Clojure Layer extensions File for Spacemacs
;;
;; Copyright (c) 2012-2015 Sylvain Benner
;;
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; URL: https://github.com/syl20bnr/spacemacs
;;
;; This file is not part of GNU Emacs.
;;
;;; License: GPLv3
;; Pre extensions are loaded *before* the packages
(defvar clojure-pre-extensions '())
;; Post extensions are loaded *after* the packages
(defvar clojure-post-extensions '(cider-eval-sexp-fu))
(defun clojure/init-cider-eval-sexp-fu ()
(eval-after-load 'eval-sexp-fu
'(require 'cider-eval-sexp-fu)))

View File

@ -0,0 +1,39 @@
# cider-eval-sexp-fu
<!-- markdown-toc start - Don't edit this section. Run M-x markdown-toc/generate-toc again -->
**Table of Contents**
- [cider-eval-sexp-fu](#cider-eval-sexp-fu)
- [Install](#install)
- [Usage](#usage)
- [Customization](#customization)
<!-- markdown-toc end -->
eval-sexp-fu.el extensions for [CIDER][].
This package briefly highlights evaluated sexps in a clojure buffer
connected to an nREPL via [CIDER][].
## Install
The package is not yet available in [MELPA][] repositories.
Check back soon for news.
You can easily install it by opening `cider-eval-sexp-fu.el` in Emacs and call
`package-install-from-buffer`.
## Usage
Just require it:
```elisp
(require 'cider-eval-sexp-fu)
```
## Customization
Customization is done via [eval-sexp-fu][].
[MELPA]: http://melpa.org/
[eval-sexp-fu]: https://github.com/hchbaw/eval-sexp-fu.el
[CIDER]: https://github.com/clojure-emacs/cider

View File

@ -0,0 +1,71 @@
;;; cider-eval-sexp-fu.el --- Briefly highlights an evaluated sexps.
;; Adapted from Sam Aaron's code found in emacs-live in order to
;; be distributable as a package by syl20bnr.
;; Author: Sylvain Benner <sylvain.benner@gmail.com>
;; Keywords: languages, clojure, cider
;; Created: 20 Mar 2015
;; Version: 1.0
;; Package-Requires: ((emacs "24") (highlight "0") (eval-sexp-fu "0.4.0"))
;; This file is not part of GNU Emacs.
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;; Tiny feature adding support for cider eval functions.
;; See `eval-sexp-fu' help for more info on how to configure the
;; flash behavior.
;;; Code:
(require 'highlight)
(require 'eval-sexp-fu)
(defun cider-esf--bounds-of-last-sexp ()
"Return the bounds of the defun around point.
Copies semantics directly from the fn cider-last-sexp to ensure highlighted
area is identical to that which is evaluated."
(cons (save-excursion
(backward-sexp)
(point))
(point)))
(defun cider-esf--initialize-cider ()
(define-eval-sexp-fu-flash-command cider-eval-last-sexp
(eval-sexp-fu-flash (cider-esf--bounds-of-last-sexp)))
(define-eval-sexp-fu-flash-command cider-pprint-eval-last-sexp
(eval-sexp-fu-flash (cider-esf--bounds-of-last-sexp)))
(define-eval-sexp-fu-flash-command cider-eval-defun-at-point
(eval-sexp-fu-flash (let ((bounds (cider--region-for-defun-at-point)))
(cons (first bounds) (second bounds)))))
;; Defines:
;; `eval-sexp-fu-cider-sexp-inner-list',
;; `eval-sexp-fu-cider-sexp-inner-sexp'
;; and the pprint variants respectively.
(define-eval-sexp-fu-eval-sexp eval-sexp-fu-cider-eval-sexp
cider-eval-last-sexp)
(define-eval-sexp-fu-eval-sexp eval-sexp-fu-cider-pprint-eval-sexp
cider-pprint-eval-last-sexp))
(eval-after-load 'cider
'(cider-esf--initialize-cider))
(provide 'cider-eval-sexp-fu)
;;; cider-eval-sexp-fu.el ends here