-
Notifications
You must be signed in to change notification settings - Fork 89
Run plugin #82
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
Open
qrmoon
wants to merge
10
commits into
rxi:master
Choose a base branch
from
qrmoon:run-plugin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Run plugin #82
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
a6145c0
Add run.lua
504ca6f
Update README.md
85ceabb
Update run.lua
7f3dc07
Improve matching in run.choose
5fd0f2a
Rename run.lua to runinterminal.lua
fecd56b
Update README.md
34aa4b0
Default to $TERMINAL or xterm
691cae8
Add run.build method
219e9c8
Merge branch 'master' into run-plugin
6ea7d0e
Change default xterm arguments
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| local core = require "core" | ||
| local common = require "core.common" | ||
| local command = require "core.command" | ||
| local config = require "core.config" | ||
| local keymap = require "core.keymap" | ||
|
|
||
| local run = {} | ||
|
|
||
| -- return a function which will run the current doc | ||
| -- as a script for the given language | ||
| function run.lang(lang) | ||
| return function() | ||
| local doc = core.active_view.doc | ||
| if doc.filename then | ||
| doc:save() | ||
| else | ||
| core.error("Cannot run an unsaved file") | ||
| return | ||
| end | ||
|
|
||
| core.log "Running a file..." | ||
| local cmd = assert(config.run[lang]):format( | ||
| "\"" .. core.active_view.doc.filename .. "\"" | ||
| ) | ||
|
|
||
| os.execute(config.run_cmd:format(cmd)) | ||
| end | ||
| end | ||
|
|
||
| -- same as run.lang except it doesn't use the active doc's name | ||
| -- (thus doesn't require a docview to be open) | ||
| function run.build(build) | ||
| return function() | ||
| core.log "Running a build..." | ||
| local cmd = assert(config.run[build]) | ||
|
|
||
| os.execute(config.run_cmd:format(cmd)) | ||
| end | ||
| end | ||
|
|
||
| -- file extensions and functions | ||
| config.run_files = { | ||
| ["%.py$"] = run.lang "python", | ||
| ["%.pyw$"] = run.lang "python", | ||
| ["%.lua$"] = run.lang "lua", | ||
| ["%.c$"] = run.lang "c", | ||
| } | ||
|
|
||
| -- system commands for running files | ||
| -- the filename is already quoted | ||
| config.run = { | ||
| python = "python %s", | ||
| lua = "lua %s", | ||
| c = "gcc %s && " .. (PLATFORM == "Windows" and "a.exe" or "./a.out"), | ||
| } | ||
|
|
||
| -- for systems other than Windows | ||
| if PLATFORM == "Windows" then | ||
| config.run_cmd = "start cmd /c \"call %s & pause\"" | ||
| else | ||
| config.run_cmd = "xterm -hold -e \"%s\"" | ||
| end | ||
|
|
||
| local function compare_length(a, b) | ||
| return a.length > b.length | ||
| end | ||
|
|
||
| -- choose the proper function based on filename | ||
| function run.choose() | ||
| local doc = core.active_view.doc | ||
| local res = {} | ||
| for pattern, func in pairs(config.run_files) do | ||
| local s, e = common.match_pattern(doc.filename, pattern) | ||
| if s then | ||
| table.insert(res, { func=func, length=e-s }) | ||
| end | ||
| end | ||
| if #res == 0 then return false end | ||
| table.sort(res, compare_length) | ||
| return res[1].func | ||
| end | ||
|
|
||
| -- run the currently open doc | ||
| function run.run_doc() | ||
| local func = run.choose() | ||
| if not func then | ||
| core.error "No matching run configuration was found" | ||
| return | ||
| end | ||
| func() | ||
| end | ||
|
|
||
| command.add("core.docview", { | ||
| ["run:run-doc"] = run.run_doc, | ||
| }) | ||
|
|
||
| keymap.add { | ||
| ["f5"] = "run:run-doc", | ||
| } | ||
|
|
||
| return run | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.