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

Integrate the OPI #1

Merged
merged 45 commits into from
Sep 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
63bd79b
Compile and execute Oz code from python
azarzadavila Aug 27, 2018
48f783c
Init structure plugin Command
azarzadavila Aug 27, 2018
c799b31
Enable Compilation and Execution of current file
azarzadavila Aug 27, 2018
d613c31
Show compilation/execution on new panel
azarzadavila Aug 27, 2018
6f52d19
Check if compilation fails
azarzadavila Aug 27, 2018
8b25580
Create Shortcut to oz_run
azarzadavila Aug 27, 2018
8e082ad
Rename command OzRun->OzCompile
azarzadavila Aug 29, 2018
c3b4bb1
Adding SocketPipe from Nassar github
azarzadavila Aug 29, 2018
a88848c
Rename oz-plugin -> oz-compile.py
azarzadavila Aug 29, 2018
f5b5f4f
Rename oz-compile.py -> oz_compile.py
azarzadavila Aug 29, 2018
42a52eb
Enable ozengine in parallel thread in console
azarzadavila Aug 29, 2018
e8ce622
Retrieving socket number from output
azarzadavila Aug 29, 2018
ed9313e
Start ozengine at init SubOz to retrieve socket
azarzadavila Aug 30, 2018
ac45247
fixup socket_pipe, import, attribute
azarzadavila Aug 30, 2018
7c7ee8c
Connect new socket
azarzadavila Aug 30, 2018
efe8eb5
Enable feed buffer
azarzadavila Aug 30, 2018
769b358
Update LICENCE
azarzadavila Aug 30, 2018
bdc7d2c
Enable feed/run shortcut
azarzadavila Aug 30, 2018
6fd9259
Update README
azarzadavila Aug 30, 2018
6f2b32b
fixup! Import space
azarzadavila Aug 31, 2018
a5032c9
Enable oz_kill command with {Application.exit 0}
azarzadavila Aug 31, 2018
85a60ff
fixup! self.running in class SubOz
azarzadavila Aug 31, 2018
43a2ab4
Add shortcut to kill subprocess ozengine
azarzadavila Aug 31, 2018
3ad9c1e
fixup! shortcut
azarzadavila Aug 31, 2018
879cdf3
Merge of thread that treats ozengine and socket
azarzadavila Sep 3, 2018
995dbac
Start ozengine at feed buffer if necessary
azarzadavila Sep 3, 2018
17a9b4a
Refactor
azarzadavila Sep 3, 2018
eb88bad
[WIP] kill oz
azarzadavila Sep 3, 2018
c6fe8e0
Feed region
azarzadavila Sep 3, 2018
6a2e441
Update shortcuts
azarzadavila Sep 3, 2018
db2d2bc
Destroy output panel when oz is killed
azarzadavila Sep 3, 2018
6ab373d
Update README
azarzadavila Sep 3, 2018
9b31a35
Use two different panels
layus Sep 3, 2018
9d34c32
Update kill shortcut
azarzadavila Sep 3, 2018
cc7fca6
Clear panels on restart
layus Sep 3, 2018
03e6a9a
Merge pull request #2 from layus/clear-panel
azarzadavila Sep 3, 2018
085520b
Remove redundant keymap files
layus Sep 4, 2018
24bff13
Add more natural keymap variants, remove useless oz_run
layus Sep 4, 2018
5dd92b8
Add menu and context menu entries
layus Sep 4, 2018
6111929
Add a .sublime-commands to kill oz
layus Sep 4, 2018
cd12700
Add support for multiline comments
layus Sep 4, 2018
0b4ef50
Use a proper condition variable for exit notification
layus Sep 4, 2018
d9a2d42
Notify OPI shutdown with its return value
layus Sep 4, 2018
62c7405
Refactor, and improve logging
layus Sep 4, 2018
02e7da0
Update Readme for OPI integration
layus Sep 5, 2018
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
48 changes: 29 additions & 19 deletions Comment.tmPreferences
Original file line number Diff line number Diff line change
@@ -1,24 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>name</key>
<string>Comment</string>
<key>scope</key>
<string>source.oz</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string>%</string>
</dict>
</array>
</dict>
<key>uuid</key>
<string>7c251375-db32-45e7-b216-0fc70b53a6f5</string>
<key>name</key>
<string>Oz comments</string>
<key>scope</key>
<string>source.oz</string>
<key>settings</key>
<dict>
<key>shellVariables</key>
<array>
<dict>
<key>name</key>
<string>TM_COMMENT_START</string>
<key>value</key>
<string>%</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_START_2</string>
<key>value</key>
<string>/*</string>
</dict>
<dict>
<key>name</key>
<string>TM_COMMENT_END_2</string>
<key>value</key>
<string>*/</string>
</dict>
</array>
</dict>
</dict>
</plist>
8 changes: 8 additions & 0 deletions Context.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{ "caption": "-", "id": "Oz feed" },
{
"caption": "Oz: Feed to Compiler",
"command": "oz_feed_context",
"mnemonic": "F"
}
]
6 changes: 6 additions & 0 deletions Default.sublime-commands
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[
{
"caption": "Oz: Halt compiler",
"command": "oz_kill"
}
]
8 changes: 8 additions & 0 deletions Default.sublime-keymap
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{ "keys": ["ctrl+keypad_period", "ctrl+l"], "command": "oz_feed_line"},
{ "keys": ["ctrl+keypad_period", "ctrl+r"], "command": "oz_feed_region"},
{ "keys": ["ctrl+keypad_period", "ctrl+s"], "command": "oz_feed_region"},
{ "keys": ["ctrl+keypad_period", "ctrl+b"], "command": "oz_feed_buffer"},
{ "keys": ["ctrl+keypad_period", "ctrl+f"], "command": "oz_feed_buffer"},
{ "keys": ["ctrl+keypad_period", "h"], "command": "oz_kill"}
]
3 changes: 3 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
The MIT License (MIT)

