[m-rev.] for review: rewrite of vim syntax file

Sebastian Godelet sebastian.godelet at outlook.com
Thu Apr 16 18:57:49 AEST 2015


Hi Peter,

here is a diff addressing all additional changes, based on my last 
attached diff.
Additionally I have attached a diff based on master if needed.

cheers, Sebastian.
----
diff --git a/vim/doc/mercury.txt b/vim/doc/mercury.txt
index 04fdbbe..006ff7f 100644
--- a/vim/doc/mercury.txt
+++ b/vim/doc/mercury.txt
@@ -72,33 +72,16 @@ following directive after the |encoding| setting 
from 2.4. >

      " Spelling (comes after encoding, to reduce load time, see :help 
spell)
      :setlocal spell spelllang=en_gb
->
+<
 
=============================================================================
  3. Filetype plugin                                      *mercury-ftplugin*

  If the mercury_highlight_extra option from |mercury-syntax| is enabled,
-One can use the following function to visually select the current
-code block (e.g. predicate definition, declaration, pragma, etc.), which
-might be helpful for refactoring. You can put this into ftplugin (or
-|after-directory|) file: >
-
-    inoremap <KEY> <ESC>:call <SID>MarkCurrentPred()<CR>
-    nnoremap <KEY> :call <SID>MarkCurrentPred()<CR>
->
-
-In a previous version of the ftplugin, there where these keybindings
-defined which are presumably not used that often. If you want them back,
-please put them into the same file as above, preferably into an
-|after-directory| file: >
-
-      " <F6> attempts to wrap a call up with { } braces for DCG escapes.
-      "
-    nnoremap <F6> I{ <ESC>%a }<ESC>j
-
-      " <F7> and <F8> comment and uncomment lines out respectively.
-      "
-    nnoremap <F7> 0i% <ESC>j
-    nnoremap <F8> :s/% //e<CR>j
+following keybindings are active: >
+
+    <C-K>r  for renaming variables, starting with the current name
+    <C-K>R  for renaming variables, starting with an empty name
+    <C-K>m  visually marks the current predicate (for copy & pasting)
  <
 
=============================================================================
  4. Mercury commands plugin                              *mercury-commands*
diff --git a/vim/ftplugin/mercury.vim b/vim/ftplugin/mercury.vim
index 1087274..c996e49 100644
--- a/vim/ftplugin/mercury.vim
+++ b/vim/ftplugin/mercury.vim
@@ -1,9 +1,11 @@
  " Vim syntax file
  " Language:     Mercury
  " Maintainer:   Sebastian Godelet <sebastian.godelet at outlook.com>
-" Last Change:  2015-04-15
+" Last Change:  2015-04-16
  " vim: ts=2 sw=2 et

+" for documentation, please use :help mercury-ftplugin
+
  if exists("b:did_mercury_ftplugin")
    finish
  endif
@@ -18,7 +20,7 @@ setlocal 
tags+=$HOME/mercury/tags.library,$HOME/mercury/tags.compiler

    " Handy if you use `:make'.
    "
-setlocal makeprg="mmc -m"
+setlocal makeprg=mmc\ --make

    " Don't wrap over-long lines.
    "
@@ -33,7 +35,7 @@ if exists("mercury_coding_standard") && 
mercury_coding_standard
    setlocal textwidth=78
    if v:version >= 703
      setlocal colorcolumn=+1
-    " Controls how auto-indenting works.  See the Vim help pages for 
details.
+      " Controls how auto-indenting works.  See the Vim help pages for 
details.
      setlocal fo-=t " do not automatically wrap text
      setlocal fo+=c " auto wrap comments, using comment leader
      setlocal fo+=r " automatically insert the comment leader after <CR>
@@ -51,15 +53,15 @@ endif
  nnoremap <C-X>l 
o0<C-D>%---------------------------------------------------------------------------%<CR><ESC>x

  if exists("mercury_highlight_extra") && mercury_highlight_extra
