Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skewer-eval-and-print-last-expression. #57

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

kostafey
Copy link

@kostafey kostafey commented Aug 6, 2015

It's an attempt to bring something like CIDER cider-pprint-eval-last-sexp.

@skeeto
Copy link
Owner

skeeto commented Aug 6, 2015

I like the idea, but not this particular (fragile) approach. Also, there already is a skewer-eval-print-last-expression, which prints the result into the current buffer. That's how skewer-eval-last-expression behaves with a prefix argument, which itself is a common Emacs convention.

Taking a look at cider-pprint-eval-last-sexp, I see it puts the output in a deciated *cider-result* buffer? What do you think of something like this instead? (Hmmm, with the js2-mode overhead, this is getting a little copy-pastey).

(defvar skewer-result-buffer "*skewer-result*")

(defun skewer-pprint-eval-last-expression ()
  (interactive)
  (if js2-mode-buffer-dirty-p
      (js2-mode-wait-for-parse
       (skewer--save-point #'skewer-pprint-eval-last-expression))
    (cl-destructuring-bind (string start end) (skewer-get-last-expression)
      (skewer-flash-region start end)
      (skewer-eval string #'skewer-post-pprint :verbose t)
      (pop-to-buffer (get-buffer-create skewer-result-buffer))
      (erase-buffer)
      (js2-mode))))

(defun skewer-post-pprint (result)
  (if (not (skewer-success-p result))
      (skewer-post-minibuffer result)
    (let ((value (cdr (assoc 'value result))))
      (insert value)
      (insert "\n")
      (js2-reparse))))

With this name (pprint), I'd probably also add json-mode and json-format as new Skewer dependencies and use them to nicely format the result buffer. It should also be tied into the existing skewer-eval-print-last-expression somehow.

@kostafey
Copy link
Author

kostafey commented Jul 24, 2017

I've updated pull request according to your code. json-format is made very simple and straightforward, it's necessary when returned value contains objects. This cause error for https://github.com/gongo/json-reformat.

@kostafey
Copy link
Author

@skeeto Could you merge this pull request, please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants