emacs mode?

33 views
Skip to first unread message

James Cooper

unread,
Apr 16, 2011, 10:44:32 PM4/16/11
to aspen...@googlegroups.com
Hi there,

Cool project.  I'm considering taking it for a spin and port a site I wrote in node.js over to it.  

What's the best way to get emacs configured so it uses python-mode for the first two pages in a file, and html or django mode for the bottom page?

I'm not an elisp whizz..  Does this involve configuring mmm?

A sample .emacs gist would be stellar if anyone has one.

cheers

-- James

Chad Whitacre

unread,
Apr 16, 2011, 11:00:02 PM4/16/11
to aspen...@googlegroups.com, James Cooper
James,

Not an emacs user myself, very interested in the answer to your question. Would love to put this on the site if/when someone figures this out.


chad




--
You received this message because you are subscribed to the Google Groups "aspen-users" group.
To post to this group, send email to aspen...@googlegroups.com.
To unsubscribe from this group, send email to aspen-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/aspen-users?hl=en.

James Cooper

unread,
Apr 17, 2011, 12:36:18 AM4/17/11
to aspen...@googlegroups.com, James Cooper
Hi Chad,

This turned out to be pretty easy



Then I customized it a bit for aspen.  Example file:

# imports

import sys

^L

# per request

foo = bar()

^L
<html>
    <title>hi</title>
</html>

___

This was my customization:

(defvar default-mode (list "nXHTML" 'nxhtml-mode))
(defvar second-modes (list
                      (list "Python" "#" "\x0c" 'python-mode)
))

So nxhtml-mode is the default mode.  That's probably what you want in case you have .html files that have no python.

Python blocks are any region that start with a # and end with a page break.  The # was the best idea I had about how to delimit the start of a Python block.  Open to better ideas.

Anyhow that seems to work pretty well.

___

tl;dr..   Grab the two-mode-mode.el file and configure your .emacs to load it.  

Is there a way to tell aspen to use a different file extension for simplate files?  I'd like to have something unique that I can tell emacs to associate with this mode.  Right now I'm just invoking it manually when I open a buffer.

-- James

Chad Whitacre

unread,
Apr 17, 2011, 3:07:31 AM4/17/11
to aspen...@googlegroups.com, James Cooper
James,
 
This turned out to be pretty easy

Sweet! I put in a quick link here:



Is there a way to tell aspen to use a different file extension for simplate files?  I'd like to have something unique that I can tell emacs to associate with this mode.  Right now I'm just invoking it manually when I open a buffer.

Hmmm ... what about a knob in aspen.conf like simplates_extension? So that would get tacked onto all requests so if you used ".smpl" then a request for /foo.html would resolve to /path/to/my/site/foo.html.smpl. But then what about /path/to/my/site/bar.gif.smpl? You can serve simplates besides HTML, though certainly that's most common. I guess in non-HTML cases you're generally going to have a stub in the template part. Like w/ json you would just have {{ json_encode(out) }} or some such. No mode necessary (html mode would be fine).

Is there a way in Emacs to use simplates-mode if a file has a page break or two? This could mess you up if you're Barry Warsaw and you use page breaks all the time. But maybe as a workaround?


chad





-- James

--

James Cooper

unread,
Apr 17, 2011, 11:16:09 AM4/17/11
to aspen...@googlegroups.com, James Cooper
Hi Chad,

Couldn't we just make the ".html" extension configurable?

[aspen]

simplate_extension=.smpl


And then you'd just name your files:

/
 index.smpl
 foo.smpl
 .aspen/
           my_include.smpl

etc?

-- James

Chad Whitacre

unread,
Apr 17, 2011, 3:29:39 PM4/17/11
to aspen...@googlegroups.com, James Cooper
James,

Well, the file extension determines the Content-Type header that is returned--*unless* you manually set it using response.headers.set('Content-Type', 'text/foo') in your simplate. So you can have a simplate named foo.pdf that automatically returns application/pdf data, or bar.png that automatically returns image/png data. And you could have a foo.smpl file where you set the Content-Type manually to text/html.

The default value is text/plain. But you can change this with default_mimetype in aspen.conf.


That way any unknown extension, including *.smpl, would be sent as text/html.

Unfortunately, though, only index.html is currently supported as the default filename. I like the idea of adding a default_filenames knob to aspen.conf as well, which would take care of that, I think.

On the mimetypes issue, I'm inclined to read a mime.types file from .aspen. This would be in addition to a mime.types file that I would bundle with aspen itself; see:


Then you could configure .smpl as text/html for your website.

How would you feel about those two configuration options (default_filename + mime.types)?



chad




-- James

--

James Cooper

unread,
Apr 17, 2011, 7:56:29 PM4/17/11
to aspen...@googlegroups.com, James Cooper
Hi Chad,

Yes, I think that combo would work well.  I didn't realize the default mime type was inferred from the file extension.  pretty cool!

-- James

Chad Whitacre

unread,
Apr 21, 2011, 4:10:05 PM4/21/11
to aspen...@googlegroups.com, James Cooper
James,

Ok, default_filenames and mime.types support added in 0.9.35:


Let me know if these don't work for you.



chad





-- James

--
Reply all
Reply to author
Forward
0 new messages