All of lore.kernel.org
 help / color / mirror / Atom feed
From: Felipe Contreras <felipe.contreras@gmail.com>
To: git@vger.kernel.org
Cc: 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>,
	Felipe Contreras <felipe.contreras@gmail.com>
Subject: [PATCH v2 1/2] Add project-wide .vimrc configuration
Date: Wed,  9 Dec 2020 00:55:36 -0600	[thread overview]
Message-ID: <20201209065537.48802-2-felipe.contreras@gmail.com> (raw)
In-Reply-To: <20201209065537.48802-1-felipe.contreras@gmail.com>

It's not efficient that everyone must set specific configurations in all
their ~/.vimrc files; we can have a project-wide .vimrc that everyone
can use.

There's different ways to load this configuration, for example with
vim-addon-local-vimrc [1], but we don't need much of the complexity of
these solutions.

Instead I created a simple loader that is in the contrib area, which can
be installed with:

  cp -aT contrib/vim ~/.vim/pack/plugins/start/git

Then, add the location of the Git repository to your ~/.vimrc:

  let g:gitvimrc_whitelist = [ expand('$HOME') . '/dev/git' ]

Then the project-wide configuration will be loaded, which sets the
correct filetype for the documentation, and also the default indentation
of c, sh, perl, and asciidoc files.

These default configurations can be overridden in the typical way (by
adding the corresponding file in ~/.vim/after/ftplugin).

We could add the vim modelines at the bottom of every file, like other
projects do, but this seems more sensible.

[1] https://github.com/MarcWeber/vim-addon-local-vimrc

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
---
 .vimrc                          | 22 ++++++++++++++++++++++
 contrib/vim/plugin/gitvimrc.vim | 21 +++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 .vimrc
 create mode 100644 contrib/vim/plugin/gitvimrc.vim

diff --git a/.vimrc b/.vimrc
new file mode 100644
index 0000000000..602c746477
--- /dev/null
+++ b/.vimrc
@@ -0,0 +1,22 @@
+" To make use of these configurations install the git plugin provided in
+" the contrib section:
+"
+"   cp -aT contrib/vim ~/.vim/pack/plugins/start/git
+"
+" Then whitelist the location of this directory to your ~/.vimrc:
+"
+"   let g:gitvimrc_whitelist = [ expand('$HOME') . '/dev/git' ]
+"
+" You can add multiple locations, or specify a regexp pattern.
+"
+
+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
+
+" 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'))
+  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
+    if (match(l:top, l:pattern) != -1)
+      let l:found = 1
+      break
+    endif
+  endfor
+  if !l:found | return | endif
+
+  exec 'source ' . fnameescape(l:file)
+endf
+
+call LoadGitVimrc()
-- 
2.29.2


  reply	other threads:[~2020-12-09  6:56 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 ` Felipe Contreras [this message]
2020-12-09  8:53   ` [PATCH v2 1/2] Add project-wide .vimrc configuration Christian Brabandt
2020-12-09 10:29     ` Felipe Contreras
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

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

  git send-email \
    --in-reply-to=20201209065537.48802-2-felipe.contreras@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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.