aboutsummaryrefslogtreecommitdiff
path: root/doc/manual/9_Preferences.md
blob: 8e6b0a481bbc53bca0ff3fe7efc6021490cc0a73 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# Preferences

At this point it is assumed you are at least familiar with the basics of
[Lua](http://www.lua.org). You do not have to know a lot of the language to
configure Textadept.

## User Init

Textadept loads modules from your `~/.textadept/init.lua` on startup. If this
file does not exist, Textadept creates it with a list of default modules to
load. You can then use the file to indicate what else you want Textadept to
load. For example if you created a generic module called `foo` that you wanted
to load alongside the default modules, your `~/.textadept/init.lua` would
contain

    require 'textadept'
    require 'foo'

If instead you wanted to load all Textadept's default modules except for the
menu, replace

    require 'textadept'

with

    require 'textadept.adeptsense'
    require 'textadept.bookmarks'
    require 'textadept.command_entry'
    require 'textadept.editing'
    require 'textadept.find'
    require 'textadept.filter_through'
    require 'textadept.mime_types'
    require 'textadept.run'
    require 'textadept.session'
    require 'textadept.snapopen'
    require 'textadept.snippets'

    --require 'textadept.menu'
    require 'textadept.keys'

Note that his list was obtained from the `textadept` module's `init.lua` which
is located in the `modules/textadept/` directory.

It is important to realize that Textadept will not load anything you do not tell
it to. If your `~/.textadept/init.lua` exists and is empty, no modules are
loaded (pretty much rendering Textadept useless).

#### Module Settings

Many of Textadept's modules have settings you can change from your
`~/.textadept/init.lua`. These settings are viewed from module's
[LuaDoc](../index.html). For example, to disable character autopairing and
whitespace stripping on save, your `~/.textadept/init.lua` might look like:

    require 'textadept'

    _m.textadept.editing.AUTOPAIR = false
    _m.textadept.editing.STRIP_WHITESPACE_ON_SAVE = false

#### Other

Your `~/.textadept/init.lua` is not restricted to just loading modules or
setting preferences. It is just Lua code that is run when Textadept loads. For
more information, see the [scripting](11_Scripting.html) page.

##### Snippets

You can add global snippets to `snippets` such as:

    snippets['file'] = '%<buffer.filename>'
    snippets['path'] = "%<(buffer.filename or ''):match('^.+[/\\]')>"

So typing `file` or `path` and then pressing `Tab` (`⇥` on Mac OSX) will insert
the snippet.

##### Key Commands

The default set of key commands is located in `modules/textadept/keys.conf`
(`modules/textadept/keys.osx.conf` on Mac OSX) and is loaded by the
`_m.textadept.menu` module. It is not recommended to edit Textadept's
`keys.conf` or `keys.osx.conf` for changing the key bindings since your changes
could be overwritten when updating Textadept. Instead, make a copy in your
`~/.textadept/` folder and modify that.

Key commands need to be defined manually for keychains or custom functions. You
can do this in your `~/.textadept/init.lua` or from a file loaded by
`~/.textadept/init.lua`. For example maybe you want `Ctrl+Shift+A, N` (`⌘⇧A, N`
on Mac OSX) to create a new buffer instead of `Ctrl+N` (`⌘N`):

    keys.cA = {}
    keys.cA.n = new_buffer
    keys.cn = nil

Earlier versions of Textadept manually defined all key commands in
`modules/textadept/keys.lua` (`keys.cn = new_buffer`, `keys.co = io.open_file`,
etc.). Now the `menu` module does this automatically by reading the keys in the
`keys.conf` or `keys.osx.conf` files mentioned earlier. Of course you can still
use Lua to define commands as demonstrated above. In fact, if you choose to
exclude loading the menu like in an earlier example above, you will have to
specify your own set of key commands! (I happen to do this and keep a copy of
`~/.textadept/modules/textadept/keys.lua` that is loaded by my
`~/.textadept/init.lua`.) Please note that key commands are _not_ handled by the
menu; they are still handled as they always have been. Therefore the keys shown
in the menu could differ from the actual set of key commands if you use Lua to
redefine them. Menu keys are shown purely for cosmetic, not functional reasons.

## Locale

Most messages displayed by Textadept are localized. `core/locale.conf` contains
these messages. By default, Textadept is localized in English. To use a
different language, put a translated version of `core/locale.conf` in your
`~/.textadept/` folder.

Feel free to translate Textadept and send your modified `locale.conf` files
to me. I will make them available to other users.

## Mime Types

Textadept recognizes a wide range of programming language files by any of the
following:

* File extension.
* Keywords in the file's shebang (`#!/path/to/exe`) line.
* A pattern that matches the text of the file's first line.

Built-in mime-types are located in `modules/textadept/mime_types.conf`. You
can override or add to them in your `~/.textadept/mime_types.conf`:

    % Recognize .luadoc files as Lua code.
    luadoc lua

    % Change .html files to be recognized as XML files instead of HTML ones.
    html xml

It is not recommended to edit Textadept's `modules/textadept/mime_types.conf`
because your changes may be overwritten when updating Textadept.

#### Detection by File Extension

    file_ext lexer

Note: `file_ext` should not start with a `.` (period).

#### Detection by Shebang Keywords

    #shebang_word lexer

Examples of `shebang_word`'s are `lua`, `ruby`, `python`.

#### Detection by Pattern

    /pattern lexer

Only the last space, the one separating the pattern from the lexer, is
significant. No spaces in the pattern need to be escaped.

## Default Run and Compile Commands and Block Quotes for Languages

Textadept does not come with language-specific modules for all languages so you
can add run commands, compile commands, and block quotes manually:

* [Run/Compile commands](http://caladbolg.net/textadeptwiki/index.php?n=Main.RunSupplemental)
* [Block Quotes](http://caladbolg.net/textadeptwiki/index.php?n=Main.CommentSupplemental)