aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/.view.luadoc8
-rw-r--r--doc/manual.md2
-rw-r--r--init.lua67
-rw-r--r--src/Makefile2
-rw-r--r--test/test.lua29
5 files changed, 72 insertions, 36 deletions
diff --git a/core/.view.luadoc b/core/.view.luadoc
index f50ca046..ed3b3b81 100644
--- a/core/.view.luadoc
+++ b/core/.view.luadoc
@@ -1449,16 +1449,16 @@ function goto_buffer(view, buffer) end
---
-- Sets the view's color theme to be string *name*, with the contents of table
--- *options* available as global variables.
+-- *env* available as global variables.
-- User themes override Textadept's default themes when they have the same name.
-- If *name* contains slashes, it is assumed to be an absolute path to a theme
-- instead of a theme name.
-- @param view A view.
-- @param name The name or absolute path of a theme to set.
--- @param options Optional table of global variables themes can utilize to
--- override default settings such as font and size.
+-- @param env Optional table of global variables themes can utilize to override
+-- default settings such as font and size.
-- @usage view:set_theme('light', {font = 'Monospace', size = 12})
-- @name set_theme
-- @see _G.lexer.colors
-- @see _G.lexer.styles
-function set_theme(view, name, options) end
+function set_theme(view, name, env) end
diff --git a/doc/manual.md b/doc/manual.md
index a2c9f209..ea324d4a 100644
--- a/doc/manual.md
+++ b/doc/manual.md
@@ -2036,6 +2036,7 @@ nested\_pair() |Replaced|[range()][]
N/A |Added |[number][]
N/A |Added |[colors][]
N/A |Added |[styles][]
+N/A |Added |[folding][] and other fold\* properties
**lfs** | |
dir\_foreach() |Replaced|for filename in [lfs.walk()][] do ... end
**textadept.bookmarks** | |
@@ -2077,6 +2078,7 @@ section below.
[number]: api.html#lexer.number
[colors]: api.html#lexer.colors
[styles]: api.html#lexer.styles
+[folding]: api.html#lexer.folding
[lfs.walk()]: api.html#lfs.walk
[toggle()]: api.html#textadept.bookmarks.toggle
[toggle_comment()]: api.html#textadept.editing.toggle_comment
diff --git a/init.lua b/init.lua
index 3ac325bf..4b8587ad 100644
--- a/init.lua
+++ b/init.lua
@@ -21,38 +21,15 @@ textadept = require('textadept')
local SETLEXERLANGUAGE = _SCINTILLA.properties.lexer_language[2]
-- Documentation is in core/.view.luadoc.
-local function set_theme(view, name, options)
+local function set_theme(view, name, env)
if not assert_type(name, 'string', 2):find('[/\\]') then
name = package.searchpath(name, string.format(
'%s/themes/?.lua;%s/themes/?.lua', _USERHOME, _HOME))
end
if not name or not lfs.attributes(name) then return end
- if not assert_type(options, 'table/nil', 3) then options = {} end
+ if not assert_type(env, 'table/nil', 3) then env = {} end
local orig_view = _G.view
if view ~= orig_view then ui.goto_view(view) end
- -- Mimic `lexer.colors` and `lexer.styles` because (1) the lexer module is not
- -- yet available and (2) even if it was, color and style settings would not
- -- be captured later during init.
- local property = view.property
- local colors = setmetatable({}, {__newindex = function(t, name, color)
- if type(color) == 'string' then
- local r, g, b = color:match('^#(%x%x)(%x%x)(%x%x)$')
- color = tonumber(string.format('%s%s%s', b, g, r), 16) or 0
- end
- property['color.' .. name] = color
- rawset(t, name, color) -- cache instead of __index for property[...]
- end})
- local styles = setmetatable({}, {__newindex = function(_, name, props)
- local settings = {}
- for k, v in pairs(props) do
- settings[#settings + 1] = type(v) ~= 'boolean' and
- string.format('%s:%s', k, v) or
- string.format('%s%s', v and '' or 'not', k)
- end
- property['style.' .. name] = table.concat(settings, ',')
- end})
- local env = {lexer = {colors = colors, styles = styles}}
- for k, v in pairs(options) do env[k] = v end
loadfile(name, 't', setmetatable(env, {__index = _G}))()
-- Force reload of all styles since the current lexer may have defined its own
-- styles. (The LPeg lexer has only refreshed default lexer styles.)
@@ -118,6 +95,34 @@ for _, mt in ipairs{buffer_mt, view_mt} do
end
end
+-- Mimic the `lexer` module because (1) it is not yet available and (2) even if
+-- it was, color, style, and property settings would not be captured during
+-- init.
+local property = view.property
+local colors = setmetatable({}, {__newindex = function(t, name, color)
+ if type(color) == 'string' then
+ local r, g, b = color:match('^#(%x%x)(%x%x)(%x%x)$')
+ color = tonumber(string.format('%s%s%s', b, g, r), 16) or 0
+ end
+ property['color.' .. name] = color
+ rawset(t, name, color) -- cache instead of __index for property[...]
+end})
+local styles = setmetatable({}, {__newindex = function(_, name, props)
+ local settings = {}
+ for k, v in pairs(props) do
+ settings[#settings + 1] = type(v) ~= 'boolean' and
+ string.format('%s:%s', k, v) or
+ string.format('%s%s', v and '' or 'not', k)
+ end
+ property['style.' .. name] = table.concat(settings, ',')
+end})
+lexer = setmetatable({colors = colors, styles = styles}, {
+ __newindex = function(_, k, v)
+ if k == 'folding' then k = 'fold' end
+ property[k:gsub('_', '.')] = v and '1' or '0'
+ end
+})
+
-- Default buffer and view settings.
local buffer, view = buffer, view
@@ -287,11 +292,11 @@ view.call_tip_use_style = buffer.tab_width *
--view.call_tip_position = true
-- Folding.
-view.property['fold'] = '1'
---view.property['fold.by.indentation'] = '1'
---view.property['fold.line.comments'] = '1'
---view.property['fold.on.zero.sum.lines'] = '1'
---view.property['fold.compact'] = '1'
+lexer.folding = true
+--lexer.fold_by_indentation = true
+--lexer.fold_line_comments = true
+--lexer.fold_on_zero_sum_lines = true
+--lexer.fold_compact = true
view.automatic_fold = view.AUTOMATICFOLD_SHOW | view.AUTOMATICFOLD_CLICK |
view.AUTOMATICFOLD_CHANGE
view.fold_flags = not CURSES and view.FOLDFLAG_LINEAFTER_CONTRACTED or 0
@@ -337,7 +342,7 @@ events.connect(events.BUFFER_NEW, function()
buffer:private_lexer_call(LOADLEXERLIBRARY, _HOME .. '/lexers')
load_settings()
buffer:private_lexer_call(SETLEXERLANGUAGE, 'text')
- if not _G.lexer then _G.lexer = require('lexer') end
+ _G.lexer = require('lexer') -- replace mimic
if buffer == ui.command_entry then
ui.command_entry.caret_line_visible = false
end
diff --git a/src/Makefile b/src/Makefile
index db7addd3..7934fa13 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -376,7 +376,7 @@ else
gtdialog_url = http://foicica.com/hg/gtdialog/archive/tip.zip
endif
-scintilla_zip = 4e081ee8d750.zip
+scintilla_zip = 83eb3011555e.zip
lua_tgz = lua-5.3.5.tar.gz
lpeg_tgz = lpeg-1.0.2.tar.gz
lfs_zip = v1_7_0_2.zip
diff --git a/test/test.lua b/test/test.lua
index 5cf884cb..c3c58f92 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -3170,6 +3170,35 @@ function test_set_lexer_style()
view.property['style.library'] = view.property['style.library']
end
+function test_lexer_fold_properties()
+ lexer.property['fold.compact'] = '0'
+ assert(not lexer.fold_compact, 'lexer.fold_compact not updated')
+ lexer.fold_compact = true
+ assert(lexer.fold_compact, 'lexer.fold_compact not updated')
+ assert_equal(lexer.property['fold.compact'], '1')
+ lexer.fold_compact = nil
+ assert(not lexer.fold_compact)
+ assert_equal(lexer.property['fold.compact'], '0')
+ local truthy, falsy = {true, '1', 1}, {false, '0', 0}
+ for i = 1, #truthy do
+ lexer.fold_compact = truthy[i]
+ assert(lexer.fold_compact, 'lexer.fold_compact not updated for "%s"', tostring(truthy[i]))
+ lexer.fold_compact = falsy[i]
+ assert(not lexer.fold_compact, 'lexer.fold_compact not updated for "%s"', tostring(falsy[i]))
+ end
+ -- Verify fold and folding properties are synchronized.
+ lexer.property['fold'] = '0'
+ assert(not lexer.folding)
+ lexer.folding = true
+ assert(lexer.property['fold'] == '1')
+ -- Lexer fold properties and view fold properties do not mirror because
+ -- Scintilla forwards view property settings to lexers, not vice-versa.
+ view.property['fold'] = '0'
+ assert(not lexer.folding)
+ lexer.folding = true
+ assert_equal(view.property['fold'], '0')
+end
+
-- TODO: test init.lua's buffer settings
function test_ctags()