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

The literal year overdue merger... #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 65 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,83 @@
# MoonScript Textadept support
[![license][6i]][6l]
[Moonscript][4] module for [Textadept][1].

This package comes with both a theme and a syntax lexer.
## Information
This module comes with snippets, theme, lexer, and auto lint for Moonscript.
The snippets can be found under the **snippets.lua** file. The theme is located
under **themes/** directory. The lexer is in **lexer/** directory. Auto linting
allows you to have your work checked after save. It is disabled by default, but
you can very easily enabled as described below, under *Usage*.

![screenshot](https://raw.githubusercontent.com/leafo/moonscript-textadept/master/screenshot.png)

## Install
To install, you need to clone the repository into your **_USERHOME/modules** directory:

To install, copy `lexers/moonscript.lua` to a `lexers` directory in your local
textadept directory (usually `.textadept`).
```
cd ~/.textadept/modules
git clone https://github.com/leafo/moonscript-textadept.git \
moonscript
```

You are done! If you want to use the latest in development version of the lexer,
or any of the other abilities of the module, then continue along in *Usage*.

To install the theme copy `themes/moon.lua` to a `themes` directory in your
local textadept directory.
### Usage

#### enable auto lint.
You only need to modify your **_USERHOME/init.lua** file with the following:

```
-- init.lua

Update your `init.lua`:
_MOONAUTOLINT = true
```

#### moonscript lexer
Copy the **lexers/moonscript.lua** file into your **_USERHOME/lexers/**
directory:

```
cp ~/.textadept/modules/moonscript/lexers/moonscript.lua \
~/.textadept/lexers/moonscript.lua
```

#### Theme install
To install the theme, copy **themes/moon.lua** into **themes/** directory in
your local textadept directory.

```
cp ~/.textadept/modules/moonscript/themes/moon.lua \
~/.textadept/themes/moon.lua
```

Then update your **_USERHOME/init.lua** with the following:

```lua
-- enable the lexer
local file_types = require "textadept.file_types"
file_types.extensions.moon = "moonscript"
-- init.lua

-- enable the theme, with a custom font (optional)
ui.set_theme(CURSES and "term" or "moon", {
font = "Source Code Pro",
fontsize = 14,
})
```

## Keybindings

```
Keys Action
cl+s opens snippets directory for modifying.
cR runs `moonc` on the current moonscript file.
cr runs `moon` on the current moonscript file.
cB builds the project with tup.
```

[1]: http://foicica.com/textadept/
[2]: https://twitter.com/a_baez
[3]: https://twitter.com/moonscript
[4]: http://moonscript.org/
[5]: http://gittup.org/tup/
[6i]: https://img.shields.io/badge/license-MIT-green.svg
[6l]: ./LICENSE
66 changes: 60 additions & 6 deletions init.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,62 @@
local file_types = require "textadept.file_types"
file_types.extensions.moon = "moonscript"
--- the Textadept initializer for the Moonscript module.
-- @copyright 2015-2016
-- @license MIT (see LICENSE)
-- @module init

ui.set_theme(CURSES and "term" or "moon", {
font = "Source Code Pro",
fontsize = 14,
})
local _snippets = require("moonscript.snippets")

textadept.file_types.extensions.moon = 'moonscript'
textadept.editing.comment_string.moonscript = '--'

textadept.run.compile_commands.moonscript = 'moonc %f'
textadept.run.run_commands.moonscript = 'moon %f'

textadept.run.build_commands["Tupfile(%.lua)?"] = "tup"

events.connect(events.LEXER_LOADED, function (lang)
if lang ~= 'moonscript' then return end

buffer.tab_width = 2
buffer.use_tabs = false
end)

if type(snippets) == 'table' then
snippets.moonscript = _snippets
end

keys.moonscript = {
[not OSX and not CURSES and 'cl' or 'ml'] = {
-- Open this module for editing: `Alt/⌘-L` `M`
s = function()
io.open_file(_USERHOME..'/modules/moonscript/snippets.lua')
end,
},

}

--- compiles automatically any moonscript file.
-- disable by changing _AUTOLINT to false.
events.connect(events.FILE_AFTER_SAVE, function()
if buffer:get_lexer() ~= 'moonscript' or not _MOONAUTOLINT then return end
buffer:annotation_clear_all()
local err = io.popen("moonc -l " .. buffer.filename .. " 2>&1"):read('*a')

local line = err:match("^.+(%d+).+>>")
if line and tonumber(line) > 0 then
line = tonumber(line) - 1
local msg = err:match(">>.+"):gsub('>>%s+','')
-- If the error line is not onscreen, annotate the current line.
if (line < buffer.first_visible_line or
line > buffer.first_visible_line + buffer.lines_on_screen) then
msg = 'line '..(line + 1)..'\n'..msg
line = buffer:line_from_position(buffer.current_pos)
end
buffer.annotation_visible = 2
buffer.annotation_text[line] = "Error: " .. msg
buffer.annotation_style[line] = 8 -- error style number
buffer:goto_line(line)
end
end)


return { }
Loading