From de3a745e1af2e441de868c2aa4849102d376acb5 Mon Sep 17 00:00:00 2001 From: mitchell <70453897+orbitalquark@users.noreply.github.com> Date: Sun, 11 Apr 2021 09:34:17 -0400 Subject: Initial pass reformatting all code. Use clang-format, LuaFormatter, and 100 character limit on lines. --- scripts/fill_layout.lua | 16 +++---- scripts/gen_iface.lua | 95 ++++++++++++++++++------------------------ scripts/gen_lua_c_api_tags.lua | 8 ++-- scripts/gen_plist.lua | 18 ++++---- scripts/gen_plots.sh | 6 +-- scripts/markdowndoc.lua | 30 ++++++------- scripts/osx/textadept_osx | 4 +- 7 files changed, 77 insertions(+), 100 deletions(-) (limited to 'scripts') diff --git a/scripts/fill_layout.lua b/scripts/fill_layout.lua index a60584dc..a1b236cd 100755 --- a/scripts/fill_layout.lua +++ b/scripts/fill_layout.lua @@ -1,10 +1,9 @@ #!/usr/bin/lua --- Filters the given file through markdown, inserts it into the template --- specified by stdin by replacing simple {{ variable }} tags, and outputs the --- result to stdout. +-- Filters the given file through markdown, inserts it into the template specified by stdin by +-- replacing simple {{ variable }} tags, and outputs the result to stdout. --- Filter the file through markdown using TOC generation in order to get header --- anchors, but ignore the actual TOC. +-- Filter the file through markdown using TOC generation in order to get header anchors, but +-- ignore the actual TOC. local p = io.popen('markdown -f toc -T ' .. arg[1]) local html = p:read('*a'):match('^.-\n\n(.+)$') html = html:gsub('([^<]+)'), - content = html:gsub('%%', '%%%%') -} -io.write(io.stdin:read('*a'):gsub('{{ (%S+) }}', tags)) +local tags = {['page.title'] = html:match('([^<]+)'), content = html} +io.write((io.stdin:read('*a'):gsub('{{ (%S+) }}', tags))) diff --git a/scripts/gen_iface.lua b/scripts/gen_iface.lua index 87844b47..28588cd8 100755 --- a/scripts/gen_iface.lua +++ b/scripts/gen_iface.lua @@ -6,37 +6,34 @@ local const_patt = '^val ([%w_]+)=([-%dx%x]+)' local event_patt = '^evt %a+ ([%w_]+)=(%d+)(%b())' local msg_patt = '^(%a+) (%a+) (%w+)=(%d+)%((%a*)%s*([^,]*),%s*(%a*)%s*([^)]*)' local types = { - [''] = 0, void = 0, int = 1, length = 2, index = 3, position = 3, line = 3, - colour = 4, bool = 5, keymod = 6, string = 7, stringresult = 8, cells = 9, - pointer = 1, textrange = 10, findtext = 11, formatrange = 12 + [''] = 0, void = 0, int = 1, length = 2, index = 3, position = 3, line = 3, colour = 4, bool = 5, + keymod = 6, string = 7, stringresult = 8, cells = 9, pointer = 1, textrange = 10, findtext = 11, + formatrange = 12 } local ignores = { -- constants to ignore - '^INDIC[012S]_', '^INVALID_POSITION', '^KEYWORDSET_MAX', '^SC_AC_', - '^SC_DOCUMENTOPTION_', '^SC_CACHE_', '^SC_CHARSET_', '^SC_EFF_', - '^SC_FONT_SIZE_MULTIPLIER', '^SC_INDIC', '^SC_LINE_END_TYPE_', '^SC_PHASES_', - '^SC_POPUP_', '^SC_PRINT_', '^SC_STATUS_', '^SC_TECHNOLOGY_', '^SC_TYPE_', - '^SC_WEIGHT_', '^SCE_', '^SCEN_', '^SCFIND_POSIX', '^SCI_', '^SCK_', - '^SCLEX_', '^UNDO_MAY_COALESCE' + '^INDIC[012S]_', '^INVALID_POSITION', '^KEYWORDSET_MAX', '^SC_AC_', '^SC_DOCUMENTOPTION_', + '^SC_CACHE_', '^SC_CHARSET_', '^SC_EFF_', '^SC_FONT_SIZE_MULTIPLIER', '^SC_INDIC', + '^SC_LINE_END_TYPE_', '^SC_PHASES_', '^SC_POPUP_', '^SC_PRINT_', '^SC_STATUS_', '^SC_TECHNOLOGY_', + '^SC_TYPE_', '^SC_WEIGHT_', '^SCE_', '^SCEN_', '^SCFIND_POSIX', '^SCI_', '^SCK_', '^SCLEX_', + '^UNDO_MAY_COALESCE' } local increments = { -- constants to increment by one '^MARKER_MAX', '^MARKNUM_', '^MAX_MARGIN', '^STYLE_', '^INDICATOR_' } local changed_setter = {} -- holds properties changed to setter functions local function to_en_us(name) - return name:gsub('([iIlL][oO])[uU]([rR])', '%1%2'): - gsub('ise$', 'ize'):gsub('([cC][eE][nN][tT])([rR])([eE])', '%1%3%2'): - gsub('CANCELLED', 'CANCELED') + return name:gsub('([iIlL][oO])[uU]([rR])', '%1%2'):gsub('ise$', 'ize'):gsub( + '([cC][eE][nN][tT])([rR])([eE])', '%1%3%2'):gsub('CANCELLED', 'CANCELED') end local function to_lua_name(camel_case) - return to_en_us(camel_case:gsub('([a-z])([A-Z])', '%1_%2'): - gsub('([A-Z])([A-Z][a-z])', '%1_%2'):lower()) -end -local function is_length(ptype, param) - return ptype == 'position' and param:find('^length') + return to_en_us(camel_case:gsub('([a-z])([A-Z])', '%1_%2'):gsub('([A-Z])([A-Z][a-z])', '%1_%2') + :lower()) end +local function is_length(ptype, param) return ptype == 'position' and param:find('^length') end local function is_index(ptype, param) - return ptype == 'int' and (param == 'style' or param == 'markerNumber' or - param == 'margin' or param == 'indicator' or param == 'selection') + return ptype == 'int' and + (param == 'style' or param == 'markerNumber' or param == 'margin' or param == 'indicator' or + param == 'selection') end for line in io.lines('../src/scintilla/include/Scintilla.iface') do @@ -92,15 +89,13 @@ for line in io.lines('../src/scintilla/include/Scintilla.iface') do functions[#functions + 1] = name functions[name] = {id, types[rtype], types[wtype], types[ltype]} elseif line:find('^get ') or line:find('^set ') then - local kind, rtype, name, id, wtype, param, ltype, param2 = - line:match(msg_patt) + local kind, rtype, name, id, wtype, param, ltype, param2 = line:match(msg_patt) if rtype:find('^%u') then rtype = 'int' end if wtype:find('^%u') then wtype = 'int' end if ltype:find('^%u') then ltype = 'int' end name = to_lua_name(name:gsub('[GS]et%f[%u]', '')) - if kind == 'get' and types[wtype] == types.int and - types[ltype] == types.int or wtype == 'bool' and ltype ~= '' or - changed_setter[name] then + if kind == 'get' and types[wtype] == types.int and types[ltype] == types.int or + (wtype == 'bool' and ltype ~= '') or changed_setter[name] then -- Special case getter/setter; handle as function. local fname = kind .. '_' .. name functions[#functions + 1] = fname @@ -121,9 +116,7 @@ for line in io.lines('../src/scintilla/include/Scintilla.iface') do if wtype ~= '' then prop[4] = types[wtype] end else prop[2] = id - if prop[1] == 0 then - prop[3] = types[wtype ~= '' and ltype == '' and wtype or ltype] - end + if prop[1] == 0 then prop[3] = types[wtype ~= '' and ltype == '' and wtype or ltype] end prop[4] = types[ltype ~= '' and wtype or ltype] end elseif line:find('cat Provisional') then @@ -136,8 +129,8 @@ end functions['auto_c_show'][3] = types.int -- was interpreted as 'length' functions['get_cur_line'][2] = types.position -- was interpreted as 'void' --- Manually adjust messages whose param or return types would be interpreted as --- 1-based numbers, but should not be, or vice-versa. +-- Manually adjust messages whose param or return types would be interpreted as 1-based numbers, +-- but should not be, or vice-versa. properties['length'][3] = types.int properties['style_at'][3] = types.index functions['marker_handle_from_line'][4] = types.index @@ -186,8 +179,7 @@ local M = {} --[[ This comment is for LuaDoc. --- -- Scintilla constants, functions, and properties. --- Do not modify anything in this module. Doing so will have unpredictable --- consequences. +-- Do not modify anything in this module. Doing so will have unpredictable consequences. module('_SCINTILLA')]] ]=]) @@ -202,8 +194,8 @@ f:write(table.concat(constants, ',')) f:write('}\n\n') f:write([[ --- --- Map of Scintilla function names to tables containing their IDs, return types, --- wParam types, and lParam types. Types are as follows: +-- Map of Scintilla function names to tables containing their IDs, return types, wParam types, +-- and lParam types. Types are as follows: -- -- + `0`: Void. -- + `1`: Integer. @@ -218,14 +210,13 @@ f:write([[ -- @name functions M.functions = {]]) for _, func in ipairs(functions) do - f:write( - string.format('%s={%d,%d,%d,%d},', func, table.unpack(functions[func]))) + f:write(string.format('%s={%d,%d,%d,%d},', func, table.unpack(functions[func]))) end f:write('}\n\n') f:write([[ --- --- Map of Scintilla property names to table values containing their "get" --- function IDs, "set" function IDs, return types, and wParam types. +-- Map of Scintilla property names to table values containing their "get" function IDs, "set" +-- function IDs, return types, and wParam types. -- The wParam type will be non-zero if the property is indexable. -- Types are the same as in the `functions` table. -- @see functions @@ -233,8 +224,7 @@ f:write([[ -- @name properties M.properties = {]]) for _, property in ipairs(properties) do - f:write(string.format( - '%s={%d,%d,%d,%d},', property, table.unpack(properties[property]))) + f:write(string.format('%s={%d,%d,%d,%d},', property, table.unpack(properties[property]))) end f:write('}\n\n') f:write([[ @@ -243,17 +233,15 @@ f:write([[ -- @class table -- @name events M.events = {]]) -for _, event in ipairs(events) do - f:write(string.format('[%s]={%s},', event, events[event])) -end +for _, event in ipairs(events) do f:write(string.format('[%s]={%s},', event, events[event])) end f:write('}\n\n') f:write([[ local marker_number, indic_number, list_type, image_type = 0, 0, 0, 0 --- -- Returns a unique marker number for use with `view.marker_define()`. --- Use this function for custom markers in order to prevent clashes with --- identifiers of other custom markers. +-- Use this function for custom markers in order to prevent clashes with identifiers of other +-- custom markers. -- @usage local marknum = _SCINTILLA.next_marker_number() -- @see view.marker_define -- @name next_marker_number @@ -265,8 +253,8 @@ end --- -- Returns a unique indicator number for use with custom indicators. --- Use this function for custom indicators in order to prevent clashes with --- identifiers of other custom indicators. +-- Use this function for custom indicators in order to prevent clashes with identifiers of +-- other custom indicators. -- @usage local indic_num = _SCINTILLA.next_indic_number() -- @see view.indic_style -- @name next_indic_number @@ -277,10 +265,9 @@ function M.next_indic_number() end --- --- Returns a unique user list identier number for use with --- `buffer.user_list_show()`. --- Use this function for custom user lists in order to prevent clashes with --- list identifiers of other custom user lists. +-- Returns a unique user list identier number for use with `buffer.user_list_show()`. +-- Use this function for custom user lists in order to prevent clashes with list identifiers +-- of other custom user lists. -- @usage local list_type = _SCINTILLA.next_user_list_type() -- @see buffer.user_list_show -- @name next_user_list_type @@ -290,10 +277,10 @@ function M.next_user_list_type() end --- --- Returns a unique image type identier number for use with --- `view.register_image()` and `view.register_rgba_image()`. --- Use this function for custom image types in order to prevent clashes with --- identifiers of other custom image types. +-- Returns a unique image type identier number for use with `view.register_image()` and +-- `view.register_rgba_image()`. +-- Use this function for custom image types in order to prevent clashes with identifiers of +-- other custom image types. -- @usage local image_type = _SCINTILLA.next_image_type() -- @see view.register_image -- @see view.register_rgba_image diff --git a/scripts/gen_lua_c_api_tags.lua b/scripts/gen_lua_c_api_tags.lua index 1830652c..20c6dda3 100755 --- a/scripts/gen_lua_c_api_tags.lua +++ b/scripts/gen_lua_c_api_tags.lua @@ -4,10 +4,10 @@ local f = io.open('../modules/ansi_c/lua_tags', 'w') -- Lua header files define API functions in a way ctags cannot detect. -- For example: `LUA_API lua_State *(lua_newstate) (lua_Alloc f, void *ud);`. --- The function name enclosed in parenthesis is causing the problem. A regex --- must be used to capture those definitions. -local p = io.popen('ctags -o - --regex-c++="/\\(([a-zA-Z_]+)\\) +\\(/\\1/f/" '.. - '../src/lua/src/lua.h ../src/lua/src/lauxlib.h') +-- The function name enclosed in parenthesis is causing the problem. A regex must be used to +-- capture those definitions. +local p = io.popen('ctags -o - --regex-c++="/\\(([a-zA-Z_]+)\\) +\\(/\\1/f/" ' .. + '../src/lua/src/lua.h ../src/lua/src/lauxlib.h') for line in p:read('*a'):gmatch('[^\n]+') do -- Strip comment lines and replace file and ex_cmd fields with empty info. if not line:find('^!') then diff --git a/scripts/gen_plist.lua b/scripts/gen_plist.lua index ab6cee55..0ecabb68 100755 --- a/scripts/gen_plist.lua +++ b/scripts/gen_plist.lua @@ -19,6 +19,7 @@ for type in types:gmatch('(.-)[%],}]+') do end end +-- LuaFormatter off -- Generate and write the XML. local xml = {[[ @@ -51,13 +52,14 @@ xml[#xml + 1] = [[ com.apple.xml-property-list com.netscape.javascript-source com.sun.java-source]] +-- LuaFormatter on for i = 1, #languages do lang, exts = languages[i], extensions[languages[i]] if #exts > 0 then - xml[#xml + 1] = "\t\t\t\tcom.textadept."..lang:gsub(' ', '-').. - "-source" + xml[#xml + 1] = "\t\t\t\tcom.textadept." .. lang:gsub(' ', '-') .. "-source" end end +-- LuaFormatter off xml[#xml + 1] = [[ net.daringfireball.markdown public.c-header @@ -101,6 +103,7 @@ xml[#xml + 1] = [[ UTImportedTypeDeclarations ]] +-- LuaFormatter on for i = 1, #languages do lang, exts = languages[i], extensions[languages[i]] if #exts > 0 then @@ -109,16 +112,13 @@ for i = 1, #languages do xml[#xml + 1] = "\t\t\t" xml[#xml + 1] = "\t\t\t\tpublic.filename-extension" xml[#xml + 1] = "\t\t\t\t" - for j = 1, #exts do - xml[#xml + 1] = "\t\t\t\t\t"..exts[j].."" - end + for j = 1, #exts do xml[#xml + 1] = "\t\t\t\t\t" .. exts[j] .. "" end xml[#xml + 1] = "\t\t\t\t" xml[#xml + 1] = "\t\t\t" xml[#xml + 1] = "\t\t\tUTTypeDescription" - xml[#xml + 1] = "\t\t\t"..lang.." source" + xml[#xml + 1] = "\t\t\t" .. lang .. " source" xml[#xml + 1] = "\t\t\tUTTypeIdentifier" - xml[#xml + 1] = "\t\t\tcom.textadept."..lang:gsub(' ', '-').. - "-source" + xml[#xml + 1] = "\t\t\tcom.textadept." .. lang:gsub(' ', '-') .. "-source" xml[#xml + 1] = "\t\t\tUTTypeConformsTo" xml[#xml + 1] = "\t\t\t" xml[#xml + 1] = "\t\t\t\tpublic.source-code" @@ -126,6 +126,7 @@ for i = 1, #languages do xml[#xml + 1] = "\t\t" end end +-- LuaFormatter off xml[#xml + 1] = [[ CFBundleExecutable @@ -151,6 +152,7 @@ xml[#xml + 1] = [[ ]] +-- LuaFormatter on f = io.open('../src/Info.plist', 'w') f:write(table.concat(xml, '\n')) f:close() diff --git a/scripts/gen_plots.sh b/scripts/gen_plots.sh index fcbe75c3..9cde1147 100755 --- a/scripts/gen_plots.sh +++ b/scripts/gen_plots.sh @@ -14,10 +14,8 @@ for rev in `hg tags | awk '{print $2}' | cut -d: -f1 | tac`; do date=`hg log -r $rev | grep ^date | cut -d: -f2- | tr + - | cut -d- -f1` hg update -r $rev -q timestamp=`date -d "$date" "+%s"` - counts=`cloc --force-lang=C,h --quiet --csv \ - --exclude-dir=doc,docs,scripts,themes,test,.github \ - --not-match-f=adeptsensedoc\\|tadoc . \ - | tail -n +3 | cut -d, -f2- | sort | tr '\n' ,` + counts=`cloc --force-lang=C,h --quiet --csv --exclude-dir=doc,docs,scripts,themes,test,.github \ + --not-match-f=adeptsensedoc\\|tadoc . | tail -n +3 | cut -d, -f2- | sort | tr '\n' ,` echo $timestamp,$counts done | lua -e " -- Filter counts from cloc into a data format readable by gnuplot. diff --git a/scripts/markdowndoc.lua b/scripts/markdowndoc.lua index 036f5082..bd0b4330 100644 --- a/scripts/markdowndoc.lua +++ b/scripts/markdowndoc.lua @@ -18,15 +18,15 @@ local SEE = '* [`%s`](#%s)\n' local TABLE = '\n#### `%s`\n\n' local TFIELD = '* `%s`: %s\n' local titles = { - [PARAM] = 'Parameters', [USAGE] = 'Usage', [RETURN] = 'Return', - [SEE] = 'See also', [TFIELD] = 'Fields' + [PARAM] = 'Parameters', [USAGE] = 'Usage', [RETURN] = 'Return', [SEE] = 'See also', + [TFIELD] = 'Fields' } -- Writes a LuaDoc description to the given file. -- @param f The markdown file being written to. -- @param description The description. --- @param name The name of the module the description belongs to. Used for --- headers in module descriptions. +-- @param name The name of the module the description belongs to. Used for headers in module +-- descriptions. local function write_description(f, description, name) -- Substitute custom [`code`]() link convention with [`code`](#code) links. local self_link = '(%[`([^`(]+)%(?%)?`%])%(%)' @@ -67,9 +67,7 @@ end local function write_hashmap(f, fmt, hashmap) if not hashmap or #hashmap == 0 then return end f:write(string.format(LIST_TITLE, titles[fmt])) - for _, name in ipairs(hashmap) do - f:write(string.format(fmt, name, hashmap[name] or '')) - end + for _, name in ipairs(hashmap) do f:write(string.format(fmt, name, hashmap[name] or '')) end f:write('\n') end @@ -81,13 +79,10 @@ function M.start(doc) f:write('## Textadept API Documentation\n\n') -- Create the table of contents. - for _, name in ipairs(modules) do - f:write(string.format(TOC, name, '#' .. name)) - end + for _, name in ipairs(modules) do f:write(string.format(TOC, name, '#' .. name)) end f:write('\n') - -- Create a map of doc objects to file names so their Markdown doc comments - -- can be extracted. + -- Create a map of doc objects to file names so their Markdown doc comments can be extracted. local filedocs = {} for _, name in ipairs(files) do filedocs[files[name].doc] = name end @@ -150,13 +145,12 @@ function M.start(doc) f:write('### Tables defined by `', name, '`\n\n') for _, tname in ipairs(tables) do local tbl = tables[tname] - if not tbl.name:find('%.') and - (name ~= '_G' or tbl.name == 'buffer' or tbl.name == 'view') then - tbl.name = name .. '.' .. tbl.name -- absolute name - elseif tbl.name ~= '_G.keys' and tbl.name ~= '_G.snippets' then - tbl.name = tbl.name:gsub('^_G%.', '') -- strip _G required for Luadoc + if not tname:find('%.') and (name ~= '_G' or tname == 'buffer' or tname == 'view') then + tname = name .. '.' .. tname -- absolute name + elseif tname ~= '_G.keys' and tname ~= '_G.snippets' then + tname = tname:gsub('^_G%.', '') -- strip _G required for Luadoc end - f:write(string.format(TABLE, tbl.name, tbl.name)) + f:write(string.format(TABLE, tname, tname)) write_description(f, tbl.description) write_hashmap(f, TFIELD, tbl.field) write_list(f, USAGE, tbl.usage) diff --git a/scripts/osx/textadept_osx b/scripts/osx/textadept_osx index e5cfc662..cea160ed 100755 --- a/scripts/osx/textadept_osx +++ b/scripts/osx/textadept_osx @@ -18,8 +18,8 @@ export CHARSETALIASDIR="$bundle_res/lib" # Strip out the argument added by macOS. if [ x`echo "x$1" | sed "s/^x-psn_.*//"` == x ]; then shift 1; fi -# Source '~/.textadept/osx_env.sh' to set variables like $PATH when opening -# Textadept.app from the Dock or the Finder. +# Source '~/.textadept/osx_env.sh' to set variables like $PATH when opening Textadept.app from +# the Dock or the Finder. if [ -f $HOME/.textadept/osx_env.sh ]; then . $HOME/.textadept/osx_env.sh; fi # Run Textadept. -- cgit v1.2.3