-    " <C-K>r is for renaming variables, starting with the current name
-    " <C-K>R is for renaming variables, starting with an empty name
-    "
    inoremap <C-K>r <ESC> :call <SID>RenameCurrentVariable(1)<CR>
    nnoremap <C-K>r :call <SID>RenameCurrentVariable(1)<CR>

    inoremap <C-K>R <ESC> :call <SID>RenameCurrentVariable(0)<CR>
    nnoremap <C-K>R :call <SID>RenameCurrentVariable(0)<CR>

+  inoremap <C-K>m <ESC> :call <SID>MarkCurrentPred()<CR>
+  nnoremap <C-K>m :call <SID>MarkCurrentPred()<CR>
+
      " Match all the occurrences of the variable under the cursor
      "
    augroup mercuryMatchVar
@@ -90,18 +92,29 @@ nnoremap ,P <ESC>O:- pragma 
foreign_proc("C",<CR><TAB>(_IO0::di, _IO::uo),<CR>[w
  nnoremap ,M <ESC>O:- mutable(VAR, TYPE, VALUE, ground, [untrailed, 
attach_to_io_state]).<ESC>2FVcw
  nnoremap ,T <ESC>Otrace [io(!IO)] (<CR>),<ESC>^O<TAB>

-  " sg - this is now the default
-" nnoremap ,m :set makeprg=mmc\ --make\
-nnoremap gi m':1/^:- interface<CR>jj
-nnoremap gI m':1/^:- implementation<CR>jj
-nnoremap gE m':/^:- end_module<CR>
+nnoremap <C-X>i m':1/^:- interface<CR>jj
+nnoremap <C-X>I m':1/^:- implementation<CR>jj

  inoremap <F3> ::in,
  inoremap <F4> ::out,
  inoremap <F5> io::di, io::uo)
  inoremap <F6> is det.

-  " functions
+  " In a previous version of the ftplugin, there where these keybindings
+  " defined which are presumably not used that often.
+
+  " <F6> attempts to wrap a call up with { } braces for DCG escapes.
+  "
+" nnoremap <F6> I{ <ESC>%a }<ESC>j
+
+  " <F7> and <F8> comment and uncomment lines out respectively.
+  "
+  " It might be better to use (and adjust) a common script for this task
+  " http://www.vim.org/scripts/script.php?script_id=2844
+  " TODO: Provide a copy and optionally bundle within vim/Makefile
+  "
+" nnoremap <F7> 0i% <ESC>j
+" nnoremap <F8> :s/% //e<CR>j

  fu! s:HighlightMatchingVariables()
      " Avoid that we remove the popup menu.
@@ -131,7 +144,7 @@ fu! s:HighlightMatchingVariables()
          \ l:lineL1PredEnd   == w:lineL1PredEnd
      return
    elseif exists('w:variable_hl_on') && w:variable_hl_on
-    " Remove any previous match.
+      " Remove any previous match.
      2match none
      let w:variable_hl_on = 0
    endif
@@ -161,7 +174,7 @@ endfu
  fu! s:CurrentSynIsRegion(pos)
    if a:pos[0] == 0|return 0|endif
    let l:id = synID(a:pos[0], a:pos[1], 0)
-  " TODO: Also check for mercuryString
+    " TODO: Also check for mercuryString
    return l:id == synIDtrans(l:id) ? 1 : 0
  endfu

@@ -198,6 +211,10 @@ fu! s:RenameCurrentVariable(keepName)
    endif
  endfu

+  " One can use the following function to visually select the current
+  " code block (e.g. predicate definition, declaration, pragma, etc.), 
which
+  " might be helpful for refactoring.
+  "
  fu! s:MarkCurrentPred()
    call setpos('.', [0, w:lineL1PredStart, 1])
    normal! v
diff --git a/vim/syntax/mercury.vim b/vim/syntax/mercury.vim
index a9cc6c8..28dd1cd 100644
--- a/vim/syntax/mercury.vim
+++ b/vim/syntax/mercury.vim
@@ -2,7 +2,9 @@
  " Language:     Mercury
  " Maintainer:   Sebastian Godelet <sebastian.godelet at outlook.com>
  " Extensions:   *.m *.moo
-" Last Change:  2015-04-15
+" Last Change:  2015-04-16
+
+" for documentation, please use :help mercury-syntax

  if exists("b:current_syntax")
    finish
@@ -467,7 +469,7 @@ if exists("mercury_highlight_comment_special") && 
mercury_highlight_comment_spec
    syn match mercuryCommentOp contained ": "

    syn cluster mercuryCommentDirectives 
contains=@Spell,mercuryToDo,mercuryCommentUri
-
+
      " Highlights the output of the Mercury error command (in extras)
    syn match mercuryCommentErr "\v(\* )@<=###[ ]@=" contained


----

On 16/04/2015 14:29, Peter Wang wrote:
> On Wed, 15 Apr 2015 12:40:36 +0800, Sebastan Godelet <sebastian.godelet at outlook.com> wrote:
>>>
>>>>
>>>> In your diff, you marked these <Fx> keyboard commands as
>>>> conflicting: " <F6> attempts to wrap a call up with { } braces for
>>>> DCG escapes. "
>>>> -nnoremap <F6> I{ <ESC>%a }<ESC>j
>>>> +" pw - conflicts
>>>> +" nnoremap <F6> I{ <ESC>%a }<ESC>j
>>>
>>> Sorry, it only conflicts with my own <F6> binding.
>> Do you think that many users are using this?
>
> I doubt it, after DCGs were largely displaced by state variables.
Ok that makes sense. After all these changes are all on master, so for a 
future release.
>
>> I find your keybindings far more useful.
>>>
>>>>      " <F7> and <F8> comment and uncomment lines out respectively.
>>>>      "
>>>> -nnoremap <F7> 0i% <ESC>j
>>>> -nnoremap <F8> :s/% //e<CR>j
>>>> +" pw - should only be applicable to mercury
>>>> +" nnoremap <F7> 0i% <ESC>j
>>>> +" nnoremap <F8> :s/% //e<CR>j
>>>>
>>>> These I didn't touch (at least I can't recall that), as far as I
>>>> remember there were like this in the original version.
>>>
>>> Never mind, I just use something else for toggling comments which
>>> works for multiple languages.
>> Would you mind to share?
>
> Hacked copy of this: http://www.vim.org/scripts/script.php?script_id=2844
I've added a note inside the ftplugin file
>
>> @@ -71,9 +76,35 @@ following directive after the |encoding| setting from 4. >
>>   =============================================================================
>>   3. Filetype plugin                                      *mercury-ftplugin*
>>
>> +If the mercury_highlight_extra option from |mercury-syntax| is enabled,
>> +One can use the following function to visually select the current
>
> one
>
>> +code block (e.g. predicate definition, declaration, pragma, etc.), which
>> +might be helpful for refactoring. You can put this into ftplugin (or
>> +|after-directory|) file: >
>> +
>> +    inoremap <KEY> <ESC>:call <SID>MarkCurrentPred()<CR>
>> +    nnoremap <KEY> :call <SID>MarkCurrentPred()<CR>
>> +>
>> +
>> +In a previous version of the ftplugin, there where these keybindings
>> +defined which are presumably not used that often. If you want them back,
>> +please put them into the same file as above, preferably into an
>> +|after-directory| file: >
>> +
>> +      " <F6> attempts to wrap a call up with { } braces for DCG escapes.
>> +      "
>> +    nnoremap <F6> I{ <ESC>%a }<ESC>j
>> +
>> +      " <F7> and <F8> comment and uncomment lines out respectively.
>> +      "
>> +    nnoremap <F7> 0i% <ESC>j
>> +    nnoremap <F8> :s/% //e<CR>j
>> +<
>
> Or just comment them out in mercury.vim?
>
>> diff --git a/vim/ftplugin/mercury.vim b/vim/ftplugin/mercury.vim
>> index d1bef44..1087274 100644
>> --- a/vim/ftplugin/mercury.vim
>> +++ b/vim/ftplugin/mercury.vim
> ...
>> @@ -92,11 +82,26 @@ endif
>>   nnoremap ,m <C-W>b:!make<UP><CR>
>>   autocmd! FileChangedShell *.err vi!
>>
>> -  " Match all the occurances of the variable under the cursor
>> -  "
>> -augroup mercuryMatchVar
>> -  autocmd! CursorMoved,CursorMovedI,WinEnter <buffer> call s:HighlightMatchingVariables()
>> -augroup END
>> +nnoremap ,p <ESC>O:- pred
>> +nnoremap ,f <ESC>O:- func
>> +nnoremap ,t <ESC>O:- type
>> +nnoremap ,i <ESC>O:- import_module
>> +nnoremap ,P <ESC>O:- pragma foreign_proc("C",<CR><TAB>(_IO0::di, _IO::uo),<CR>[will_not_call_mercury, promise_pure, thread_safe, tabled_for_io],<CR><BS>"<CR><CR><BS>").<ESC>kkkei
>> +nnoremap ,M <ESC>O:- mutable(VAR, TYPE, VALUE, ground, [untrailed, attach_to_io_state]).<ESC>2FVcw
>> +nnoremap ,T <ESC>Otrace [io(!IO)] (<CR>),<ESC>^O<TAB>
>> +
>> +  " sg - this is now the default
>> +" nnoremap ,m :set makeprg=mmc\ --make\
>
> Ok.  BTW I found you need to escape the space with backslash:
>
>      setlocal makeprg=mmc\ --make
>
>> +nnoremap gi m':1/^:- interface<CR>jj
>> +nnoremap gI m':1/^:- implementation<CR>jj
>> +nnoremap gE m':/^:- end_module<CR>
>
> gi and gI are standard vim commands so perhaps we should pick something
> else, say, <C-X>i and <C-X>I?  I don't remember ever using the gE binding
> after adding it.
Yes there's not always an end_module directive and I usually just use gg 
or G for this. I've used <C-X>[iI] now, that appears to be unused.
>
>> +
>> +inoremap <F3> ::in,
>> +inoremap <F4> ::out,
>> +inoremap <F5> io::di, io::uo)
>> +inoremap <F6> is det.
>> +
>> +  " functions
>
>> diff --git a/vim/syntax/mercury.vim b/vim/syntax/mercury.vim
>> index 463f876..a9cc6c8 100644
>> --- a/vim/syntax/mercury.vim
>> +++ b/vim/syntax/mercury.vim
> ...
>> @@ -279,7 +279,7 @@ syn region  mercuryForeignModList matchgroup=mercuryBracket start='\[' end=']'
>>         \ mercuryDelimiter, at mercuryComments, at mercuryFormatting,
>>         \ mercuryString,mercuryOperator,mercuryBlock
>>
>> -syn match mercuryClauseHead /\v^[a-z][a-zA-Z0-9_]*[(]@=/
>> +syn match mercuryClauseHead /\v^[a-zA-Z][a-zA-Z0-9_.]*[( =]@=/
>
> The first letter can be restricted to lowercase letters as well.
>
> Well, I'll like the changes, don't know about anybody else :)
Well if others on the mailing list follow this thread, they can raise 
objections.
>
> Peter
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: all-changes.diff
Type: text/x-patch
Size: 29917 bytes
Desc: not available
URL: <http://lists.mercurylang.org/archives/reviews/attachments/20150416/4bb1d84e/attachment.bin>


More information about the reviews mailing list