aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormitchell <70453897+667e-11@users.noreply.github.com>2020-03-11 22:50:30 -0400
committermitchell <70453897+667e-11@users.noreply.github.com>2020-03-11 22:50:30 -0400
commit21fe6139c683240c6be4718e448c4915b2fc1021 (patch)
tree2ffb5879684cd60adabff8c418dfb68c12e67555
parentb9d6697007bc10244f542fc8d3b6386823bd99c3 (diff)
downloadtextadept-21fe6139c683240c6be4718e448c4915b2fc1021.tar.gz
textadept-21fe6139c683240c6be4718e448c4915b2fc1021.zip
Replaced `buffer.style_name` table with `buffer:name_of_style()`.
This requires Scintilla changeset 429993cf4429.
-rw-r--r--CHANGELOG.md3
-rw-r--r--core/.buffer.luadoc10
-rw-r--r--modules/textadept/file_types.lua19
-rw-r--r--modules/textadept/menu.lua2
-rw-r--r--src/Makefile8
-rw-r--r--test/test.lua4
6 files changed, 19 insertions, 27 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 13eabff0..5ef765cd 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2609,7 +2609,7 @@ Changes:
* Renamed `gui` to [`ui`][].
* Renamed `_M.textadept` to [`textadept`][].
* New [`events.INITIALIZED`][] event.
-* Renamed `buffer:get_style_name()` to [`buffer.style_name`][].
+* Renamed `buffer:get_style_name()` to `buffer.style_name`.
* Renamed `ui.docstatusbar_text` to [`ui.bufstatusbar_text`][].
* Removed `textadept.bookmarks.BOOKMARK_COLOR`,
`textadept.editing.HIGHLIGHT_COLOR`, and `textadept.run.ERROR_COLOR` while
@@ -2631,7 +2631,6 @@ Changes:
[`ui`]: api.html#ui
[`textadept`]: api.html#textadept
[`events.INITIALIZED`]: api.html#events.INITIALIZED
-[`buffer.style_name`]: api.html#buffer.style_name
[`ui.bufstatusbar_text`]: api.html#ui.bufstatusbar_text
[`io` module]: api.html#io
[CDK]: http://invisible-island.net/cdk/cdk.html
diff --git a/core/.buffer.luadoc b/core/.buffer.luadoc
index ec97e5eb..f7670b7b 100644
--- a/core/.buffer.luadoc
+++ b/core/.buffer.luadoc
@@ -795,8 +795,6 @@
-- Table of flags that indicate whether or not text is italic for style
-- numbers from `0` to `255`.
-- The default values are `false`.
--- @field style_name (table, Read-only)
--- Table of style names for style numbers from `0` to `255`.
-- @field style_size (table)
-- Table of font sizes of text for style numbers from `0` to `255`.
-- @field style_underline (table)
@@ -2383,6 +2381,13 @@ function multi_edge_add_line(buffer, column, color) end
function multi_edge_clear_all(buffer) end
---
+-- Returns the name of style number *style*, which is between `0` and `255`.
+-- @param buffer A buffer.
+-- @param style_num The style number between `0` and `255` to get the name of.
+-- @return string
+function name_of_style(buffer, style) end
+
+---
-- Types a new line at the caret position according to [`buffer.eol_mode`]().
-- @param buffer A buffer.
function new_line(buffer) end
@@ -3311,7 +3316,6 @@ function set_theme(buffer, name, props) end
-- * line_from_index_position
-- * load_lexer_library
-- * mouse_wheel_captures
--- * name_of_style
-- * named_styles
-- * null
-- * point_x_from_position
diff --git a/modules/textadept/file_types.lua b/modules/textadept/file_types.lua
index 40416927..21261093 100644
--- a/modules/textadept/file_types.lua
+++ b/modules/textadept/file_types.lua
@@ -42,7 +42,7 @@ end
-- Attempts to detect the language based on a buffer's first line of text or
-- that buffer's filename.
-- @param buffer The buffer to detect the language of.
--- @return lexer language
+-- @return lexer language or nil
local function detect_language(buffer)
local line = buffer:get_line(0)
-- Detect from first line.
@@ -50,8 +50,7 @@ local function detect_language(buffer)
if line:find(patt) then return lexer end
end
-- Detect from file extension.
- return buffer.filename and M.extensions[buffer.filename:match('[^/\\.]+$')] or
- 'text'
+ return buffer.filename and M.extensions[buffer.filename:match('[^/\\.]+$')]
end
local SETDIRECTPOINTER = _SCINTILLA.properties.doc_pointer[2]
@@ -60,32 +59,24 @@ local GETERROR = _SCINTILLA.properties.status[1]
-- LuaDoc is in core/.buffer.luadoc.
local function set_lexer(buffer, lang)
assert_type(lang, 'string/nil', 2)
- if not lang then lang = detect_language(buffer) end
+ if not lang then lang = detect_language(buffer) or 'text' end
buffer:private_lexer_call(SETDIRECTPOINTER, buffer.direct_pointer)
buffer:private_lexer_call(SETLEXERLANGUAGE, lang)
local errmsg = buffer:private_lexer_call(GETERROR)
if #errmsg > 0 then
buffer:private_lexer_call(SETLEXERLANGUAGE, 'text')
- ui.print(errmsg)
- return -- do not error() since the stack trace implicates this function
+ error(errmsg, 2)
end
buffer._lexer = lang
if package.searchpath(lang, package.path) then _M[lang] = require(lang) end
if buffer ~= ui.command_entry then events.emit(events.LEXER_LOADED, lang) end
local last_line = buffer.first_visible_line + buffer.lines_on_screen
- buffer:colourise(0, buffer:position_from_line(last_line + 1))
+ buffer:colourise(0, buffer:position_from_line(last_line + 1)) -- refresh
end
-- Gives new buffers lexer-specific functions.
events.connect(events.BUFFER_NEW, function()
buffer.get_lexer, buffer.set_lexer = get_lexer, set_lexer
- buffer.style_name = setmetatable({}, {
- __index = function(_, style_num) -- LuaDoc is in core/.buffer.luadoc
- return style_num >= 0 and style_num <= 255 and
- buffer:private_lexer_call(style_num) or nil
- end,
- __newindex = function() error('read-only property') end
- })
end, 1)
-- Auto-detect lexer on file open or save as.
diff --git a/modules/textadept/menu.lua b/modules/textadept/menu.lua
index f986037a..24790f96 100644
--- a/modules/textadept/menu.lua
+++ b/modules/textadept/menu.lua
@@ -256,7 +256,7 @@ local default_menubar = {
local text = string.format("'%s' (U+%04X:%s)\n%s %s\n%s %s (%d)", char,
utf8.codepoint(char), bytes, _L['Lexer'],
buffer:get_lexer(true), _L['Style'],
- buffer.style_name[style], style)
+ buffer:name_of_style(style), style)
buffer:call_tip_show(buffer.current_pos, text)
end}
},
diff --git a/src/Makefile b/src/Makefile
index 444a8afd..70446771 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -114,9 +114,9 @@ sci_objs = AutoComplete.o CallTip.o CaseConvert.o CaseFolder.o Catalogue.o \
Indicator.o KeyMap.o LineMarker.o MarginView.o PerLine.o \
PositionCache.o RESearch.o RunStyles.o ScintillaBase.o Selection.o \
Style.o UniConversion.o ViewStyle.o UniqueString.o XPM.o
-sci_lex_objs = Accessor.o CharacterCategory.o CharacterSet.o LexerBase.o \
- LexerModule.o LexerNoExceptions.o LexerSimple.o PropSetSimple.o \
- StyleContext.o WordList.o
+sci_lex_objs = Accessor.o CharacterCategory.o CharacterSet.o DefaultLexer.o \
+ LexerBase.o LexerModule.o LexerNoExceptions.o LexerSimple.o \
+ PropSetSimple.o StyleContext.o WordList.o
sci_lexer_objs = LexLPeg.o LexLPeg-curses.o
sci_gtk_objs = PlatGTK.o ScintillaGTK.o ScintillaGTKAccessible.o
sci_curses_objs = ScintillaCurses.o
@@ -366,7 +366,7 @@ else
gtdialog_url = http://foicica.com/hg/gtdialog/archive/tip.zip
endif
-scintilla_zip = 0c14c2086500.zip
+scintilla_zip = 429993cf4429.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 e21e3da8..80ec31c4 100644
--- a/test/test.lua
+++ b/test/test.lua
@@ -1753,11 +1753,9 @@ function test_file_types_get_lexer()
buffer:goto_pos(buffer:position_from_line(LINE(2)))
assert_equal(buffer:get_lexer(), 'html')
assert_equal(buffer:get_lexer(true), 'css')
- assert_equal(buffer.style_name[buffer.style_at[buffer.current_pos]], 'identifier')
+ assert_equal(buffer:name_of_style(buffer.style_at[buffer.current_pos]), 'identifier')
buffer:set_save_point()
io.close_buffer()
-
- assert_raises(function() buffer.style_name[1] = 'foo' end, 'read-only property')
end
function test_file_types_set_lexer()