diff options
author | 2011-03-07 17:51:37 -0500 | |
---|---|---|
committer | 2011-03-07 17:51:37 -0500 | |
commit | 8f45a882cfcb9f31baf56be603c58f81a8561f38 (patch) | |
tree | 4a32d9cac6e6802209599fc47902a23b43ef0356 | |
parent | 8028fc7114bbe09c75b7112c9572f36cc33ad6e3 (diff) | |
download | textadept-8f45a882cfcb9f31baf56be603c58f81a8561f38.tar.gz textadept-8f45a882cfcb9f31baf56be603c58f81a8561f38.zip |
Load a post_init.lua script for language-specific module extensions.
-rw-r--r-- | doc/manual/7_Modules.md | 46 | ||||
-rw-r--r-- | modules/textadept/mime_types.lua | 5 |
2 files changed, 43 insertions, 8 deletions
diff --git a/doc/manual/7_Modules.md b/doc/manual/7_Modules.md index e430819c..193e9496 100644 --- a/doc/manual/7_Modules.md +++ b/doc/manual/7_Modules.md @@ -72,15 +72,13 @@ Pressing `Ctrl+Q` comments or uncomments the code on the selected lines. #### Buffer Properties Sometimes language-specific modules set default buffer properties like tabs and -indentation size. See the module's Lua code for these settings and change them -if you prefer something else. +indentation size. See the module's Lua code for these settings. If you wish to +change them or use different settings, see the +[Customizing Modules](#customizing_modules) section below. ## Getting Modules -The most up-to-date versions of Textadept's language modules can be found in -the [modules -repository](http://code.google.com/p/textadept/source/browse/?repo=modules). -User-created modules are also available from the +For now, user-created modules are obtained from the [wiki](http://caladbolg.net/textadeptwiki). ## Installing Modules @@ -94,3 +92,39 @@ that comes with Textadept. ## Developing Modules See the [LuaDoc](../modules/_m.html) for modules. + +## Customizing Modules + +It is never recommended to modify the default modules that come with Textadept, +even if you just want to change the buffer settings for a language-specific +module or add a few more snippets. Instead you have two options: load your own +module instead of the default one or load your custom module code after the +default module loads. To load your own module, simply place it appropriately in +`~/.textadept/modules/`. To load your module code after the default module +loads, create a `post_init.lua` Lua script in the appropriate +`~/.textadept/modules/` sub-folder. Please note that for generic modules, only +the first option applies. Either option applies for language-specific modules. + +Suppose you wanted to completely change the menubar structure. You would first +create a new `menu.lua` and then put it in `~/.textadept/modules/textadept/`. +Now when Textadept looks for `menu.lua`, it will load yours instead of its own. +Similarly, if you copy the default Lua language-specific module (`modules/lua`) +to `~/.textadept/modules/` and make custom changes, that module is loaded for +editing Lua code instead of the default module. + +If you keep a modified copy of language-specific modules, you will likely want +to update them with each new Textadept release. Instead of potentially wasting +time merging your changes, you can load custom code independent of the module in +a `post_init.lua` file. For example, instead of copying the `lua` module and +changing its `set_buffer_properties()` function to use tabs, you can do this +from `post_init.lua`: + + module('_m.lua', package.seeall) + + function set_buffer_properties() + buffer.use_tabs = true + end + +Similarly, you can use `post_init.lua` to change the compile/run commands, load +more [Adeptsense tags](../modules/_m.textadept.adeptsense.html#load_ctags), and +add additional key commands and snippets. diff --git a/modules/textadept/mime_types.lua b/modules/textadept/mime_types.lua index ff24602e..d4a7467b 100644 --- a/modules/textadept/mime_types.lua +++ b/modules/textadept/mime_types.lua @@ -119,11 +119,12 @@ local function set_lexer(buffer, lang) buffer:private_lexer_call(SETLEXERLANGUAGE, lang) local ret, err = pcall(require, lang) if ret then + ret, err = pcall(require, lang..'.post_init') _m[lang].set_buffer_properties() events.emit('language_module_loaded', lang) - elseif not ret and not err:find("^module '"..lang.."' not found:") then - error(err) end + local module_not_found = "^module '"..lang.."[^\']*' not found:" + if not ret and not err:find(module_not_found) then error(err) end buffer:colourise(0, -1) end |