Ticket #4187: commentify.plugin.sl

File commentify.plugin.sl, 723 bytes (added by psprint, 3 years ago)

An example plugin which comments the current line with /* … */

Line 
1% Copy to ~/.config/mc/plugin for this file to be loaded at mc's startup.
2
3define commentify()
4{
5    variable cur_pos;   % Current cursor offset
6    variable bol;       % Begin-Of-Line offset
7
8    % Get current cursor position and beginning of current line.
9    cur_pos = mc->cure_cursor_offset();
10    bol = mc->cure_get_bol();
11    % Move to the start of the line.
12    mc->cure_cursor_move(bol - cur_pos);
13    % Insert "/*".
14    mc->cure_insert_ahead('*');
15    mc->cure_insert_ahead('/');
16    % Move to the end of the line.
17    mc->cure_cursor_move(mc->cure_get_eol()-bol);
18    % Insert "*/".
19    mc->cure_insert_ahead('/');
20    mc->cure_insert_ahead('*');
21}
22
23mc->editor_map_key_to_func("Commentify","alt-i","commentify");