defunkt / coffee-mode Goto Github PK
View Code? Open in Web Editor NEWEmacs Major Mode for CoffeeScript
Home Page: http://ozmm.org/posts/coffee_mode.html
Emacs Major Mode for CoffeeScript
Home Page: http://ozmm.org/posts/coffee_mode.html
The code below causes Aquamacs to freeze for a few seconds in coffee-mode. Repeating the last line will lengthen the freeze. keyboard-quit doesn't stop the freeze, so I'm not entirely sure what's happening, but I suspect it is caused by the syntax highlighter misinterpreting the '/' character as a regexp delimiter (as in #23) and then choking on the brackets. It can be worked around by putting a closing '/' in a comment at the end of the line.
class Woot
donk: ->
1 / 1
[[-0]]
[[-0]]
[[-0]]
[[-0]]
[[-0]]
[[-0]]
[[-0]]
[[-0]]
[[-0]]
The CoffeeScript (compiler) sources are full of trailing whitespace, so trying to edit them with a non-customized coffee-mode results in a mess.
In general, this seems like a feature that can be useful, but has no place in a language mode.
Without a license your code can't legally be used by anyone without explicit permission.
I think there is a problem with the regexp for regexps, since it can be triggered by two ordinary divisions, e.g.:
1/2 + 3/4
Is there a way to make the imenu from multiple files be found on a Tags file?
�[1Gcoffee> �[0K�[9Gdd = 2
dd = 2
�[34m2�[39m
�[1Gcoffee> �[0K�[9G
have a coffee file like
a = (t) -> (couple spaces AFTER the arrow)
......
Do some editing, and save the coffee file.
Result:
a = (t) -> (no more spaces after the arrow)
Similarly, a blank line with couple spaces becomes a blank line with not spaces.
They look the same, but it creates a lot of problems:
This code needs to run only once, not every time coffee-mode
loads. By putting this code into the major-mode definition, you force users to put their customizations into a hook instead of an eval-after-load
block.
On Windows , Node v0.8.2 ,CoffeeScript version 1.3.3
I found a problem on compiling large coffee file (above150 lines) in coffee-mode: if there is some syntax error in the file. the shell-command-to-string function fail to fetch any error message from the shell command "coffee -b --bare largefile.coffee" process.
any one help?
Single quoted strings do not show up as strings. Only double quoted strings do.
Hello, cofee-previous-indent seems to be hanging emacs, if the previous line is not indented. Here's a quick fix, hope i didn't break anything ;)
(save-excursion
(forward-line -1)
(if (bobp)
0
(progn
(while (coffee-line-empty-p) (forward-line -1))
(current-indentation)))))
The symbol old-bolp
as seen here is void (undefined).
I imagine this was just a mishap during a refactor, but it stops the Backspace key from working in certain situations.
Right now the examples include an automatic compile function which is called in "before-save-hook". This means that it compiles the old version of the file, before the latest changes have been saved. To get the latest changes compiled, you have to make a dummy edit, and save again.
It would be great to have an after-save-hook instead, to properly auto-compile the latest version of the file.
Beginning with Emacs 24, modes for programming languages are supposed to derived from prog-mode
.
In both thisRow
and watch_this
the 'this' part is highlighted.
I'm using coffee-mode full-time! I just checked whether I should update my copy and noticed that while the version number is unchanged, the diff between what I have from a few months back and where you are now is significant. In terms of lines of diff, anyway. Updating the version number when merging pulls would be helpful. Thanks for a great tool.
I'm getting this error when I open an empty .coffee file and press enter. I've tested it with no other customizations than the ones documented in the README. I'm running GNU Emacs 23.1.1 on Linux.
The following bit will cause coffee-mode to freeze mid-display
hPI = Math.PI/2
for v in [ [ -1, 2], [ 1, 2], [ 1, 0], [ -1, 0],
[ PI-1, 2], [ PI+1, 2], [ PI+1, 0], [ PI-1, 0],
[ -1, 3], [ 1, 3], [ 1, 1], [ -1, 1],
[hPI-1, 3], [hPI+1, 3], [hPI+1, 1], [hPI-1, 1],
[ PI-1, 3], [ PI+1, 3], [ PI+1, 1], [ PI-1, 1] ]
false
but neither
hPI = Math.PI/2 # /
for v in [ [ -1, 2], [ 1, 2], [ 1, 0], [ -1, 0],
[ PI-1, 2], [ PI+1, 2], [ PI+1, 0], [ PI-1, 0],
[ -1, 3], [ 1, 3], [ 1, 1], [ -1, 1],
[hPI-1, 3], [hPI+1, 3], [hPI+1, 1], [hPI-1, 1],
[ PI-1, 3], [ PI+1, 3], [ PI+1, 1], [ PI-1, 1] ]
false
nor
hPI = Math.PI/2
for v in [ [ -1, 2], [ 1, 2], [ 1, 0], [ -1, 0],
[ PI-1, 3], [ PI+1, 3], [ PI+1, 1], [ PI-1, 1] ]
false
have trouble. Seems like a regexp parsing problem.
Emacs 23.2.
I find that none of the coffee-indentors-bol actually match coffee-indenters-bol-regexp while editing except when the line containing the indenter was itself at an indentation level of 0.
For example, this is the unaltered coffee-mode indentation behavior that I observe:
if happy
if know it
claphands() # Shouldn't this have been indented?
I find that I can make it behave as I want it to if I remove the ^ from coffee-indenters-bol-regexp, as so
;; Works
(defun coffee-indenters-bol-regexp ()
(regexp-opt coffee-indenters-bol 'words))
instead of
;; Broken
(defun coffee-indenters-bol-regexp ()
(concat "^" (regexp-opt coffee-indenters-bol 'words)))
Based on the ELisp manual, I think that my replacement is correct when using the looking-at function.
Has anyone else actually observed this problem? It's just so fundamental that I reasoned it must be a problem with my particular setup...
Hi,
it's quite unusual for an Emacs major mode to use tab-width for indentation depth. c-mode, c++-mode, javascript-mode etc use c-basic-offset; python-mode uses py-indent-offset; ruby-mode uses ruby-indent-level; sh-mode uses sh-basic-offset... you get the idea. See also http://www.emacswiki.org/emacs/IndentationBasics
It would be nice if coffee-mode would have a similar setting. I prefer to leave tab-width at 8 for best compatibility with other people's code, but that's far too wide for indentation of course.
Thanks!
PS: It looks like sometimes tab-width is used (implicitly by indent.el's insert-tab), sometimes coffee-tab-width. Is this by design?
Hitting RET
with point here:
task 'test', 'Run the test suite.', ->
for file in fs.readdirSync('test/*')
^
Needs to move point here:
task 'test', 'Run the test suite.', ->
for file in fs.readdirSync('test/*')
^
Same with if
and else
.
I'm new to emacs so it is possible that it is my fault, but auto-indent doesnt work for me in coffee-mode.
I'm using emacs 23.2 in fedora 15, and installed coffee-mode as described in the README file. I also added the suggested lines to my .emacs file. I'm using the suggested 2-space indentation in the config.
I'm sure coffee-mode works, because the window does have the CoffeeScript menu, and the mode indicator is 'Coffee'.
Whenever i press RET, the cursor goes to the first character of the new line, except when there is an '->' sign, or something that indicates that the indentation level of the next line should be incremented by one. In this case, the indentation level is 1, so the cursor will be on the third character of the new line. Indentation behaves the same no matter what the current indentation level is.
Hi, using latest coffee mode from the git repo, and it will never auto indent beyond the first level for me.
pressing ret on second line
if foo:
if bar:
^ cursor
pressing RET on fourth line
class Foo
constructor: ->
if 1:
if foo:
^ cursor...
Anyone know what could be causing this?
I get an error "invalid option: -s" while compiling coffee with coffee-compile-file. When i run coffee binary it lack -s :
-i, --interactive
-r, --run
-o, --output [DIR]
-w, --watch
-p, --print
-l, --lint
-e, --eval
-t, --tokens
-v, --verbose
-n, --no-wrap
-g, --globals
--narwhal
--install-bundle
--version
-h, --help
Just asking for that to be implemented.
In
(add-hook coffee-mode-hook
'(lambda() (coffee-custom)))
coffee-mode-hook should be quoted
Emacs 24 introduces a new way to handle auto-indentation with Return - namely electric-layout-mode. The custom indentation logic enabled by default in coffee-mode doesn't work particularly well with electric-layout-mode enabled - it seems to me that everything get indented twice. I guess it would be nice if you added some check whether electric-layout-mode is enabled or not which would alter the indentation behaviour of coffee-mode.
It's easy to get Emacs 24 if you're an OS X user - just to a
brew install emacs --cocoa --use-git-head --HEAD
Hi!
I was testing you mode.
I followed your instructions to install this mode.
Here is coffe-script chunk in my .emacs file:
; Coffee-Script mode
(add-to-list 'load-path "~/.emacs.d/coffee-mode")
(require 'coffee-mode)
(add-to-list 'auto-mode-alist '("\\.coffee$" . coffee-mode))
(add-to-list 'auto-mode-alist '("Cakefile" . coffee-mode))
And when I compile my emacs file (using M-x emacs-lisp-byte-compile
, it throws this:
Compiling file /home/neoriddle/.emacs at Tue Sep 13 19:59:30 2011
.emacs:163:1:Error: Cannot open load file: coffee-mode
Is there something wrong?
Thank you very much.
Right now, only the first and last lines of the following are font-locked as comments, but everything should be:
###!
Something
Copyright (c) Foo and Bar
###
(Great work on coffee-mode! :)
...within strings and regexps.
--no-wrap command option in coffee has been changed to "-b" or "--bare" in the trunk.
Pusing this to Marmalade would make it easier for users to install via package.el
. Uploading is simple, but it has to follow the packaging guidelines, which includes having a ;;; coffee-mode.el ends here
at the very end of the file.
Please correct the link in the .el file from http://github.com/defunkt/coffee-script to http://github.com/defunkt/coffee-mode
It'd be nice to be able to configure at least some of the compilation options used by commands like coffee-compile-region
. I understand why -s
and -p
need to be there for that particular function, but --bare
seems a little more arbitrary, and in general it would make sense to be able to pass arbitrary numbers of compilation options.
Again, I'm happy to make a pull request to get this done, but I'm putting it here where smarter/more available people can contribute as well. Thanks for a great Emacs mode for CoffeeScript!
boolExp ? something : other
highlights something :
as if there were not a space before the colon (as an object literal).
If I add the following code to my .emacs file:
(defun coffee-custom ()
"coffee-mode-hook"
(set (make-local-variable 'tab-width) 2))
(add-hook 'coffee-mode-hook
'(lambda() (coffee-custom)))
... then I get tabs inserted as two spaces, which is correct. However, this breaks auto-indentation.
I then create a new .coffee file and type in a class without using the TAB key (i.e. just relying on auto-indentation). Note how, with tabs set to two spaces, auto-indentation doesn't indent the body of the bar function:
class Foo
bar: (baz) ->
qux()
If I remove the above snippet from my .emacs file and try again, the body of the bar function is indented automatically:
class Foo
bar: (baz) ->
qux()
First: thank you for all your hard work and contributions!
When compiling Node.js on Windows, the most common way is to use Cygwin. When using the coffee
command via Cygwin-compiled Node.js on Windows, you have to use Cygwin-style absolute paths. So for example, instead of:
coffee --compile foo.coffee
You have to use:
coffee --compile /cygdrive/c/users/my_user/foo.coffee
That goes for any paths used in the command, including output dirs for compiled JS. My feature request is this:
Could you add support for system-type
of windows-nt
to your major/minor modes such that paths expand to the absolute Cygwin-path as shown above? I'll try to fork and make a pull request, but I'm putting this here in case someone who is smarter or has more free time can tackle it first.
Thanks again for all your hard work!
Some modes support fill-paragraph (meta-q) on comments, with just the comment getting word wrapped (python-mode does this at least). Right now meta-q just reformats everything.
On the lastest version, the if == highlights "if =" green, while, like an assignment.
While a keyword in a camelCase variable, e.g. new in newTab
, is correctly not highlighted, a keyword in an underscored variable is incorrectly highlighted, e.g. new in new_tab
.
Block comments are not handled properly right now.
coffee-args-compile: '("-cb -o ../attachments")
Compiled and saved /_____ /src/test.js
The file was compiled and correctly saved in ../_attachments.
Coffee-mode is overriding the yas/expand
key, that for me is bound to TAB
.
What is the best way to get that working?
The example coffee-mode-hook has the argument --no-wrap, but that argument is no longer valid in the latest version of coffeescript. Including it as an argument for compilation will throw an error, so the example should be changed.
Patch adds some extra colors which I like. In this:
sum_the_nums = (num1, num2) => num1 + num2
Previously, everything on that line was black but with my patch "num1" and "num2" gets variable-font-locked and the "=>" operator keyword-font-locked. It makes it easier for me to see where the lambda functions start. YMMV :)
Explain the compile-file-on-save trick.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.