git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: Felipe Contreras <felipe.contreras@gmail.com>,
	Git <git@vger.kernel.org>, Junio C Hamano <gitster@pobox.com>,
	Jeff King <peff@peff.net>,
	Emily Shaffer <emilyshaffer@google.com>,
	"Brian M. Carlson" <sandals@crustytoothpaste.net>,
	Aaron Schrab <aaron@schrab.com>,
	Denton Liu <liu.denton@gmail.com>,
	Christian Couder <christian.couder@gmail.com>
Subject: Re: [PATCH v2 1/2] Add project-wide .vimrc configuration
Date: Wed, 9 Dec 2020 04:29:25 -0600	[thread overview]
Message-ID: <CAMP44s18FMyJoHogud3QjWGya_9bAB7yAaYUb1aTQ12fYUTNxw@mail.gmail.com> (raw)
In-Reply-To: <20201209085356.GJ22416@256bit.org>

Hello,

On Wed, Dec 9, 2020 at 2:54 AM Christian Brabandt <cb@256bit.org> wrote:

> Felipe Contreras schrieb am Mittwoch, den 09. Dezember 2020:
>
> > +augroup git
> > +     au BufRead,BufNewFile */Documentation/*.txt set filetype=asciidoc
> > +
> > +     au FileType c setl noexpandtab tabstop=8 shiftwidth=0 cino=(s,:0,l1,t0
> > +     au FileType sh setl noexpandtab tabstop=8 shiftwidth=0
> > +     au FileType perl setl noexpandtab tabstop=8 shiftwidth=0
> > +     au FileType asciidoc setl noexpandtab tabstop=8 shiftwidth=0 autoindent
> > +augroup END
>
> This will set filetype specific options. So after this file has been
> loaded, it will set e.g. set tabstop and shiftwidth options for
> filetypes outside of the git project.
>
> Shouldn't this only apply to files inside the git code repository?

Yes. But this file can only be loaded if your cwd is inside this
repository. That is; if "git rev-parse --show-toplevel" shows the same
directory as this file.

> > +
> > +" vim: noexpandtab tabstop=8 shiftwidth=0
> > diff --git a/contrib/vim/plugin/gitvimrc.vim b/contrib/vim/plugin/gitvimrc.vim
> > new file mode 100644
> > index 0000000000..c3946e5410
> > --- /dev/null
> > +++ b/contrib/vim/plugin/gitvimrc.vim
> > @@ -0,0 +1,21 @@
> > +let s:gitvimrc_whitelist = get(g:, 'gitvimrc_whitelist', [])
> > +
> > +function LoadGitVimrc()
> > +  let l:top = trim(system('git rev-parse --show-toplevel'))
>
> trim needs at least vim 8.0.1630. Is this recent enough?

2018? I think that's good enough. If not I'd be happy to include any
other suggestion.

> Could also use
> systemlist()[0] which is available starting at vim 7.4.248 or just a
> simple split(system(), "\n")[0] which should be compatible with vim 7.

Yeah, in Linux. Will that work in Windows where carriage returns are "\r\n"?

> > +  if l:top == '' | return | endif
> > +  let l:file = l:top . '/.vimrc'
> > +  if !filereadable(l:file) | return | endif
> > +
> > +  let l:found = 0
> > +  for l:pattern in s:gitvimrc_whitelist
>
> You could directly use `get(g:, 'gitvimrc_whitelist', [])` directly, so
> the script local var s:gitvimrc_whitelist is not really needed.

True. It's just a force of habit to copy the global scope to the
script scope. That being said; the "for" would call the get() function
multiple times (probably). So I'm not entirely sure what is being
gained.

> > +    if (match(l:top, l:pattern) != -1)
>
> This uses a regex match. Perhaps do a string comparsion? If this is
> needed, consider adding "\C" to force matching case and perhaps also \V
> to force a literal match. Otherwise the options magic, ignorecase,
> smartcase etc are applied to the matching.

This was straight-up copied from another solution. I just checked :h
match() and didn't find any low-hanging fruit.

If you have a better proposal just type it out. I'm not overly
familiar with vimscript, I just know the above works.

> > +      let l:found = 1
> > +      break
> > +    endif
> > +  endfor
> > +  if !l:found | return | endif
> > +
> > +  exec 'source ' . fnameescape(l:file)
> > +endf
> > +
> > +call LoadGitVimrc()
>
> On the style: I personally dislike the `l:` prefix for function local
> variables, as this does not add anything. But perhaps this is just my
> personal preference.

I don't mind either way. I just add it for consistency since the
syntax sometimes doesn't identify such variables (e.g "if !found"),
but most of the time the syntax doesn't do it either way (which is
odd).

So just s/l:// ?

Cheers.

-- 
Felipe Contreras

  reply	other threads:[~2020-12-09 10:35 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-09  6:55 [PATCH v2 0/2] vim: configuration and sharness syntax Felipe Contreras
2020-12-09  6:55 ` [PATCH v2 1/2] Add project-wide .vimrc configuration Felipe Contreras
2020-12-09  8:53   ` Christian Brabandt
2020-12-09 10:29     ` Felipe Contreras [this message]
2020-12-09 10:45       ` Christian Brabandt
2020-12-09 17:27   ` Jeff King
2020-12-10  1:55     ` Felipe Contreras
2020-12-10 15:27       ` Jeff King
2020-12-11  0:43         ` Felipe Contreras
2020-12-10  3:50   ` brian m. carlson
2020-12-11  1:08     ` Felipe Contreras
2020-12-11  2:56       ` brian m. carlson
2020-12-11  4:37         ` Felipe Contreras
2020-12-15  1:39         ` Jeff King
2020-12-15  3:03           ` Felipe Contreras
2020-12-15  5:28             ` Jeff King
2020-12-15  6:56               ` Felipe Contreras
2020-12-09  6:55 ` [PATCH v2 2/2] contrib: vim: add sharness syntax file Felipe Contreras
2020-12-09  7:05   ` Eric Sunshine
2020-12-09 10:39     ` Felipe Contreras
2020-12-09 17:11 ` [PATCH v2 0/2] vim: configuration and sharness syntax Jeff King
2020-12-10  3:25   ` Felipe Contreras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMP44s18FMyJoHogud3QjWGya_9bAB7yAaYUb1aTQ12fYUTNxw@mail.gmail.com \
    --to=felipe.contreras@gmail.com \
    --cc=aaron@schrab.com \
    --cc=christian.couder@gmail.com \
    --cc=emilyshaffer@google.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=liu.denton@gmail.com \
    --cc=peff@peff.net \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).