aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrancesco <francesco.bbt@gmail.com>2021-06-15 23:18:20 +0200
committerGitHub <noreply@github.com>2021-06-15 23:18:20 +0200
commit081665d20f2ad1a9b8b516f24438fd73cd6324f3 (patch)
tree7ea2154be64d9d578e8a1e903e207df6ce30127a
parentdc4448f9e3ca44ed175d0dabbc20486c9b7d92a8 (diff)
parentdef5ced2aecdba4239f56f1f512127484dec260a (diff)
downloadlite-xl-plugins-081665d20f2ad1a9b8b516f24438fd73cd6324f3.tar.gz
lite-xl-plugins-081665d20f2ad1a9b8b516f24438fd73cd6324f3.zip
Merge pull request #32 from adamharrison/EphemeralTabs
Added in the ability to have ephemeral tabs.
-rw-r--r--README.md1
-rw-r--r--plugins/ephemeraldocviews.lua45
2 files changed, 46 insertions, 0 deletions
diff --git a/README.md b/README.md
index 114f114..c12aecf 100644
--- a/README.md
+++ b/README.md
@@ -33,6 +33,7 @@ Plugin | Description
[`eofnewline`](https://github.com/bokunodev/lite_modules/blob/master/plugins/eofnewline-xl.lua?raw=1) | Make sure the file ends with one blank line.
[`eval`](plugins/eval.lua?raw=1) | Replaces selected Lua code with its evaluated result
[`exec`](plugins/exec.lua?raw=1) | Runs selected text through shell command and replaces with result
+[`ephemeraldocviews`](plugins/ephemeraldocviews.lua?raw=1) | Preview tabs. Opening a doc will replace the contents of the preview tab. Marks tabs as non-preview on any change.
[`fallbackfonts`](https://github.com/takase1121/lite-fallback-fonts)* | Adds support for fallback fonts *([gif](https://raw.githubusercontent.com/takase1121/lite-fallback-fonts/master/assets/Iw18fI57J0.gif))*
[`formatter`](https://github.com/vincens2005/lite-formatters)* | formatters for various languages
[`ghmarkdown`](plugins/ghmarkdown.lua?raw=1) | Opens a preview of the current markdown file in a browser window *([screenshot](https://user-images.githubusercontent.com/3920290/82754898-f7394600-9dc7-11ea-8278-2305363ed372.png))*
diff --git a/plugins/ephemeraldocviews.lua b/plugins/ephemeraldocviews.lua
new file mode 100644
index 0000000..37b3a3b
--- /dev/null
+++ b/plugins/ephemeraldocviews.lua
@@ -0,0 +1,45 @@
+-- mod-version:1 -- lite-xl 1.16
+local core = require "core"
+local command = require "core.command"
+local RootView = require "core.rootview"
+local DocView = require "core.docview"
+local Doc = require "core.doc"
+
+local open_doc = RootView.open_doc
+function RootView:open_doc(doc)
+ local node = self:get_active_node_default()
+ local ephemeral, existing_ephemeral = node.views, nil
+ for i, view in ipairs(node.views) do
+ if view.doc == doc then
+ ephemeral = false
+ end
+ if view.doc and view.doc.ephemeral then
+ existing_ephemeral = view
+ end
+ end
+ if ephemeral and existing_ephemeral then
+ node:close_view(self.root_node, existing_ephemeral)
+ end
+ local view = open_doc(self, doc)
+ if ephemeral then
+ view.doc.ephemeral = #node.views > 1
+ end
+ return view
+end
+
+local get_name = DocView.get_name
+function DocView:get_name()
+ return self.doc and self.doc.ephemeral and ("-- " .. get_name(self) .. " --") or get_name(self)
+end
+
+local doc_insert = Doc.insert
+function Doc:insert(...)
+ doc_insert(self, ...)
+ self.ephemeral = false
+end
+
+local doc_remove = Doc.remove
+function Doc:remove(...)
+ doc_remove(self, ...)
+ self.ephemeral = false
+end