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

evaluate buffer or region? #43

Open
sunilw opened this issue Feb 22, 2014 · 6 comments
Open

evaluate buffer or region? #43

sunilw opened this issue Feb 22, 2014 · 6 comments

Comments

@sunilw
Copy link

sunilw commented Feb 22, 2014

Just wondering if at some point you will add the ability to evaluate a region or the buffer.

@skeeto
Copy link
Owner

skeeto commented Feb 22, 2014

Just wondering if at some point you will add the ability to evaluate a region or the buffer.

You can evaluate the entire buffer with skewer-load-buffer. It's a little bit smarter than just sending the whole buffer the same way it sends expressions. The buffer is loaded as a script so you get correct line number / file information in your error messages.

I don't see much use in a skewer-eval-region. For most users it's probably a sign that they're doing something wrong, so I don't really want to add one. Fortunately you can provide your own just by dropping this in your Emacs config:

(defun skewer-eval-region (beg end)
  "Execute the region as JavaScript code in the attached browsers."
  (interactive "r")
  (skewer-eval (buffer-substring beg end) #'skewer-post-minibuffer))

@romario89
Copy link

You can evaluate the entire buffer with skewer-load-buffer
That (M-x skewer-load-buffer) seems to be necessary for evaluating html tags with C-M-x. I have tried to make C-M-x work for an hour (js2 & C-x C-e was working fine) and it somehow just didn't work. After I've done M-x skewer-load-buffer, it started to work fine. I 've looked back on the READ.md if M-x skewer-load-buffer was talked about no it wasn't. I recommend it be included in READ.md.

@skeeto
Copy link
Owner

skeeto commented Nov 21, 2016

M-x skewer-load-buffer only works with JavaScript, and should only be
used with JavaScript. Skewer's JavaScript evaluations normally go
through an indirect eval() in the page. For skewer-load-buffer, a
snapshot of the buffer is hosted by Skewer and added to the page via a
script tag. It's semantically slightly different, but occasionally is
convenient or necessary.

It has no meaning for skewer-html-mode. But I'm curious why it seems to
fix your problem. Maybe it's some kind of autoload issue?

@romario89
Copy link

romario89 commented Nov 22, 2016

What you said eventually turned out to be right: After one or two successfully working C-M-x key presses, it stopped evaluating the html tags.

Now I've restarted Emacs and run-skewer from scratch and did M-x skewer-html-mode and it started to evaluate the html tags (finally :) For instance it evaluated the
< b u tton class="myButton" on c lick=" calculate()" type="button" > CALCULATE </ button > successfully.

That's fine. But out of curiosity I reproduced the steps which caused me trouble at first hand. I noticed that if I try to M-C-x on a tag such as on:
< s p an class="caption_span">< i>< u >Old Tax Rate | < / u>< / i>< / s pan>< b r > ( where | is the position of cursor) it then stops evaluating all html tags! But if I place the cursor on < / span > tag, then it works! I guess that's where I went into trouble at first hand. Now it's all fine but I think that this small detail be included somewhere in the documentation. My apologies if it was already included but I didn't see it :=)

@skeeto
Copy link
Owner

skeeto commented Nov 22, 2016

Yup, this is a bug. The problem is all those tags being on the same
line, which the code was not prepared to handle. It causes the HTML
selector to be miscomputed, which then crashes the script, which breaks
the long poll loop and prevents further tag evaluation.

I gave the HTML selector stuff an overhaul, this time not being
sensitive to newlines. This negative property was inherited from
sgml-get-context, itself sensitive to newlines.

@kisp
Copy link

kisp commented Feb 26, 2023

Just wanted to note that I did add a skewer-eval-region as defined above together with a (define-key skewer-mode-map (kbd "C-c C-r") 'skewer-eval-region).

I find it useful sometimes to control exactly (and to know beforehand) what will get evaluated.

Of course, I'll run skewer-eval-defun and skewer-eval-last-expression whenever it makes sense. :)

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

No branches or pull requests

4 participants