diff options
-rw-r--r-- | FAQ.md | 10 | ||||
-rw-r--r-- | doc/06_AdeptEditing.md | 9 | ||||
-rw-r--r-- | modules/cpp/init.lua | 3 | ||||
-rw-r--r-- | modules/lua/init.lua | 3 | ||||
-rw-r--r-- | modules/textadept/editing.lua | 55 |
5 files changed, 33 insertions, 47 deletions
@@ -58,16 +58,6 @@ Take a look at these [commands][]. - - - **Q:** -Clicking "Block Comment" (or executing the key command) does nothing. Why? - -**A:** -Take a look at these [comments][]. - -[comments]: http://foicica.com/wiki/comment-supplemental - -- - - - -**Q:** The curses version does not support feature _x_ the GUI version does. Is this a bug? diff --git a/doc/06_AdeptEditing.md b/doc/06_AdeptEditing.md index 83e12802..764693c7 100644 --- a/doc/06_AdeptEditing.md +++ b/doc/06_AdeptEditing.md @@ -294,11 +294,4 @@ modules usually define their [own set][] of snippets, but your Pressing `Ctrl+/` (`⌘/` on Mac OSX | `M-/` in curses) comments or uncomments the code on the selected lines. Selecting any part of a line renders the entire line -eligible for commenting or uncommenting. Note: In order for this feature to -work, the language you are working with must have its comment prefix defined. -Language-specific modules usually [define prefixes][], but you can do so -[manually][] in your [user-init file][]. - -[define prefixes]: api/_M.html#Block.Comment -[manually]: http://foicica.com/wiki/comment-supplemental -[user-init file]: 08_Preferences.html#User.Init +eligible for commenting or uncommenting. diff --git a/modules/cpp/init.lua b/modules/cpp/init.lua index 0e328838..646ca218 100644 --- a/modules/cpp/init.lua +++ b/modules/cpp/init.lua @@ -23,9 +23,6 @@ local M = {} -- from *`_USERHOME`/modules/cpp/api*. module('_M.cpp')]] --- Comment string tables use lexer names. -_M.textadept.editing.comment_string.cpp = '//' - -- Compile and Run command tables use file extensions. _M.textadept.run.compile_command.c = 'gcc -pedantic -Os -o "%(filename_noext)" %(filename)' diff --git a/modules/lua/init.lua b/modules/lua/init.lua index 8bf381a9..90dbf0a6 100644 --- a/modules/lua/init.lua +++ b/modules/lua/init.lua @@ -24,9 +24,6 @@ local M = {} -- from *`_USERHOME`/modules/lua/api*. module('_M.lua')]] --- Comment string tables use lexer names. -_M.textadept.editing.comment_string.lua = '--' - -- Compile and Run command tables use file extensions. _M.textadept.run.compile_command.lua = 'luac %(filename)' _M.textadept.run.run_command.lua = 'lua %(filename)' diff --git a/modules/textadept/editing.lua b/modules/textadept/editing.lua index b14ac849..e28cbbc9 100644 --- a/modules/textadept/editing.lua +++ b/modules/textadept/editing.lua @@ -40,16 +40,14 @@ M.STRIP_TRAILING_SPACES = true M.HIGHLIGHT_COLOR = not CURSES and 'color.orange' or 'color.yellow' --- --- Map of lexer names to line comment prefix strings for programming languages, --- used by the `block_comment()` function. --- Keys are lexer names and values are the line comment prefixes for the --- language. This table is typically populated by [language-specific modules][]. --- --- [language-specific modules]: _M.html#Block.Comment +-- Map of lexer names to line comment strings for programming languages, used by +-- the `block_comment()` function. +-- Keys are lexer names and values are either the language's line comment +-- prefixes or block comment delimiters separated by a '|'. -- @class table -- @name comment_string -- @see block_comment -M.comment_string = {} +M.comment_string = {actionscript='//',ada='--',antlr='//',adpl='!',applescript='--',asp='\'',awk='#',b_lang='//',bash='#',batch=':',bibtex='%',boo='#',chuck='//',cmake='#',coffeescript='#',context='%',cpp='//',csharp='//',css='/*|*/',cuda='//',desktop='#',django='{#|#}',dmd='//',dot='//',eiffel='--',erlang='%',forth='|\\',fortran='!',fsharp='//',gap='#',gettext='#',glsl='//',gnuplot='#',go='//',groovy='//',gtkrc='#',haskell='--',hypertext='<!--|-->',idl='//',inform='!',ini='#',Io='#',java='//',javascript='//',json='/*|*/',jsp='//',latex='%',less='//',lilypond='%',lisp=';',lua='--',makefile='#',matlab='#',nemerle='//',nsis='#',objective_c='//',pascal='//',perl='#',php='//',pike='//',pkgbuild='#',prolog='%',props='#',ps='%',python='#',rails='#',rebol=';',rexx='--',rhtml='<!--|-->',rstats='#',ruby='#',sass='//',scala='//',scheme=';',smalltalk='"|"',sql='#',tcl='#',tex='%',vala='//',vb='\'',vbscript='\'',verilog='//',vhdl='--',xml='<!--|-->'} --- -- Map of auto-paired characters like parentheses, brackets, braces, and quotes, @@ -264,38 +262,49 @@ function M.autocomplete_word(default_words) end --- --- Comments or uncomments the selected lines with line comment prefix string --- *prefix* or the prefix from the `comment_string` table for the current lexer. +-- Comments or uncomments the selected lines with line comment string *comment* +-- or the comment from the `comment_string` table for the current lexer. -- As long as any part of a line is selected, the entire line is eligible for -- commenting/uncommenting. --- @param prefix Optional prefix string inserted or removed from the beginning --- of each line in the selection. The default value is the prefix in the --- `comment_string` table for the current lexer. +-- @param comment Optional comment string inserted or removed from each line in +-- the selection. Comment delimiters are separated by a '|'. The default value +-- is the comment in the `comment_string` table for the current lexer. -- @see comment_string -- @name block_comment -function M.block_comment(prefix) +function M.block_comment(comment) local buffer = buffer - prefix = prefix or M.comment_string[buffer:get_lexer(true)] + comment = comment or M.comment_string[buffer:get_lexer(true)] + local prefix, suffix = comment:match('^([^|]+)|?([^|]*)$') if not prefix then return end local anchor, pos = buffer.selection_start, buffer.selection_end local s, e = buffer:line_from_position(anchor), buffer:line_from_position(pos) - if s ~= e and pos == buffer:position_from_line(e) then e = e - 1 end + local ignore_last_line = s ~= e and pos == buffer:position_from_line(e) anchor, pos = buffer.line_end_position[s] - anchor, buffer.length - pos buffer:begin_undo_action() - for line = s, e do - local pos = buffer:position_from_line(line) - if buffer:text_range(pos, pos + #prefix) == prefix then - buffer:set_sel(pos, pos + #prefix) + for line = s, not ignore_last_line and e or e - 1 do + local p = buffer:position_from_line(line) + if buffer:text_range(p, p + #prefix) == prefix then + buffer:set_sel(p, p + #prefix) buffer:replace_sel('') + if suffix ~= '' then + p = buffer.line_end_position[line] + buffer:set_sel(p - #suffix, p) + buffer:replace_sel('') + if line == s then anchor = anchor - #suffix end + if line == e then pos = pos - #suffix end + end else - buffer:insert_text(pos, prefix) + buffer:insert_text(p, prefix) + if suffix ~= '' then + buffer:insert_text(buffer.line_end_position[line], suffix) + if line == s then anchor = anchor + #suffix end + if line == e then pos = pos + #suffix end + end end end buffer:end_undo_action() anchor, pos = buffer.line_end_position[s] - anchor, buffer.length - pos - if anchor < buffer:position_from_line(s) then - anchor = buffer:position_from_line(s) -- stay on the first line - end + anchor = math.max(anchor, buffer:position_from_line(s)) -- stay on first line if s ~= e then buffer:set_sel(anchor, pos) else buffer:goto_pos(pos) end end |