├── .gitignore
├── Default.sublime-commands
├── LICENSE.md
├── Main.sublime-menu
├── README.md
├── Tab Context.sublime-menu
├── diff_tabs.py
├── diff_tabs.sublime-settings
├── diff_tabs_edit_settings.py
├── diff_tabs_open_default_settings.py
└── diff_tabs_open_user_settings.py
/.gitignore:
--------------------------------------------------------------------------------
1 | *.pyc
2 |
--------------------------------------------------------------------------------
/Default.sublime-commands:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "caption": "DiffTabs: Diff With Current Tab…",
4 | "command": "diff_tabs_palette"
5 | },
6 | {
7 | "caption": "Preferences: DiffTabs Settings – Default",
8 | "command": "diff_tabs_open_default_settings"
9 | },
10 | {
11 | "caption": "Preferences: DiffTabs Settings – User",
12 | "command": "diff_tabs_open_user_settings"
13 | },
14 | {
15 | "caption": "Preferences: DiffTabs Settings",
16 | "command": "diff_tabs_edit_settings"
17 | }
18 | ]
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 |
3 | **Copyright (c) 2016 Andrew So**
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6 |
7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8 |
9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
--------------------------------------------------------------------------------
/Main.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | {
3 | "id": "preferences",
4 | "children": [
5 | {
6 | "caption": "Package Settings",
7 | "mnemonic": "P",
8 | "id": "package-settings",
9 | "children": [
10 | {
11 | "caption": "DiffTabs",
12 | "children": [
13 | {
14 | "command": "diff_tabs_open_default_settings",
15 | "caption": "Settings – Default"
16 | },
17 | {
18 | "command": "diff_tabs_open_user_settings",
19 | "caption": "Settings – User"
20 | },
21 | {
22 | "command": "diff_tabs_edit_settings",
23 | "caption": "Settings"
24 | },
25 | { "caption": "-" }
26 | ]
27 | }
28 | ]
29 | }
30 | ]
31 | }
32 | ]
33 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DiffTabs
2 |
3 | Sublime Text 4/3/2 plugin that adds the option to diff the current tab with another open tab.
4 |
5 | ## Usage
6 |
7 | 
8 |
9 | Right click another tab along the tab bar and select "DiffTabs: Diff With Current Tab…" (The tab you right click will be the from-file and the current tab will be the to-file).
10 | Your diff results will appear in a new tab.
11 |
12 | ### Keyboard Support
13 |
14 | 
15 |
16 | Open the Command Palette by pressing ⌘+Shift+P on Mac or Ctrl+Shift+P on Linux/Windows.
17 | Type in `DiffTabs: Diff With Current Tab…` and press Enter.
18 | In the dropdown select another tab (The tab you select will be the from-file and the current tab will be the to-file).
19 |
20 | ## Configuration
21 |
22 | - ST2:
23 | - Preferences > Package Settings > DiffTabs > Settings - User
24 | - ST3/ST4:
25 | - Preferences > Package Settings > DiffTabs > Settings
26 |
27 | | Key | Possible values | Default value | Description |
28 | |---------------|-------------------------|---------------|---------------------------------------------------------------------------------------------------------------------------------------|
29 | | `"output_to"` | `"buffer"` \| `"panel"` | `"buffer"` | Where to display diff output to
buffer: diff results will display in a new tab
panel: diff results will display in bottom panel |
30 |
31 | ## Installation
32 |
33 | **Package Control:**
34 |
35 | 1. Install [Package Control](https://packagecontrol.io/installation) if necessary.
36 | 2. Open the Command Palette by pressing ⌘+Shift+P on Mac or Ctrl+Shift+P on Linux/Windows.
37 | 3. Type in `Package Control: Install Package` and press Enter
38 | 4. Type `DiffTabs` and hit Enter
39 |
40 | **Without Git:** Download the latest source from [GitHub](https://github.com/soandrew/DiffTabs) and extract archive to your Sublime Text "Packages" directory.
41 |
42 | **With Git:** Clone the repository to your Sublime Text "Packages" directory:
43 |
44 | - `git clone https://github.com/soandrew/DiffTabs.git`
45 |
46 | The "Packages" directory is located at:
47 |
48 | - ST2:
49 | - OS X: `~/Library/Application Support/Sublime Text 2/Packages`
50 | - Linux: `~/.config/sublime-text-2/Packages`
51 | - Windows: `%APPDATA%\Sublime Text 2\Packages`
52 | - ST3/ST4:
53 | - OS X: `~/Library/Application Support/Sublime Text 3/Packages`
54 | - Linux: `~/.config/sublime-text-3/Packages`
55 | - Windows: `%APPDATA%\Sublime Text 3\Packages`
56 |
--------------------------------------------------------------------------------
/Tab Context.sublime-menu:
--------------------------------------------------------------------------------
1 | [
2 | { "caption": "-" },
3 | { "caption": "DiffTabs: Diff With Current Tab…", "command": "diff_tabs", "args": { "group": -1, "index": -1 } }
4 | ]
5 |
--------------------------------------------------------------------------------
/diff_tabs.py:
--------------------------------------------------------------------------------
1 | # coding: utf-8
2 | import sublime
3 | import sublime_plugin
4 | import difflib
5 | import time
6 | import os.path
7 |
8 | def is_st2():
9 | return sublime.version()[0] == '2'
10 |
11 | def load_settings():
12 | return sublime.load_settings("diff_tabs.sublime-settings")
13 |
14 | def populate_view(view, txt):
15 | if is_st2():
16 | view.set_syntax_file('Packages/Diff/Diff.tmLanguage')
17 | edit = view.begin_edit()
18 | view.insert(edit, 0, txt)
19 | view.end_edit(edit)
20 | else:
21 | view.assign_syntax('Packages/Diff/Diff.sublime-syntax')
22 | view.run_command('append', {'characters': txt})
23 |
24 | def generate_diff_view(window, aview, bview):
25 | aname = aview.file_name() if aview.file_name() else aview.name()
26 | bname = bview.file_name() if bview.file_name() else bview.name()
27 |
28 | a = aview.substr(sublime.Region(0, aview.size())).splitlines()
29 | b = bview.substr(sublime.Region(0, bview.size())).splitlines()
30 |
31 | adate = time.ctime() if aview.is_dirty() or aview.is_scratch() else time.ctime(os.stat(aname).st_mtime)
32 | bdate = time.ctime() if bview.is_dirty() or bview.is_scratch() else time.ctime(os.stat(bname).st_mtime)
33 |
34 | diff = difflib.unified_diff(b, a, bname, aname, bdate, adate, lineterm='')
35 | difftxt = u"\n".join(line for line in diff)
36 |
37 | if difftxt == "":
38 | sublime.status_message("Files are identical")
39 | else:
40 | output_to = load_settings().get('output_to', "buffer")
41 | if output_to == "panel":
42 | v = window.get_output_panel('diff_tabs') if is_st2() else window.create_output_panel('diff_tabs')
43 | populate_view(v, difftxt)
44 | window.run_command('show_panel', {'panel': 'output.diff_tabs'})
45 | else:
46 | v = window.new_file()
47 | v.set_name(os.path.basename(bname) + " -> " + os.path.basename(aname))
48 | v.set_scratch(True)
49 | populate_view(v, difftxt)
50 |
51 | class DiffTabsCommand(sublime_plugin.WindowCommand):
52 | def run(self, group, index):
53 | window = self.window
54 |
55 | aview = window.active_view()
56 | if window.get_view_index(aview) == (group, index):
57 | return
58 | bview = window.views_in_group(group)[index]
59 |
60 | generate_diff_view(window, aview, bview)
61 |
62 | def is_visible(self, group, index):
63 | window = self.window
64 | view = window.active_view()
65 | return window.get_view_index(view) != (group, index)
66 |
67 | class DiffTabsPaletteCommand(sublime_plugin.TextCommand):
68 | def run(self, edit):
69 | window = sublime.active_window()
70 | aview = self.view
71 | other_views = [v for v in window.views() if v.id() != aview.id()]
72 |
73 | def on_select(selected_idx):
74 | if selected_idx == -1:
75 | return
76 | generate_diff_view(window, aview, other_views[selected_idx])
77 |
78 | window.show_quick_panel(
79 | [os.path.basename(v.file_name()) if v.file_name() else v.name() for v in other_views],
80 | on_select
81 | )
82 |
--------------------------------------------------------------------------------
/diff_tabs.sublime-settings:
--------------------------------------------------------------------------------
1 | {
2 | // Where to display diff output to (buffer|panel)
3 | "output_to": "buffer"
4 | }
5 |
--------------------------------------------------------------------------------
/diff_tabs_edit_settings.py:
--------------------------------------------------------------------------------
1 | import sublime
2 | import sublime_plugin
3 |
4 | class DiffTabsEditSettingsCommand(sublime_plugin.WindowCommand):
5 | def run(self):
6 | self.window.run_command(
7 | 'edit_settings',
8 | {
9 | "base_file": "${packages}/DiffTabs/diff_tabs.sublime-settings",
10 | "default": (
11 | "// See the left pane for the list of settings and valid values\n"
12 | + "{\n"
13 | + "\t$0\n"
14 | + "}\n"
15 | )
16 | }
17 | )
18 |
19 | def is_visible(self):
20 | return int(sublime.version()) >= 3116
21 |
22 | def is_enabled(self):
23 | return self.is_visible()
24 |
--------------------------------------------------------------------------------
/diff_tabs_open_default_settings.py:
--------------------------------------------------------------------------------
1 | import sublime
2 | import sublime_plugin
3 |
4 | class DiffTabsOpenDefaultSettingsCommand(sublime_plugin.WindowCommand):
5 | def run(self):
6 | self.window.run_command(
7 | 'open_file',
8 | {
9 | "file": "${packages}/DiffTabs/diff_tabs.sublime-settings"
10 | }
11 | )
12 |
13 | def is_visible(self):
14 | return int(sublime.version()) < 3116
15 |
16 | def is_enabled(self):
17 | return self.is_visible()
18 |
--------------------------------------------------------------------------------
/diff_tabs_open_user_settings.py:
--------------------------------------------------------------------------------
1 | import sublime
2 | import sublime_plugin
3 |
4 | class DiffTabsOpenUserSettingsCommand(sublime_plugin.WindowCommand):
5 | def run(self):
6 | self.window.run_command(
7 | 'open_file',
8 | {
9 | "file": "${packages}/User/diff_tabs.sublime-settings",
10 | "contents": (
11 | "// See Preferences > Package Settings > DiffTabs > Settings - Default\n"
12 | + "// for the list of settings and valid values\n"
13 | + "{\n"
14 | + "\t$0\n"
15 | + "}\n"
16 | )
17 | }
18 | )
19 |
20 | def is_visible(self):
21 | return int(sublime.version()) < 3116
22 |
23 | def is_enabled(self):
24 | return self.is_visible()
25 |
--------------------------------------------------------------------------------