• This repository has been archived on 21/Jan/2019
  • Stars
    star
    138
  • Rank 263,536 (Top 6 %)
  • Language
    Emacs Lisp
  • Created about 12 years ago
  • Updated over 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Impatient html mode. See your changes in the browser as you type

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.

More Repositories

1

roku_media_server

A client and server combo for serving mp3s and other local media over your local network to your Roku set-top box.
Python
90
star
2

gambit-game-lib

Game library that exploits Gamit-C
C
24
star
3

OakOLED

C++
11
star
4

cljs-bench

Runs benchmarks against a range of Clojurescript versions and reports the results
Clojure
10
star
5

MOVE

Playing with the MOVE architectural concept
Clojure
9
star
6

brianscheme

An attempt at building a bootstrapped scheme
Scheme
5
star
7

scan_server

Web based application SANE to control a desktop scanner and saves and organizes the images into documents.
Python
5
star
8

clojure-gl

clojure opengl quick project
Clojure
5
star
9

1MonthLispGame

TB Tanks! My International Lisp Games Expo Entry
Clojure
5
star
10

LispGLShaders

Playing around with pixel and vertex shaders in OpenGL within Common Lisp
Common Lisp
4
star
11

bucketlogs

Python library/tool to fetch, parse, and optionally display your s3 bucket logs.
Python
4
star
12

BetaInvaders

"Invaders" for the Digispark Pro Beta Board
Arduino
3
star
13

rfpset

Fast-persistent set implementation in C and Ruby
Ruby
3
star
14

giggle

Write games in Lua. Leverage a high performance, multiplatform 2d game library in C++.
C
3
star
15

showoff-cljs

A "game library" written in Clojurescript
Clojure
2
star
16

racket-parsers

An implementation of a parsec-like parser in Racket
Racket
2
star
17

liquids

an iOS implementation of http://nullprogram.com/blog/2012/02/03/
Objective-C
2
star
18

ld23

My entry into the 23rd Ludum Dare "48 Hour" Competition
Clojure
1
star
19

assorted-parts

Quick designs for 3d print or cut. No particular theme other than they weren't big enough projects to warrant their own repo.
1
star
20

lithp

simple lisp interpreter written in c
C
1
star
21

tft_webserver

ESP8266 Arduino project for web controlled display
Arduino
1
star
22

cmsc313_examples

Example code for CMSC313
C
1
star
23

swarm-mothership

JavaScript
1
star
24

kahlua.js

Collection of knockout.js components with a quickscript.js flavor
Vim Script
1
star
25

BetaSketcher

Etch-a-sketch like program for the Digispark Pro Beta Shield
C++
1
star
26

daily-programmer

Occasional solutions to problems posted at http://www.reddit.com/r/dailyprogrammer
C++
1
star
27

cljs-base

My standard Clojurescript base project
Clojure
1
star
28

netguy204.github.com

web space for mymedia
1
star
29

ld42

Newspaper Sim
JavaScript
1
star
30

cpp-starter-project

A c++ starter project that builds using the lazy-cpp pre-processor and the Boehm collector
C
1
star
31

giggle_starter

A starter project for the giggle game library
Lua
1
star
32

platformer

May be an interesting physics driven platformer... one day.
Clojure
1
star
33

icestick-chisel-template

Template project that realizes an Icestick (ICE40-1K) FPGA from Chisel source code
Makefile
1
star
34

mancala

The game of Mancala in your browser. Touch friendly.
JavaScript
1
star
35

netguy204-python-experiments

Unlikely to be useful to anyone but me but this is a useful way for me to distribute this code to myself in a sane way
Python
1
star