Giter VIP home page Giter VIP logo

imp.el's Introduction

Impatient Mode

See the effect of your HTML as you type it.

Installation through MELPA

The easiest way to get up and running with impatient-mode is to install it through MELPA. If you're not already using MELPA, it's quite easy to setup.

Installation from Source

If you are installing from source, please note that this package requires both simple-httpd and htmlize in order to operate. The simple-httpd webserver runs within emacs to serve up your buffers as you edit them. htmlize is used to send font lock highlighting to clients for non-HTML buffers.

simple-httpd can be installed through MELPA or directly from GitHub.

htmlize is also available through MELPA.

Once you have installed simple-httpd and htmlize and you've cloned impatient-mode, you can add impatient-mode to your load path and require it:

(add-to-list 'load-path "~/.emacs.d/impatient-mode")
(require 'impatient-mode)

Using impatient-mode

Enable the web server provided by simple-httpd:

M-x httpd-start

Publish buffers by enabling the minor mode impatient-mode.

M-x impatient-mode

And then point your browser to http://localhost:8080/imp/, select a buffer, and watch your changes appear as you type!

If you are editing HTML that references resources in other files (like CSS) you can enable impatient-mode on those buffers as well. This will cause your browser to live refresh the page when you edit a referenced resource.

Except for html-mode buffers, buffer contents will be run through a user-defined filter. The default user filter is htmlize, but you can set your own with imp-set-user-filter. The user filter is nothing but a regular elisp function. Here's how you would define a basic filter:

(defun my-filter (_)
  (princ "<html><body>test</body></html>" (current-buffer)))

The original editing buffer is passed along the user filter as a parameter, which we didn't use in the previous example, but which is demonstrated in the following example:

(defun my-filter (buffer)
  (let ((count 
     (with-current-buffer buffer
           (count-words-region (point-min) (point-max)))))
    (princ (format  "<html><body>%d</body></html>" count) (current-buffer))))

You can remove user filters with imp-remove-user-filter, which will reset the default htmlize. For reference, this is how the default user function is defined:

(defun default-user-filter (buffer)
  "Htmlization of buffers before sending to clients."
  (let ((html-buffer (save-match-data (htmlize-buffer buffer))))
    (insert-buffer-substring html-buffer)
    (kill-buffer html-buffer)))

Security implications

Please be aware that enabling impatient-mode exposes the whole directory in which the file resides, not only the file itself. If our file is accessible under http://localhost:8080/imp/live/example.txt/, it is possible to access http://localhost:8080/imp/live/example.txt/a-file-in-the-same-directory/or-even/a-subdirectory-of-it.txt. It's especially dangerous when enabling impatient-mode for files like ~/.bashrc because it allows to access any file in the user's home directory files such as ~/.ssh/id_rsa.

This behavior is not a bug, it is needed for the HTML files to work properly along with their resources (such as CSS and JS). Please be aware of what is exposed and/or configure your filewall accordingly.

imp.el's People

Contributors

brool avatar danielsz avatar leppert avatar mendartis avatar netguy204 avatar pkkm avatar skeeto avatar vifon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

imp.el's Issues

<script> tag with src cause imp stop updating

Whenever I have a html file with script tag like this

<!DOCTYPE html>
<html>
 <head>
   <title>Test</title>
   <script type="text/javascript" src="test.js"></script>
 </head>
 <body>
 </body>
</html>

the file stop updating.

Here is the javascript error I found in firebug

TypeError: doc.body is null

    iwindow.scrollTo(offX, offY != null ? offY : doc.body.clientHeight);

I am using Firefox 24

syncing between html source and rendered page

I have two question regarding the issue:

1- can I sync between the html source (in the emacs buffer) and the rendered page as in AUCTEX. For example, I want to click on the code it takes me to the rendered position and vice versa.

2- Can i render to an emacs window (not to an external browser) for simple html files.

doc.body.clientHeight -> document.body.clientHeight in chrome

Hi there
I'm not sure whether this is an actual issue, or I'm dense or something, but I was getting 500 errors when running impatient-mode.

Digging around a bit, I found references to doc.body.clientHeight were causing problems. Changing it to document.body.clientHeight sorted things out for me.

Not sure whether you want/need to change anything, but thought I'd let you know, to be on the safe side.

Thanks for a FANTASTIC system.

browser tab shows htmlized buffer, not rendered html

I had htis problem once before and cannot remember how I fixed it, or if it just somehow went a way by accident. When I tyr to view html buffers using impatient mode, I don't see the html itself; instead, I get a picture of the buffer, rendered as HTML (see image below).

Inspecting the source, I see that the document in the content iframe contains a comment <!-- created by htmlize-1.51 in css mode.-->.

Any idea what might be causing this? seems like maybe
htmlized output

avoid unnecessary refresh

Thinks imp.el, I love it!
I want that after-save-hook can be used instead of after-change-functions. This avoids unnecessary refresh.
any opinions about this?

Wrong mime type

When i enable impatient mode on a html buffer with an associated css file, the browser does not update when i change the css. If i enable impatient mode on the css file, the browser tries to update the html when the css is changed, but it is unable to use the css file, as the mime type is now text instead of css. I am not interested in previewing the css file in the browser, I just want html page to update when the css changes. Is this the intended behavior?

Headers sent twice

httpd-send-file sends its own header, so with the latest changes you end up sending the header twice when serving a related file.

$ curl --head http://localhost:8080/imp/live/hello.html/hello.png
HTTP/1.1 200 OK
Server: simple-httpd (Emacs 24.1.1)
Date: Thu, 16 Aug 2012 21:42:21 EDT
Connection: keep-alive
Content-Type: text/plain
Cache-Control: (max-age=60, must-revalidate)
HTTP/1.1 200 OK
Server: simple-httpd (Emacs 24.1.1)
Date: Thu, 16 Aug 2012 21:42:21 EDT
Connection: keep-alive
Content-Type: image/png
Last-Modified: Thu, 16 Aug 2012 21:12:38 EDT
ETag: "d6e434baf797dfc6"
Content-Length: 1116

HTML meta tags aren't previewed

HTML meta tags aren't obeyed due to the fact that the page is, understandably, rendered in an iframe. In my case this means <meta name=viewport content="width=device-width, initial-scale=1"> isn't observed, thereby affecting mobile previews. Is there an easy fix or workaround for this on the imp.el side?

Extensibility

Hi,

For non html files, buffers go through the htmlize-buffer function.
Following that line of thought, I would like to be able to register my own function on a per buffer basis. (This will give me the flexibility I need for tooling purposes).

I am willing to write a PR, but I would like to coordinate the effort with you. Is the idea acceptable to you? If so, we need to decide what that function will return: a string of the html document, a buffer with a html document, etc.

Thanks!

html is rendering as plain text instead of html?

i am writing a minor mode on top of imp.el

(defun foo (buffer)
  (with-temp-buffer
    (funcall 'web-mode)
    (httpd-start)
    (impatient-mode)))

i have created a temporary buffer which has html content and enabled impatient mode in it. when i browse, it is showing as plain text instead of html.

im

can't preview the html on Chrome

Hi, I have installed the imp, but when I call imp-visit-buffer, the preview page only shows me a "0".

Could you point me the right direction?

Thanks?

example of major-mode senstivity, i.e. org-mode support

Don't know if this is useful, but it made me happy.

(defun imp-htmlize-filter (buffer)
  "Alternate htmlization of BUFFER before sending to clients."
  (let ((m (with-current-buffer buffer major-mode)))
    (case m
      (org-mode
       (let ((output (current-buffer)))
         (with-current-buffer buffer
           (org-export-as-html 100 nil output))))
      (t
       (let ((html-buffer (save-match-data (htmlize-buffer buffer))))
         (insert-buffer-substring html-buffer)
         (kill-buffer html-buffer))))))

Other approaches would probably be better though.

Fun hack, thanks!

Pages inaccessible with uniquify enabled in a specific setup

Steps to reproduce

  1. Enable uniquify (a package which automatically renames the buffer names to make them unique in a sensible way).
  2. (setq uniquify-buffer-name-style 'forward)
  3. Open ~/dir1/example-file and ~/dir2/example-file.
  4. Enable impatient-mode in ~/dir1/example-file.
  5. Try to access it in a web browser.

What happens

The requested URL is forbidden.

error: Buffer dir1 is private or doesn't exist.

What was expected

The file's contents should be displayed.

Browser returns to top of document on change

If you have a long document that requires the browser window to have a scroll bar, any change of the buffer (and subsequent change of the served page) causes the browser to return to the top of the page.

Steps to reproduce:

  1. Open a long buffer and share it with impatient mode.
  2. Navigate to the impatient mode address in Firefox and scroll down.
  3. Make any change to the buffer.
  4. Observe that the Firefox page has snapped back to the top of the page.

Expected behavior:

I would expect it to stay at the same point on the page. As it is, this makes it impossible to follow along with the work that is being done.

System information:

  • Firefox 20 "for Ubuntu" (using a clean profile, i.e. no extensions, and in safe mode)
  • Ubuntu 12.04
  • Emacs version (from ppa:cassou/emacs): GNU Emacs 24.3.1 (x86_64-pc-linux-gnu, GTK+ Version 3.4.2) of 2013-04-14 on chindi10, modified by Debian
  • Impatient mode version: 20130127.1656
  • Simple HTTPd version: 20121224.1121

Other notes:

This does not happen on Chromium on my system.

Make at least one formal release.

Impatient-mode has been sitting at "0.1" since the beginning. Bump the version up to at least 1.0.0 and create a signed tag matching the version number. I suggest sticking to the semver spec (always use 3 segments) when picking a version.

403 Forbidden when there're several same filename's files

I have 2 test.html in different dirs:
testjs/test.html
test/test.html

When I access them using impatient-mode, the server responses with
"
**Forbidden

The requested URL is forbidden.

error: Buffer testjs is private or doesn't exist.**
".

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.