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

Convert Inline Eval of a Form into a Comment (add result as a comment) #160

Closed
dharrigan opened this issue Jan 5, 2021 · 11 comments
Closed
Labels
enhancement New feature or request

Comments

@dharrigan
Copy link
Contributor

Hi,

Recently, Conjure (re-)learnt the ability to display the results of an evaluation beside the form as virtual text. This virtual text, being super doopar handy, unfortunately disappears when there is cursor movement.

It would be incredibly useful for composing results on the fly if the inline eval could also be converted into a comment which would greatly aid in train-of-thought, repl-driven development, demos, screencasts and so on. It is noted that another popular editor built upon Emacs offers this feature too (thus having a bit more parity with that would aid in people transitioning across)

A suggestion would be to use <prefix>ec to eval the form and add the result of the eval as a comment.

@Olical Olical added the enhancement New feature or request label Jan 5, 2021
@emilaasa
Copy link

emilaasa commented Jan 5, 2021

A great case that I use this for is rich comment forms:

(comment
  (my-fun-function good-argument) ; [1 2 3 4 5] 
  (my-fun-function bad-argument) ; OutOfMemoryError
    ) 

Another is for screencasts with limited screen real estate where this can be really effective.

@practicalli-johnny
Copy link

, e ; is the key binding I added to Spacemacs to eval a top level form to a comment.

I use eval top level form to comment extensively in my live broadcasts and screencasts, to explain what is going on with code.

I also rely on eval to comment when designing, especially with data structure design. This cuts down on cognitive load, as I have a reminder of the structure at a glance.

As mentioned by @emilaasa I also use eval to comment in rich comment blocks. This provides living documentation showing what to expect from important API calls in the namespace.

Thank you.

@sotte
Copy link

sotte commented Jan 5, 2021

A bit hacky, but hey :)

:nmap ,ec :ConjureEval<CR>A ; <ESC>"cp                                                                                                                  

Conjure stores the results of eval in the named register c. So this mapping turns

(comment
  (a.inc 2)
  (a.inc 3)  
)

into

(comment
  (a.inc 2) ; 3
  (a.inc 3)  
)

If you want a history of your execution + results you could also use the log buffer (,lv).

@dharrigan
Copy link
Contributor Author

Works great! Thank you.

@emilaasa
Copy link

Also testing it now and it works perfectly!

@Olical
Copy link
Owner

Olical commented Jan 26, 2021

Going to open this up for a little longer for more work. I want to add some config so people can have it use ;; (over ;) for the comment, just because it was requested. I don't really want this feature but still, it'll improve it for some people!

I also want to refactor how you invoke this, so it becomes something like <prefix>ece for current form, <prefix>ecw for current word and <prefix>ecr for the root form. People want to be able to eval different things into comments, so I need to provide a more general system for that, <prefix>ec is too short and specific already to open this up.

So, warning, the mapping will be changing on develop before I cut a release to be more general and open to extension.

@Olical Olical reopened this Jan 26, 2021
@dharrigan
Copy link
Contributor Author

I fully support this ;-)

@emilaasa
Copy link

emilaasa commented Jan 26, 2021 via email

@justone
Copy link
Contributor

justone commented Jan 26, 2021

This is a very cool feature, and one I will definitely use when pairing with others. Thanks for adding it.

@Olical
Copy link
Owner

Olical commented Jan 28, 2021

So I've split the mapping into <prefix>ece, <prefix>ecr and <prefix>ecw which map to current/root form and current word respectively. I hope they work well for you! You can always remap "eval current form into comment" to <prefix>e; etc if you so wish! The config can all be found in :h conjure.

@Olical
Copy link
Owner

Olical commented Jan 28, 2021

I've also added g:conjure#eval#comment_prefix which you can set to ";; " (with a trailing space) to have two semi-colon comments. I personally use single commas for any code or data and two for prose, but some people may want two everywhere.

@Olical Olical closed this as completed in 262cb2d Jan 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

6 participants