├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── images ├── menu.gif ├── options.gif └── settings.gif ├── keymaps └── gcc-make-run.cson ├── lib ├── gcc-make-run-view.coffee └── gcc-make-run.coffee ├── menus └── gcc-make-run.cson ├── package.json └── styles └── gcc-make-run.less /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | npm-debug.log 3 | node_modules 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## 0.2.12 4 | * Fix not handling `TextBuffer.save()` becoming async in atom 1.19 correctly [[\#19](https://github.com/tomlau10/gcc-make-run/issues/19)@maxbrunsfeld] [[\#28](https://github.com/tomlau10/gcc-make-run/issues/28)@ziadxkabakibi] 5 | * Fix `setText() of undefined` in run option view [[\#27](https://github.com/tomlau10/gcc-make-run/issues/29)@kebien6020] 6 | 7 | ## 0.2.11 8 | * Fix `terminal start command` config `#{title}` causing config.cson error and changed to `$title` [[\#23](https://github.com/tomlau10/gcc-make-run/issues/23)@aquaraider11] 9 | * If encountered this issue already, needs manually delete the `terminal` key under `gcc-make-run` in `config.cson` (`File` > `Config...`) 10 | 11 | ## 0.2.10 12 | * Fix extra windows due to not handling deactivate correctly [[\#12](https://github.com/tomlau10/gcc-make-run/issues/12)@Dreded] 13 | * Fix cannot change focus in options view 14 | * Add `terminal start command` config for Linux platform [[\#22](https://github.com/tomlau10/gcc-make-run/pull/22)@aquaraider11] 15 | 16 | ## 0.2.9 17 | * Add `Press any key to continue` after running in MacOS platform [[\#9](https://github.com/tomlau10/gcc-make-run/pull/9)@crazymousethief] 18 | 19 | ## 0.2.8 20 | * Fix run options not working after previous update [[\#6](https://github.com/tomlau10/gcc-make-run/issues/6)@Weslysilva] 21 | 22 | ## 0.2.7 23 | * Add output extension setting [[\#5](https://github.com/tomlau10/gcc-make-run/issues/5)@adiultra] 24 | * Fix input cursor going to background when clicking the option view 25 | 26 | ## 0.2.6 27 | * Add `Press Enter to continue` after running in Linux platform [[\#3](https://github.com/tomlau10/gcc-make-run/issues/3)@nilosweden] 28 | 29 | ## 0.2.1 - 0.2.5 30 | * Fix images links in readme 31 | * Fix a rendering problem in readme 32 | * Fix detection for `C++14` grammar [[\#1](https://github.com/tomlau10/gcc-make-run/issues/1)@Adobe-Android] 33 | * Fix typo in readme 34 | 35 | ## 0.2.0 36 | * Improve option panel UI and CSS 37 | * Update readme and images 38 | * Fix wrong shortcut binding in Mac 39 | * Add a `debug` flag in config 40 | 41 | ## 0.1.1 42 | * Fix setting page not show up due to [*wrong use*](https://discuss.atom.io/t/configuration-vars-dont-show-up/14480) of `activationCommand` in `package.json` 43 | 44 | ## 0.1.0 - First Release 45 | * Add Compile-Run and Make-Run function **(remake of [kriscross07/gpp-compiler](https://atom.io/packages/gpp-compiler))** 46 | * Add Option Panel **(modified from [rgbkrk/script](https://atom.io/packages/script))** 47 | * Add config for compiler flags and run arguments 48 | * Add error checking when compiling non-saved files 49 | * Add notifications for the executed command and compiler output 50 | * Add support for Windows, Ubuntu and Mac 51 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Tom Lau 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GCC Make Run Package 2 | 3 | Compile-run C/C++ source code and execute Makefile in Atom. 4 | 5 | 6 | 7 | ## Preface 8 | 9 | I am a Windows user and just switched to Atom from Notepad++. Previously I wrote a script in NppExec to compile-run my C/C++ programs and execute Makefiles with customizable compile flags and run options. Atom has numerous community packages and I have tried some. They are really great in certain extent but still cannot fully satisfy my need. Therefore I decided to reference their packages and make my own. 10 | 11 | 12 | 13 | ## Features 14 | 15 | * Compile the current actively opened C/C++ file 16 | * Execute the current actively opened Makefile 17 | * Execute Makefile from Tree View 18 | * Customize compilers used 19 | * Customize compiler flags 20 | * Customize run options 21 | * Shortcut to compile-run [ default: `f6` ] 22 | * Shortcut to access run options panel [ default: `ctrl-f6`/`cmd-f6` ] 23 | 24 | 25 | 26 | ## Setup 27 | I have tested in the following three platforms: 28 | 29 | ### Windows 30 | For Windows users, I recommend installing the [**TDM-GCC**](http://tdm-gcc.tdragon.net/) (*which I am using*), then go to the setting page of this package and change the make utility to `mingw32-make`, after that everything should work. If you have installed other gcc-compilers, just make sure their command names are in you `PATH` environment variable 31 | 32 | ### Ubuntu 33 | For Ubuntu users, `gcc` and `make` should have already been installed, though you may need to install `g++` in addition. 34 | 35 | ### Mac 36 | For Mac users, Xcode is not a prerequisite but you need to at least install the **Xcode Command Line Tools**. [This](http://railsapps.github.io/xcode-command-line-tools.html) site has a more detailed walkthrough. 37 | 38 | 39 | 40 | ## Usage 41 | 42 | ### Settings Page 43 | ![Settings Page](https://raw.githubusercontent.com/tomlau10/gcc-make-run/master/images/settings.gif) 44 | * Edit compiler command name or path 45 | * Edit compiler flags and run arguments 46 | * Toggle unconditional build 47 | 48 | ### Run Options 49 | ![Run Options](https://raw.githubusercontent.com/tomlau10/gcc-make-run/master/images/options.gif) 50 | * Quick access to edit flags and arguments 51 | * Can use `[shift-]tab` to change input focus and `enter` to trigger the `run` button 52 | * Can trigger one-time unconditional build here 53 | 54 | ### Context Menu 55 | ![Context Menu](https://raw.githubusercontent.com/tomlau10/gcc-make-run/master/images/menu.gif) 56 | * Trigger Make-Run on Makefile from tree view 57 | * To execute a Makefile, a `run` target need to be specified, just as in the above `.gif` 58 | **Note**: Arguments in run options will be passed as environment variable `ARGS` to the Makefile, but compiler flags and link libraries will not. Below is an example `run` target: 59 | 60 | ```Makefile 61 | ... 62 | run: 63 | testing $(ARGS) 64 | ... 65 | ``` 66 | 67 | 68 | 69 | ## Code and Repo Reference 70 | I am new in CoffeeScript and know little about the Model-View-Controller design, thus my code may be messy. Below are the packages that I used and the repositories that I have referenced. They are great and you may want to try them out! 71 | * [kriscross07/atom-gpp-compiler](https://atom.io/packages/gpp-compiler) 72 | \+ A simple but useful package to compile-run C/C++ files 73 | \- Cannot customize run arguments 74 | \- On windows the cmd console just flash then close after the C/C++ program ends 75 | \! The closest that I want, thus mine is a **remake with enhancements** 76 | 77 | * [rgbkrk/atom-script](https://atom.io/packages/script) 78 | \+ Support many languages 79 | \+ Customizable compile and run flags 80 | \- Does not support C/C++ on Windows... 81 | \- Does not support interactive running 82 | \! The option view is **modified from this package** 83 | 84 | * [ksxatompackages/cmd-exec](https://atom.io/packages/command-executor) 85 | \+ Can register commands to do many things 86 | \- Troublesome to set up 87 | 88 | * [noseglid/atom-build](https://atom.io/packages/build) 89 | \+ Support automated build 90 | \- Need to specify an auto-build file 91 | -------------------------------------------------------------------------------- /images/menu.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomlau10/gcc-make-run/daab701fafa774e5a7df1082773f1176ba7ccc8a/images/menu.gif -------------------------------------------------------------------------------- /images/options.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomlau10/gcc-make-run/daab701fafa774e5a7df1082773f1176ba7ccc8a/images/options.gif -------------------------------------------------------------------------------- /images/settings.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tomlau10/gcc-make-run/daab701fafa774e5a7df1082773f1176ba7ccc8a/images/settings.gif -------------------------------------------------------------------------------- /keymaps/gcc-make-run.cson: -------------------------------------------------------------------------------- 1 | # For more detailed documentation see 2 | # https://atom.io/docs/latest/behind-atom-keymaps-in-depth 3 | 4 | # windows and linux 5 | '.platform-win32 atom-workspace, .platform-linux atom-workspace': 6 | 'f6': 'gcc-make-run:compile-run' 7 | 'ctrl-f6': 'gcc-make-run:run-options' 8 | 9 | # darwin 10 | '.platform-darwin atom-workspace': 11 | 'f6': 'gcc-make-run:compile-run' 12 | 'cmd-f6': 'gcc-make-run:run-options' 13 | -------------------------------------------------------------------------------- /lib/gcc-make-run-view.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # heavily modified from rgbkrk/atom-script - lib/script-options-view.coffee 3 | # https://github.com/rgbkrk/atom-script 4 | # https://atom.io/packages/script 5 | ### 6 | 7 | {CompositeDisposable} = require 'atom' 8 | {$, View} = require 'atom-space-pen-views' 9 | 10 | module.exports = 11 | class RunOptionsView extends View 12 | 13 | @content: -> 14 | @div class: 'run-options-view', => 15 | @div class: 'panel-heading', 'Configure Compile-Run Options' 16 | @div class: 'panel-body', => 17 | @table => 18 | @tr => 19 | @td => @label 'Compiler Flags:' 20 | @td => @tag 'atom-text-editor', class: 'editor mini', mini: '', keydown: 'traverseInputFocus', outlet: 'cflags' 21 | @tr => 22 | @td => @label 'Link Libraries:' 23 | @td => @tag 'atom-text-editor', class: 'editor mini', mini: '', keydown: 'traverseInputFocus', outlet: 'ldlibs' 24 | @tr => 25 | @td => @label 'Run Arguments:' 26 | @td => @tag 'atom-text-editor', class: 'editor mini', mini: '', keydown: 'traverseInputFocus', outlet: 'args' 27 | @div class: 'btn-group', => 28 | @button class: 'btn btn-primary', click: 'run', keydown: 'traverseButtonFocus', outlet: 'buttonRun', => 29 | @span class: 'icon icon-playback-play', 'Run' 30 | @button class: 'btn', click: 'rebuild', keydown: 'traverseButtonFocus', => 31 | @span class: 'icon icon-sync', 'Rebuild' 32 | @button class: 'btn', click: 'save', keydown: 'traverseButtonFocus', => 33 | @span class: 'icon icon-clippy', 'Save' 34 | @button class: 'btn', click: 'cancel', keydown: 'traverseButtonFocus', outlet: 'buttonCancel', => 35 | @span class: 'icon icon-x', 'Cancel' 36 | 37 | initialize: (@main) -> 38 | # observe shortcut 39 | @subscriptions = new CompositeDisposable 40 | @subscriptions.add atom.commands.add 'atom-workspace', 41 | 'core:cancel': => @hideRunOptions() 42 | 'core:close': => @hideRunOptions() 43 | 'gcc-make-run:compile-run': => @hideRunOptions(true) 44 | 'gcc-make-run:run-options': => @showRunOptions() 45 | 46 | # add modal panel 47 | @runOptionsPanel = atom.workspace.addModalPanel(item: @, visible: false) 48 | 49 | # hide panel when click outside 50 | $('atom-workspace').click => @hideRunOptions() 51 | @.mousedown (e) -> 52 | target = e.target 53 | while target != @ 54 | if target.classList.contains('editor') 55 | target.focus() 56 | break 57 | target = target.parentNode 58 | e.preventDefault() 59 | @.click (e) -> e.stopPropagation() 60 | 61 | destroy: -> 62 | @runOptionsPanel?.destroy() 63 | @subscriptions?.dispose() 64 | 65 | showRunOptions: -> 66 | return if @runOptionsPanel.isVisible() 67 | @restoreOptions() 68 | @runOptionsPanel.show() 69 | @cflags.focus() 70 | 71 | hideRunOptions: (shouldSave) -> 72 | return unless @runOptionsPanel.isVisible() 73 | @runOptionsPanel.hide() 74 | @saveOptions() if shouldSave 75 | 76 | restoreOptions: -> 77 | cfgs = ['cflags', 'ldlibs', 'args'] 78 | @[cfg].get(0).getModel().setText(atom.config.get("gcc-make-run.#{cfg}")) for cfg in cfgs 79 | 80 | saveOptions: -> 81 | cfgs = ['cflags', 'ldlibs', 'args'] 82 | atom.config.set("gcc-make-run.#{cfg}", @[cfg].get(0).getModel().getText()) for cfg in cfgs 83 | 84 | run: -> 85 | @hideRunOptions(true) 86 | atom.commands.dispatch @workspaceView(), 'gcc-make-run:compile-run' 87 | 88 | rebuild: -> 89 | @hideRunOptions(true) 90 | @main.oneTimeBuild = true 91 | atom.commands.dispatch @workspaceView(), 'gcc-make-run:compile-run' 92 | 93 | save: -> 94 | @hideRunOptions(true) 95 | atom.notifications.addSuccess('Run Options Saved') 96 | 97 | cancel: -> 98 | @hideRunOptions() 99 | 100 | traverseInputFocus: (e) -> 101 | switch e.keyCode 102 | # press tab key should change focus 103 | when 9 104 | # stop default propagation 105 | e.preventDefault() 106 | # find next/prev input box to focus 107 | row = @find(e.target).parents('tr:first')[if e.shiftKey then 'prevAll' else 'nextAll']('tr:first') 108 | if row.length 109 | row.find('atom-text-editor').focus() 110 | # focus run or close button if no input box can be found 111 | else 112 | if e.shiftKey then @buttonCancel.focus() else @buttonRun.focus() 113 | # enter key 114 | when 13 then @buttonRun.click() 115 | # otherwise ignore 116 | return true 117 | 118 | traverseButtonFocus: (e) -> 119 | switch e.keyCode 120 | when 9 121 | # press tab on close button should focus the first input box 122 | if !e.shiftKey && e.target == @buttonCancel.context 123 | @cflags.focus() 124 | return false 125 | # press shift tab on run button should focus the last input box 126 | else if e.shiftKey && e.target == @buttonRun.context 127 | @args.focus() 128 | return false 129 | # emulate button click when pressing enter key 130 | when 13 then e.target.click() 131 | # otherwise ignore 132 | return true 133 | 134 | workspaceView: -> 135 | atom.views.getView(atom.workspace) 136 | -------------------------------------------------------------------------------- /lib/gcc-make-run.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | # a remake of kriscross07/atom-gpp-compiler with extended features 3 | # https://github.com/kriscross07/atom-gpp-compiler 4 | # https://atom.io/packages/gpp-compiler 5 | ### 6 | 7 | GccMakeRunView = require './gcc-make-run-view' 8 | {CompositeDisposable} = require 'atom' 9 | {parse, join} = require 'path' 10 | {exec, execSync} = require 'child_process' 11 | {statSync} = require 'fs' 12 | {_extend} = require 'util' 13 | 14 | module.exports = GccMakeRun = 15 | config: 16 | 'C': 17 | title: 'gcc Compiler' 18 | type: 'string' 19 | default: 'gcc' 20 | order: 1 21 | description: 'Compiler for `C`, in full path or command name (make sure it is in your `$PATH`)' 22 | 'C++': 23 | title: 'g++ Compiler' 24 | type: 'string' 25 | default: 'g++' 26 | order: 2 27 | description: 'Compiler for `C++`, in full path or command name (make sure it is in your `$PATH`)' 28 | 'make': 29 | title: 'make Utility' 30 | type: 'string' 31 | default: 'make' 32 | order: 3 33 | description: 'The `make` utility used for compilation, in full path or command name (make sure it is in your `$PATH`)' 34 | 'uncondBuild': 35 | title: 'Unconditional Build' 36 | type: 'boolean' 37 | default: false 38 | order: 4 39 | description: 'Will not check if executable is up to date' 40 | 'cflags': 41 | title: 'Compiler Flags' 42 | type: 'string' 43 | default: '' 44 | order: 5 45 | description: 'Flags for compiler, eg: `-Wall`' 46 | 'ldlibs': 47 | title: 'Link Libraries' 48 | type: 'string' 49 | default: '' 50 | order: 6 51 | description: 'Libraries for linking, eg: `-lm`' 52 | 'args': 53 | title: 'Run Arguments' 54 | type: 'string' 55 | default: '' 56 | order: 7 57 | description: 'Arguments for executing, eg: `1 "2 3" "\\\"4 5 6\\\""`' 58 | 'ext': 59 | title: 'Output Extension' 60 | type: 'string' 61 | default: '' 62 | order: 8 63 | description: 'The output extension, eg: `out`, in Windows compilers will use `exe` by default' 64 | 'terminal': 65 | title: 'Terminal Start Command (only Linux platform)' 66 | type: 'string' 67 | default: 'xterm -T $title -e' 68 | order: 9 69 | description: 'Customize the terminal start command, eg: `gnome-terminal -t $title -x bash -c`' 70 | 'debug': 71 | title: 'Debug Mode' 72 | type: 'boolean' 73 | default: false 74 | order: 10 75 | description: 'Turn on this flag to log the executed command and output in console' 76 | 77 | gccMakeRunView: null 78 | oneTimeBuild: false 79 | 80 | ### 81 | # package setup 82 | ### 83 | activate: (state) -> 84 | @gccMakeRunView = new GccMakeRunView(@) 85 | @subscriptions = new CompositeDisposable() 86 | @subscriptions.add( 87 | atom.commands.add 'atom-workspace', 'gcc-make-run:compile-run': => @compile(), 88 | atom.commands.add '.tree-view .file > .name', 'gcc-make-run:make-run': (e) => @make(e.target.getAttribute('data-path')) 89 | ) 90 | 91 | deactivate: -> 92 | @subscriptions.dispose() 93 | @gccMakeRunView.cancel() 94 | 95 | serialize: -> 96 | gccMakeRunViewState: @gccMakeRunView.serialize() 97 | 98 | ### 99 | # compile and make run 100 | ### 101 | compile: () -> 102 | # get editor 103 | editor = atom.workspace.getActiveTextEditor() 104 | return unless editor? 105 | 106 | # save file 107 | srcPath = editor.getPath() 108 | if !srcPath 109 | atom.notifications.addError('gcc-make-run: File Not Saved', { detail: 'Temporary files must be saved first' }) 110 | return 111 | Promise.resolve(editor.save() if editor.isModified()).then => 112 | 113 | # get grammar 114 | grammar = editor.getGrammar().name 115 | switch grammar 116 | when 'C', 'C++', 'C++14' then grammar = 'C++' if grammar == 'C++14' 117 | when 'Makefile' 118 | @make(srcPath) 119 | return 120 | else 121 | atom.notifications.addError('gcc-make-run: Grammar Not Supported', { detail: 'Only C, C++ and Makefile are supported' }) 122 | return 123 | 124 | # get config 125 | info = parse(editor.getPath()) 126 | info.useMake = false 127 | info.exe = info.name 128 | ext = atom.config.get('gcc-make-run.ext') 129 | if ext then info.exe += ".#{ext}" else if process.platform == 'win32' then info.exe += '.exe' 130 | compiler = atom.config.get("gcc-make-run.#{grammar}") 131 | cflags = atom.config.get('gcc-make-run.cflags') 132 | ldlibs = atom.config.get('gcc-make-run.ldlibs') 133 | 134 | # check if update needed before compile 135 | if !@shouldUncondBuild() && @isExeUpToDate(info) 136 | @run(info) 137 | else 138 | cmd = "\"#{compiler}\" #{cflags} \"#{info.base}\" -o \"#{info.exe}\" #{ldlibs}" 139 | atom.notifications.addInfo('gcc-make-run: Running Command...', { detail: cmd }) 140 | exec(cmd , { cwd: info.dir }, @onBuildFinished.bind(@, info)) 141 | 142 | make: (srcPath) -> 143 | # get config 144 | info = parse(srcPath) 145 | info.useMake = true 146 | mk = atom.config.get('gcc-make-run.make') 147 | mkFlags = if @shouldUncondBuild() then '-B' else '' 148 | 149 | # make 150 | cmd = "\"#{mk}\" #{mkFlags} -f \"#{info.base}\"" 151 | atom.notifications.addInfo('gcc-make-run: Running Command...', { detail: cmd }) 152 | exec(cmd, { cwd: info.dir }, @onBuildFinished.bind(@, info)) 153 | 154 | onBuildFinished: (info, error, stdout, stderr) -> 155 | # notifications about compilation status 156 | hasCompiled = (stdout?.indexOf('up to date') < 0 && stdout?.indexOf('to be done') < 0) || !stdout? 157 | atom.notifications[if error then 'addError' else 'addWarning']("gcc-make-run: Compile #{if error then 'Error' else 'Warning'}", { detail: stderr, dismissable: true }) if stderr 158 | atom.notifications[if hasCompiled then 'addInfo' else 'addSuccess']('gcc-make-run: Compiler Output', { detail: stdout }) if stdout 159 | 160 | # continue only if no error 161 | return if error 162 | atom.notifications.addSuccess('gcc-make-run: Build Success') if hasCompiled 163 | @run(info) 164 | 165 | run: (info) -> 166 | # build the run cmd 167 | return unless @checkMakeRunTarget(info) 168 | return unless @buildRunCmd(info) 169 | 170 | # run the cmd 171 | console.log info.cmd if atom.config.get('gcc-make-run.debug') 172 | exec(info.cmd, { cwd: info.dir, env: info.env }, @onRunFinished.bind(@)) 173 | 174 | onRunFinished: (error, stdout, stderr) -> 175 | # command error 176 | atom.notifications.addError('gcc-make-run: Run Command Failed', { detail: stderr, dismissable: true }) if error 177 | console.log stdout if stdout && atom.config.get('gcc-make-run.debug') 178 | 179 | ### 180 | # helper functions 181 | ### 182 | isExeUpToDate: (info) -> 183 | # check src and exe modified time 184 | srcTime = statSync(join(info.dir, info.base)).mtime.getTime() 185 | try 186 | exeTime = statSync(join(info.dir, info.exe)).mtime.getTime() 187 | catch error 188 | exeTime = 0 189 | 190 | if srcTime < exeTime 191 | atom.notifications.addSuccess("gcc-make-run: Output Up To Date", { detail: "'#{info.exe}' is up to date" }) 192 | return true 193 | return false 194 | 195 | checkMakeRunTarget: (info) -> 196 | # return if not using Makefile 197 | return true if !info.useMake 198 | 199 | mk = atom.config.get("gcc-make-run.make") 200 | info.exe = undefined 201 | 202 | # try make run to get the target 203 | try 204 | info.exe = execSync("\"#{mk}\" -nf \"#{info.base}\" run", { cwd: info.dir, stdio: [], encoding: 'utf8' }).split('#')[0].match(/[^\r\n]+/g)[0] 205 | if !info.exe || info.exe.indexOf('to be done') >= 0 then throw Error() 206 | if process.platform == 'win32' && info.exe.indexOf('.exe') != -1 then info.exe += '.exe' 207 | return true 208 | catch error 209 | # cannot get run target 210 | atom.notifications.addError( 211 | "gcc-make-run: Cannot find 'run' target", 212 | { 213 | detail: """ 214 | Target 'run' is not specified in #{info.base} 215 | Example 'run' target: 216 | run: 217 | excutable $(ARGS) 218 | """, 219 | dismissable: true 220 | } 221 | ) 222 | return false 223 | 224 | shouldUncondBuild: -> 225 | ret = @oneTimeBuild || atom.config.get('gcc-make-run.uncondBuild') 226 | @oneTimeBuild = false 227 | return ret 228 | 229 | buildRunCmd: (info) -> 230 | # get config 231 | mk = atom.config.get('gcc-make-run.make') 232 | info.env = _extend({ ARGS: atom.config.get('gcc-make-run.args') }, process.env) 233 | 234 | # for linux platform, get terminal and replace the title 235 | terminal = atom.config.get('gcc-make-run.terminal').replace('$title', "\"#{info.exe}\"") if process.platform == 'linux' 236 | 237 | if info.useMake 238 | switch process.platform 239 | when 'win32' then info.cmd = "start \"#{info.exe}\" cmd /c \"\"#{mk}\" -sf \"#{info.base}\" run & pause\"" 240 | when 'linux' then info.cmd = "#{terminal} \"" + @escdq("\"#{mk}\" -sf \"#{info.base}\" run") + "; read -n 1 -p 'Press any key to continue...'\"" 241 | when 'darwin' then info.cmd = 'osascript -e \'tell application "Terminal" to activate do script "' + @escdq("clear && cd \"#{info.dir}\"; \"#{mk}\" ARGS=\"#{@escdq(info.env.ARGS)}\" -sf \"#{info.base}\" run; " + 'read -n 1 -p "Press any key to continue..." && osascript -e "tell application \\"Atom\\" to activate" && osascript -e "do shell script ' + @escdq("\"osascript -e #{@escdq('"tell application \\"Terminal\\" to close windows 0"')} + &> /dev/null &\"") + '"; exit') + '"\'' 242 | else 243 | # normal run 244 | switch process.platform 245 | when 'win32' then info.cmd = "start \"#{info.exe}\" cmd /c \"\"#{info.exe}\" #{info.env.ARGS} & pause\"" 246 | when 'linux' then info.cmd = "#{terminal} \"" + @escdq("\"./#{info.exe}\" #{info.env.ARGS}") + "; read -n 1 -p 'Press any key to continue...'\"" 247 | when 'darwin' then info.cmd = 'osascript -e \'tell application "Terminal" to activate do script "' + @escdq("clear && cd \"#{info.dir}\"; \"./#{info.exe}\" #{info.env.ARGS}; " + 'read -n 1 -p "Press any key to continue..." && osascript -e "tell application \\"Atom\\" to activate" && osascript -e "do shell script ' + @escdq("\"osascript -e #{@escdq('"tell application \\"Terminal\\" to close windows 0"')} + &> /dev/null &\"") + '"; exit') + '"\'' 248 | 249 | # check if cmd is built 250 | return true if info.cmd? 251 | atom.notifications.addError('gcc-make-run: Cannot Execute Output', { detail: 'Execution after compiling is not supported on your OS' }) 252 | return false 253 | 254 | escdq: (s) -> 255 | # escape double quote 256 | s.replace(/\\/g, '\\\\').replace(/"/g, '\\"') 257 | -------------------------------------------------------------------------------- /menus/gcc-make-run.cson: -------------------------------------------------------------------------------- 1 | # See https://atom.io/docs/latest/hacking-atom-package-word-count#menus for more details 2 | 'context-menu': 3 | 'atom-text-editor': [ 4 | { 5 | 'label': 'Compile Run' 6 | 'command': 'gcc-make-run:compile-run' 7 | }, 8 | { 9 | 'label': 'Toggle Run Options' 10 | 'command': 'gcc-make-run:run-options' 11 | } 12 | ], 13 | '.tree-view .file > .name': [ 14 | { 15 | 'label': 'Make Run', 16 | 'command': 'gcc-make-run:make-run' 17 | } 18 | ] 19 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "gcc-make-run", 3 | "main": "./lib/gcc-make-run", 4 | "version": "0.2.12", 5 | "description": "Compile-run C/C++ source code and execute Makefile in Atom.", 6 | "keywords": [ 7 | "gcc", 8 | "g++", 9 | "c++", 10 | "compile", 11 | "make", 12 | "run" 13 | ], 14 | "repository": "https://github.com/tomlau10/gcc-make-run", 15 | "license": "MIT", 16 | "engines": { 17 | "atom": ">=1.0.0" 18 | }, 19 | "dependencies": { 20 | "atom-space-pen-views": "^2.0.3" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /styles/gcc-make-run.less: -------------------------------------------------------------------------------- 1 | /* 2 | * modified from rgbkrk/atom-script - styles/script.less 3 | * https://github.com/rgbkrk/atom-script 4 | * https://atom.io/packages/script 5 | */ 6 | 7 | // The ui-variables file is provided by base themes provided by Atom. 8 | // 9 | // See https://github.com/atom/atom-dark-ui/blob/master/styles/ui-variables.less 10 | // for a full listing of what's available. 11 | @import "ui-variables"; 12 | 13 | .run-options-view { 14 | .panel-heading { 15 | text-align: center; 16 | font-size: 1.25rem; 17 | } 18 | 19 | table { 20 | width: 100%; 21 | margin-top: 5px; 22 | 23 | td { 24 | padding: 5px; 25 | vertical-align: middle; 26 | 27 | atom-text-editor { 28 | width: 99%; 29 | } 30 | } 31 | 32 | td:first-child { 33 | width: 25%; 34 | text-align: right; 35 | } 36 | } 37 | 38 | .btn-group { 39 | padding: 0.5rem; 40 | display: flex; 41 | 42 | * { 43 | flex: 1; 44 | padding: 0.2rem; 45 | } 46 | } 47 | } 48 | --------------------------------------------------------------------------------