Add commands for scite and automatically add comments (LUA)

Source: Internet
Author: User

Scite official documentationThe instructions for adding commands are as follows:

1
2
3
4
5
6
7
8
9
10
Command. Name. Number. filepattern
Command. Number. filepattern
Command. Is. Filter. Number. filepattern
Command. subsystem. Number. filepattern
Command. Save. Before. Number. filepattern
Command. Input. Number. filepattern
Command. Replace. selection. Number. filepattern
Command. Quiet. Number. filepattern
Command. mode. Number. filepattern
Command. Shortcut. Number. filepattern

Extra commands can be added to the Tools menu. For example to include the 'astyle' indenter, the properties file cocould contain

1
2
3
Command. name.0. *. Cc = indent
Command.0. *. Cc = astyle-tao $ (filenameext)
Command. Is. filter.0. *. Cc = 1

The first line defines the string that will appear in the Tools menu (immediately below 'Go '). the second line is the command string, similar to those of the compile, build, and go commands. the optional command. is. filter property states that the command modifies
The current file so it may need to be read in after loading the command if load. on. Activate is set.
If command. save. before is set to 1, scite automatically saves the file before execution. if it is set to 2, scite will not save the file, otherwise scite asks you. on Windows, the optional command. input Property specifies text that will be piped to the command.
This may reference other properties; for example, command. input.0 .*. cc = $ (currentselection) wocould pipe the current selection to the command processes. the command. input property is only supported for subsystem 0 (command line programs ).

The optional command. replace. selection can be used to specify that the command output shocould Replace the current selection (or be inserted at the cursor location, if there is no selection ). this property has three available settings: 0, the default, means do
Not replace the selection. 1 means replace the selection when the command finishes. 2 means replace the selection only if the command finishes with an exit code of 0. if the user cancels the command via "tools/stop executing", the selection will not be replaced
Even in Mode 1. note, commands run asynchronously, so you are not prevented from modifying the document or even switching buffers while a command is running. however, please bear in mind that command. replace. selection will send the output to whatever window
Is active when the command completes.
A final command property that is currently supported only on Windows is command. quiet. A value of 1 indicates that the command I/O shoshould not be echoed to the output pane. this may be useful in combination with command. input and command. replace. selection.

The command. mode property is a comma-separated list of flags/settings. each mode setting can have an argument, separated from the setting name by a colon. for most of these, the argument portion is optional; if the setting name appears without an argument,
This works the same as "setting: yes ". if a setting is already ded in the command. mode but also appears as a separate command property, the mode property will be overridden. similarly, if a single setting appears more than once with different arguments, the last
Valid argument takes priority. The supported command. Mode settings are:

1
2
3
4
5
6
Filter-accepts keyword arguments yes and no
Quiet-accepts keyword arguments yes and no
Replaceselection-accepts yes, no, and auto
Savebefore-accepts yes, no, and prompt
Subsystem-console, windows, shellexec, Lua, ctor, winhelp, htmlhelp
Groupundo-yes or no

Currently, all of these should t groupundo are based on individual properties with similar names, and so are not described separately here. the groupundo setting works with subsystem 3 (LUA/Director), and indicates that scite shoshould treat any changes made
The command as a single undo action. A command that uses the groupundo setting shocould not change which buffer is active in the editor.
The command. shortcut cut property allows you to specify a keyboard shortcut cut for the command. by default, commands 0 to 9 have keyboard shortcuts Ctrl + 0 to Ctrl + 9 respectively, but this can be overridden. for commands numbered higher than 9, there is no default
Keyboard shortcut cut. The notation used to specify keyboard shortcuts is the same as for the user. Shortcuts property, described elsewhere in this document.

If the text of a command starts with '*' Then the parameters dialog is displayed to prompt for parameters before executing the command. the initial '*' is not supported in the command that is executed.

The command number can be in the range of 0 to 49. command numbers 0 to 9 are assigned Ctrl + number shortcuts. internally these commands use IDs starting from 1100 (idm_tools) which can be used in user. shortcuts and user. context. menu:

1
User. Context. Menu = inindent | 1100 |

If command. Name is empty then no item is added to the Tools menu. This can be used for commands that are only in the context menu or user shortcuts.

HereToLuaforwindowsSee using Lua with scite. The procedure is as follows:
1. Open the "sciteglobal. properties" file and add the following at the end of the file:

1
2
3
4
Command. name.0. * = auto addcomment
Command.0. * = auto_addcomment
Command. subsystem.0. * = 3
Command. mode.0. * = savebefore: No

2. Open the "scite \ scite-Debug \ extman. Lua" file and add the following code at the end of the file:

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
Local strcommentheader = "dependencies \ r \ n -- \ r \ n ------------------------------------------------------------------------------- \ r \ n"
Local patterncommentfun = "function. + % (. *) % )"
Local strcommentfun = "--------------------------------------------------------------------------------- \ r \ n -- \ r \ n"
Local patterncommenttable = "* ([% W _] +) * = % S * (% B {})"
Local strcommenttable = "------------------------------------------------------------------------------- \ r \ n -- @ class Table \ r \ n"
-------------------------------------------------------------------------------
-- Automatically add Lua language comments
Function auto_addcomment ()
Local nline = Editor: linefromposition (editor. currentpos)
Local nposition = Editor: positionfromline (nline)
-- File Header comment
If 0 = nline then
Editor: inserttext (nposition, strcommentheader)
Editor. currentpos = editor. lineendposition [1]
Editor: setsel (editor. currentpos, editor. currentpos)
Return
End
-- Function annotation. Only the function is declared in the same line.
Local strlinetext = Editor: textrange (nposition, editor. lineendposition [nline])
Local strparam = string. Match (strlinetext, patterncommentfun)
If nil ~ = Strparam then
Local tcommentfun = {strcommentfun}
For k in string. gmatch (strparam, "([% W _] +) [,] *") Do
Tcommentfun [# tcommentfun + 1] = string. Format ("-- @ Param % s \ r \ n", K)
End
Local strcomment = table. Concat (tcommentfun)
Editor: inserttext (Editor: positionfromline (nline), strcomment)
Editor. currentpos = editor. lineendposition [nline + 1]
Editor: setsel (editor. currentpos, editor. currentpos)
Return
End
-- Table comment
Local strrangetext = Editor: textrange (nposition, editor. length)
Local strtable, strfield = string. Match (strrangetext, patterncommenttable)
If nil ~ = Strtable then
Local tcommenttable = {strcommenttable}
Tcommenttable [# tcommenttable + 1] = string. Format ("-- @ name % s \ r \ n", strtable)
For k in string. gmatch (strfield, "([% W _] +) * = *") Do
Tcommenttable [# tcommenttable + 1] = string. Format ("-- @ field % s \ r \ n", K)
End
Local strcomment = table. Concat (tcommenttable)
Editor: inserttext (Editor: positionfromline (nline), strcomment)
Editor. currentpos = editor. lineendposition [nline + 1]
Editor: setsel (editor. currentpos, editor. currentpos)
Return
End
End

3. Save and restart scite. On the menu bar → "Tools", you can see the newly added command"Auto addcomment", As shown in:

4. In the Lua file, the effect is shown in:

5. In the current line to be commented out, press the shortcut key Ctrl + 0 to comment out. After such annotation, The Lua code can passLuadocGenerate a document. If there is a problem with the above Code or there is a better way, please let me know for correction.

References:
1. http://www.scintilla.org/SciTEDoc.html
2. http://www.scintilla.org/SciTELua.html
3. http://lua-users.org/wiki/UsingLuaWithScite

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.