Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-09 Thread Andrew Dunstan




On 06/05/2018 05:33 PM, Andrew Gierth wrote:

"Matthew" == Matthew Woodcraft  writes:

  Matthew> A few days ago there was a suggestion on this list to add a
  Matthew> .editorconfig file specifying tab width:
  Matthew> 
https://www.postgresql.org/message-id/87efhuz9be.fsf%40news-spur.riddles.org.uk

  Matthew> The .editorconfig format also supports a
  Matthew> trim_trailing_whitespace option (see https://editorconfig.org/
  Matthew> ).

Yes. I was actually planning to ask if any .editorconfig users (of which
I'm not one - my only use for it is to improve display output on github)
would like to contribute the most useful content for such a file.




I'm not one either (yet!) but it seems to me like something worth doing. 
It seems to support an impressively large number of editors and display 
mechanisms, and adding a single small file to support it doesn't seem 
onerous.


cheers

andrew

--
Andrew Dunstanhttps://www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services




Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Andrew Gierth
> "Matthew" == Matthew Woodcraft  writes:

 Matthew> A few days ago there was a suggestion on this list to add a
 Matthew> .editorconfig file specifying tab width:
 Matthew> 
https://www.postgresql.org/message-id/87efhuz9be.fsf%40news-spur.riddles.org.uk

 Matthew> The .editorconfig format also supports a
 Matthew> trim_trailing_whitespace option (see https://editorconfig.org/
 Matthew> ).

Yes. I was actually planning to ask if any .editorconfig users (of which
I'm not one - my only use for it is to improve display output on github)
would like to contribute the most useful content for such a file.

-- 
Andrew (irc:RhodiumToad)



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Andrew Gierth
> "Peter" == Peter Eisentraut  writes:

 >> +   (lambda () (add-to-list 'write-file-functions 
 >> 'delete-trailing-whitespace)

 Peter> dir-locals doesn't work this way.  It's not a general lisp file.

Right. The correct approach is

+   (eval add-hook 'before-save-hook 'delete-trailing-whitespace nil t)))

(see the value of safe-local-eval-forms for why)

-- 
Andrew (irc:RhodiumToad)



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Matthew Woodcraft
On 2018-06-05 18:22, David Fetter wrote:
> Folks,
> 
> Here's my attempt to $subject. I've tested with vim, but I'm much less
> certain I got the EMACS code right.
> 
> Is there any interest in such a feature?

A few days ago there was a suggestion on this list to add a
.editorconfig file specifying tab width:
https://www.postgresql.org/message-id/87efhuz9be.fsf%40news-spur.riddles.org.uk

The .editorconfig format also supports a trim_trailing_whitespace option
(see https://editorconfig.org/ ).

So that might be a simpler way to achieve this (I suppose people who
don't want this behaviour just wouldn't configure their editors to
honour .editorconfig files).

-M-




Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Peter Eisentraut
On 6/5/18 13:37, Tom Lane wrote:
> I note that Peter E. seems to have a recipe for finding such issues,
> which I suspect is grounded in some obscure git feature or other.
> That might be easier to work with, since you'd only need one fix
> not one per editor.

I have a git alias:

check-whitespace = !git diff-tree --check $(git hash-object -t tree
/dev/null) HEAD ${1:-$GIT_PREFIX}

Also, in Emacs I use

(global-whitespace-mode 1)
(setq whitespace-style
  '(face
trailing empty indentation space-after-tab space-before-tab))

With source code other than PostgreSQL, this will occasionally result in
angry fruit salad.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Peter Eisentraut
On 6/5/18 13:22, David Fetter wrote:
> diff --git a/.dir-locals.el b/.dir-locals.el
> index 9525d6b604..858461e6bd 100644
> --- a/.dir-locals.el
> +++ b/.dir-locals.el
> @@ -4,7 +4,8 @@
>  (c-file-style . "bsd")
>  (fill-column . 78)
>  (indent-tabs-mode . t)
> -(tab-width . 4)))
> +(tab-width . 4)
> + (lambda () (add-to-list 'write-file-functions 
> 'delete-trailing-whitespace)
>   (dsssl-mode . ((indent-tabs-mode . nil)))
>   (nxml-mode . ((indent-tabs-mode . nil)))
>   (perl-mode . ((perl-indent-level . 4)

dir-locals doesn't work this way.  It's not a general lisp file.

-- 
Peter Eisentraut  http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Teodor Sigaev

I use FileStly plugin to vim [1]. But I slightly modify it,  see in attachment.

FileStyle, sorry.

--
Teodor Sigaev   E-mail: teo...@sigaev.ru
   WWW: http://www.sigaev.ru/



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Teodor Sigaev

I once tried to have vim highlight trailing whitespace, spaces before
tabs, and overlength lines (>80 chars), and while I could do each thing
in isolation, I wasn't able to get it to highlight the three of them at
the same time.  If you have a recipe for that, I welcome it.


I use FileStly plugin to vim [1]. But I slightly modify it,  see in attachment.
And addition in .vimrc:

if expand('%:e') == "c" ||  expand('%:e') == "h" || expand('%:e')  == "cpp" || 
expand('%:e')  == "m" || expand('%:e') == "hpp" || expand('%:e') == "pl" || 
expand('%:e') == "pm" ||  expand('%:e') == "y" ||  expand('%:e') == "l"

else
let g:filestyle_plugin = 1
endif


[1]  https://www.vim.org/scripts/script.php?script_id=5065
--
Teodor Sigaev   E-mail: teo...@sigaev.ru
   WWW: http://www.sigaev.ru/
"   Copyright 2014 Alexander Serebryakov
"
"   Licensed under the Apache License, Version 2.0 (the "License");
"   you may not use this file except in compliance with the License.
"   You may obtain a copy of the License at
"
"   http://www.apache.org/licenses/LICENSE-2.0
"
"   Unless required by applicable law or agreed to in writing, software
"   distributed under the License is distributed on an "AS IS" BASIS,
"   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
"   See the License for the specific language governing permissions and
"   limitations under the License.

"Plugin checking the file to follow Your Vim settings

if !exists('g:filestyle_plugin')
  let g:filestyle_plugin = 1

  highligh FileStyleTabsError ctermbg=Red guibg=Red
  highligh FileStyleTrailngSpacesError ctermbg=Cyan guibg=Cyan
  highligh FileStyleSpacesError ctermbg=Yellow guibg=Yellow
  highligh FileStyleTooLongLine cterm=inverse gui=inverse

  "Defining auto commands
  augroup filestyle_auto_commands
autocmd!
autocmd BufReadPost,BufNewFile * call FileStyleActivate()
autocmd FileType * call FileStyleCheckFiletype()
autocmd WinEnter * call FileStyleCheck()
  augroup end

  "Defining plugin commands
  command! FileStyleActivate call FileStyleActivate()
  command! FileStyleDeactivate call FileStyleDeactivate()
  command! FileStyleCheck call FileStyleCheck()

endif


"Turn plugin on
function FileStyleActivate()
  let b:filestyle_active = 1
  call FileStyleCheck()
endfunction


"Turn plugin off
function FileStyleDeactivate()
  let b:filestyle_active = 0
  call clearmatches()
endfunction


"Check filetype to handle specific cases
function FileStyleCheckFiletype()
  "Avoid checking of help files
  if =='help'
call FileStyleDeactivate()
  endif
endfunction


"Highlighting specified pattern
function FileStyleHighlightPattern(highlight)
  call matchadd(a:highlight['highlight'], a:highlight['pattern'])
endfunction


"Checking expandtab option
function FileStyleExpandtabCheck()
  if 
let l:highlight = {'highlight' : 'FileStyleTabsError',
 \ 'pattern': '\t\+'}
  else
let l:highlight = {'highlight' : 'FileStyleSpacesError',
 \ 'pattern': '^\t* \{'.',\}'}
  endif
  call FileStyleHighlightPattern(l:highlight)
endfunction


"Checking trailing spaces
function FileStyleTrailingSpaces()
let l:highlight = {'highlight' : 'FileStyleTrailngSpacesError',
 \ 'pattern': '\s\+$'}
  call FileStyleHighlightPattern(l:highlight)
endfunction

"Checking inner spaces
function FileStyleInnerSpaces()
let l:highlight = {'highlight' : 'FileStyleTabsError',
 \ 'pattern': '\ \+\t'}
  call FileStyleHighlightPattern(l:highlight)
endfunction

function FileStyleAllInnerSpaces()
let l:highlight = {'highlight' : 'FileStyleTabsError',
 \ 'pattern': '\ \{4,\}'}
  call FileStyleHighlightPattern(l:highlight)
endfunction


"Checking long lines
function FileStyleLongLines()
  if  > 0
let l:highlight = {'highlight' : 'FileStyleTooLongLine',
 \ 'pattern': '\%' . (+1) . 'v.*' }
call FileStyleHighlightPattern(l:highlight)
  endif
endfunction


"Checking file dependenly on settings
function FileStyleCheck()
  if b:filestyle_active == 1
call clearmatches()
call FileStyleExpandtabCheck()
call FileStyleTrailingSpaces()
call FileStyleInnerSpaces()
call FileStyleAllInnerSpaces()
call FileStyleLongLines()
  endif
endfunction



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread David Fetter
On Tue, Jun 05, 2018 at 01:28:54PM -0400, Alvaro Herrera wrote:
> On 2018-Jun-05, David Fetter wrote:
> Hi David
> 
> > Here's my attempt to $subject. I've tested with vim, but I'm much less
> > certain I got the EMACS code right.
> > 
> > Is there any interest in such a feature?
> 
> I'd rather have the editor warn me (highlight) such things rather than
> fix them silently (I wonder if it'd cause a mess with regression .out
> files for example, which I do edit on occasion).

For what it's worth, the patch trims trailing whitespace only on
certain types of files in vim and just one (C) in emacs for just this
reason.

> I once tried to have vim highlight trailing whitespace, spaces before
> tabs, and overlength lines (>80 chars), and while I could do each thing
> in isolation, I wasn't able to get it to highlight the three of them at
> the same time.  If you have a recipe for that, I welcome it.

In vim, one way to do it is:

highlight link sensibleWhitespaceError Error
autocmd Syntax * syntax match sensibleWhitespaceError excludenl /\s\+\%#\@ http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!
Consider donating to Postgres: http://www.postgresql.org/about/donate



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Tom Lane
Alvaro Herrera  writes:
> On 2018-Jun-05, David Fetter wrote:
>> Is there any interest in such a feature?

> I'd rather have the editor warn me (highlight) such things rather than
> fix them silently (I wonder if it'd cause a mess with regression .out
> files for example, which I do edit on occasion).

Yeah, agreed.  FWIW, I'm not that fussed about this for .h/.c files,
since pgindent will fix it sooner or later (or even right away, if the
committer is anal enough to pgindent before committing, as some of us
are).  It's a bit more of a problem for other file types.

I note that Peter E. seems to have a recipe for finding such issues,
which I suspect is grounded in some obscure git feature or other.
That might be easier to work with, since you'd only need one fix
not one per editor.

regards, tom lane



Re: [PATCH] Trim trailing whitespace in vim and emacs

2018-06-05 Thread Alvaro Herrera
On 2018-Jun-05, David Fetter wrote:

Hi David

> Here's my attempt to $subject. I've tested with vim, but I'm much less
> certain I got the EMACS code right.
> 
> Is there any interest in such a feature?

I'd rather have the editor warn me (highlight) such things rather than
fix them silently (I wonder if it'd cause a mess with regression .out
files for example, which I do edit on occasion).

I once tried to have vim highlight trailing whitespace, spaces before
tabs, and overlength lines (>80 chars), and while I could do each thing
in isolation, I wasn't able to get it to highlight the three of them at
the same time.  If you have a recipe for that, I welcome it.

-- 
Álvaro Herrerahttps://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services