Copyright (c) 2017 Robert Koeninger
Copyright (c) 2018 Andres Zarza Davila

Also, concerning socket_pipe.py : Copyright (c) 2016 Ramsey Nasser 2016

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
30 changes: 30 additions & 0 deletions Main.sublime-menu
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"caption": "Oz",
"mnemonic": "O",
"id": "oz-menu",
"children":
[
{
"caption": "Halt Oz",
"command": "oz_kill"
},
{ "caption": "-", "id": "feed" },
{
"caption": "Feed Line",
"command": "oz_feed_line",
"mnemonic": "L"
},
{
"caption": "Feed Selection",
"command": "oz_feed_region",
"mnemonic": "S"
},
{
"caption": "Feed File",
"command": "oz_feed_buffer",
"mnemonic": "F"
},
]
}
]
28 changes: 25 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,28 +1,50 @@
# Sublime/Oz

[Oz language](http://mozart.github.io/) support for [Sublime Text 3](https://www.sublimetext.com/).
This plugin intends to be an alternative to the classic Emacs Oz interface.
It is however still in work. Particularly killing subprocesses is still not
correctly implemented and not automatic.

## Usage

To evaluate some code, you need to feed it to the Oz compiler.
This can be done from the "Oz" menu, from the context menu or with the following shortcuts.

* Feed Line : **Ctrl-. + Ctrl-l**
* Feed Region (selected text): **Ctrl-. + Ctrl-r**
* Feed Buffer (the whole file): **Ctrl-. + Ctrl-b**

It may be useful to kill the running compiler. This is also available in the "Oz" menu, or with a shortcut.
The compiler will be restarted automatically on the next feed command.

* Kill oz : **Ctrl-. + h**


## Features

* OPI Integration - Submit current line/selection/file to the Oz compiler (as with the Emacs OPI).
* Syntax Highlighting - detects files matching the pattern `*.oz`.
* Comments - Applies Oz-style single line (%) comments using standard commands/shortcuts.
* Comments - Comment/Uncomment Oz code using standard commands/shortcuts.

## Automatic Installation

Sublime/Oz is available from [Package Control](https://packagecontrol.io/packages/Oz) under the name `Oz`.
This package contains only the syntax Highlighting and Comments. If you wish to
use the build/run features you need to install the plugin manualy.

## Manual Installation

Download this repo as an archive or `git clone` it under the `Packages` directory under your Sublime user path.
Download this repo as an archive or `git clone` it under the `Packages\User` directory under your Sublime user path.

On Windows, this is something like `C:\Users\%USER_NAME%\AppData\Roaming\Sublime Text 3\Packages`.

On linux, this is something like `/home/user/.config/sublime-text-3`

Once the `sublime-oz` package is in place, just restart Sublime, and it should be ready to go.

## Future Work

* Snippets
* Build/Run
* Formatting

## Contributing
Expand Down
43 changes: 43 additions & 0 deletions oz_compile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import subprocess
from subprocess import PIPE, Popen
import sublime
import sublime_plugin

def compile_mozart(file):
process = Popen(['ozc', '-c', file], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
process.wait()
return_code = process.poll()
outs = stdout.decode('utf-8')
errs = stderr.decode('utf-8')
return [outs, errs, return_code]

def execute_mozart(file):
process = Popen(['ozengine', file], stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
process.wait()
outs = stdout.decode('utf-8')
errs = stderr.decode('utf-8')
return [outs, errs]

class OzCompileCommand(sublime_plugin.TextCommand):
def run(self, edit):
file = self.view.file_name()
co = compile_mozart(file)
[out_comp, err_comp, code_comp] = compile_mozart(file)
window = sublime.active_window()
panel = window.find_output_panel('oz_panel')
if(panel == None):
panel = window.create_output_panel('oz_panel')
window.run_command('show_panel', {'panel':'output.oz_panel'})
panel.set_read_only(False)
panel.run_command("append", {"characters": "Compilation output :\n"})
panel.run_command("append", {"characters": out_comp+"\n"+err_comp+"\n"})
if(code_comp == 0):
[out_exec, err_exec] = execute_mozart(file+'f')
panel.run_command("append", {"characters": "Execution output:\n"})
panel.run_command("append", {"characters": out_exec+"\n"+err_exec+"\n"})
panel.set_read_only(True)
def is_visible(self):
print(self.view.window().active_panel())
return True
118 changes: 118 additions & 0 deletions oz_plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
import subprocess
from subprocess import PIPE, Popen
import sublime
import sublime_plugin
import threading
from .socket_pipe import OzThread

sp = None

def with_oz(f):
def wrapper(*args, **kwargs):
global sp
if not sp:
start_oz()
f(*args, **kwargs)
return wrapper

def start_oz():
global sp
sp = OzThread()
sp.start()

class OzRunCommand(sublime_plugin.TextCommand):
@with_oz
def run(self, edit):
pass

@with_oz
def feed_region(view):
global sp
msg = ""
for region in view.sel():
if not region.empty():
msg += view.substr(region)
sp.send(msg)

class OzFeedRegion(sublime_plugin.TextCommand):
def run(self, edit):
feed_region(self.view)

def is_enabled(self):
for region in self.view.sel():
if not region.empty():
return True
return False

def description(self):
"Feed the selected text to the Oz compiler"


@with_oz
def feed_line(view):
global sp
msg = ""
for region in view.sel():
if region.empty:
line = view.line(region)
msg += view.substr(line) + '\n'
sp.send(msg)

class OzFeedLine(sublime_plugin.TextCommand):
def run(self, edit):
feed_line(self.view)

def is_enabled(self):
for region in self.view.sel():
if region.empty():
return True
return False

def description(self):
"Feed the current line to the Oz compiler"

class OzFeedBuffer(sublime_plugin.TextCommand):
@with_oz
def run(self, edit):
global sp
msg = self.view.substr(sublime.Region(0, self.view.size()))
sp.send(msg)

def description(self):
"Feed the current file to the Oz compiler"

class OzFeedContext(sublime_plugin.TextCommand):
def run(self, edit):
global sp
msg = ""
for region in self.view.sel():
if not region.empty:
return feed_region(self.view)
return feed_line(self.view)

def is_enabled(self):
for region in self.view.sel():
return True
return False

def description(self):
"Feed text to the Oz compiler"


def stop():
global sp
if sp:
sp.stop()
sp = None

class OzKillCommand(sublime_plugin.TextCommand):
def run(self, edit):
stop()

def description(self):
"Kill the Oz compiler"

class ExitListener(sublime_plugin.EventListener):
def on_pre_close(view):
stop()

Loading