From patchwork Wed Nov 11 16:02:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Peter_M=C3=BCller?= X-Patchwork-Id: 3660 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4CWTz83t5Fz3wl4 for ; Wed, 11 Nov 2020 16:03:00 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4CWTz81yypzD3; Wed, 11 Nov 2020 16:03:00 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4CWTz80YZrz2yf7; Wed, 11 Nov 2020 16:03:00 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4CWTz73p0Mz2xhb; Wed, 11 Nov 2020 16:02:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4CWTz54vpgzD3; Wed, 11 Nov 2020 16:02:57 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1605110578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nhmLcZuh2N2o4v0ueVuCVLI7uDmTkT1lGZxaT0m5hDI=; b=m3UXIcOcqeN9CoEduAItJtSGUQsMZ3pesnHZFD/tG4B05p97es//w2XQfXKwUVasGuPFjN 5rOJzQJNuUCDXRAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1605110578; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nhmLcZuh2N2o4v0ueVuCVLI7uDmTkT1lGZxaT0m5hDI=; b=OEq9nLVFFdEbABpR5TCFYlVkQjhz8kWyApqtiC71aPNmttk8UfjD7qrxOgB4cUwaGVbesn XCJgkAeawa6+6oBpMMR05OnK9KMs8lGjfD0+hQ1qJPrXuCiova5jgMGq8MqNoROIAne/bS SP65hRFTKPjVKHcPVPjOeMpCp3Ny6pEyjQFDWegfVXAYDJ1syKi7qJWMQfnvOMrSDyDC5z W1jamSxsbEryDd8K+fFpnqkIkeH/hw1Bxw3AIsg5mLF7nbZVP4Kzi7N/ji6h21gfxal8Y4 ItGSU33TPocZhrWf0yicVZqNiUZlfqihKna5j+GgUA5axIJqpUP608NLavZuhg== To: "IPFire: Infrastructure-List" From: =?utf-8?q?Peter_M=C3=BCller?= Subject: [PATCH] brutally tell ignorant Vim not to indent Python scripts with spaces Message-ID: Date: Wed, 11 Nov 2020 17:02:55 +0100 MIME-Version: 1.0 Content-Language: en-US X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "IPFire: Development-List" Errors-To: development-bounces@lists.ipfire.org Sender: "Development" This patch brutally overwrites the default vimrc file located at /usr/share/vim/vim81/defaults.vim (at the time of writing) in order to tell Vim it must not indent Python scripts with spaces. Since we have agreed on indenting Python scripts with tabs (the PEP8 standard does not give a very plausible explanation why spaces are better than tabs, anyway - but hey, those are the experts [tm], and who are we to question their decisions?!), the auto-indention of Vim has been an ongoing nuisance: Instead of even trying to be smart and checking the indention type of the source code lines before, it just expands tabs to spaces by default, rendering Python scripts with tabulators as indention unusable as soon as any additional line is inserted. Ultimately, using nano as a quick workaround "solved" the problem, but makes developing a pain in the ass deluxe. Vim is probably the most arrogant and ignorant editor ever written. It is even worse than proprietary/commercial products such as IDEs by M$, and that's saying something. (I mean, if a user is pressing a certain key on his/her/its keyboard, who could have _thought_ of the possibility that this user actually _wanted_ to consciously press this key and have its output on the screen. Assisted programming comes to mind; using computers as tools is one thing, letting them do the thinking is another... :-/ ) Of course, one could disable expanding tabs into spaces by setting up a custom ~/.vimrc file, but this causes Vim to ignore _any_ other directives as well, which means there is no syntax highlighting anymore, matching brackets are not marked as such, and we are basically sitting in front of an machine behaving like one of its colleagues in the 80s. Some smart people came up with the idea of system-wide files such as /etc/ssh/ssh_config, or /etc/vim/vimrc, respectively. It even contains statements for including a _custom_ vimrc at /etc/vim/vimrc.local, which is exactly what we want to do. However, Vim reads its configuration from /usr/share/vim/vimrc, which is not simply a symlink to /etc/vim/vimrc or vice versa (that would be too easy, wouldn't it - why not spreading the same content twice across a system to bloat up things a little bit, eh?), and jumps into a Debian-specific configuration file afterwards. As soon as any custom directive is placed in /etc/vim/vimrc.local and Vim is told not to overwrite it, we are dealing with the same less-than-default configuration mentioned above. This leaves us with the decision of (a) either copying the entire content of /usr/share/vim/vim81/defaults.vim to _every_ users home directory, creating boiler plate configuration en masse or (b) tamper with files managed by the systems' packaging tool, which means we are damaging the integrity of our machines (did anyone mentioned security here?!), for nothing except a simple change to the Python indention plugin behaviour at all. In the authors opinion, (b) is the least unfavourable option. This patch finally "solves" the unwanted Vim behaviour on our machines, hopefully making Michaels and my lives a little bit less harassed, since we need to puke into one less front yard of another development team all the time. Cc: Michael Tremer Signed-off-by: Peter Müller --- files/usr/share/vim/vim81/defaults.vim | 143 +++++++++++++++++++++++++ 1 file changed, 143 insertions(+) create mode 100644 files/usr/share/vim/vim81/defaults.vim diff --git a/files/usr/share/vim/vim81/defaults.vim b/files/usr/share/vim/vim81/defaults.vim new file mode 100644 index 0000000..100cf12 --- /dev/null +++ b/files/usr/share/vim/vim81/defaults.vim @@ -0,0 +1,143 @@ +" The default vimrc file. +" +" Maintainer: Bram Moolenaar +" Last change: 2019 Feb 18 +" +" This is loaded if no vimrc file was found. +" Except when Vim is run with "-u NONE" or "-C". +" Individual settings can be reverted with ":set option&". +" Other commands can be reverted as mentioned below. + +" When started as "evim", evim.vim will already have done these settings. +if v:progname =~? "evim" + finish +endif + +" Bail out if something that ran earlier, e.g. a system wide vimrc, does not +" want Vim to use these default values. +if exists('skip_defaults_vim') + finish +endif + +" Use Vim settings, rather than Vi settings (much better!). +" This must be first, because it changes other options as a side effect. +" Avoid side effects when it was already reset. +if &compatible + set nocompatible +endif + +" When the +eval feature is missing, the set command above will be skipped. +" Use a trick to reset compatible only when the +eval feature is missing. +silent! while 0 + set nocompatible +silent! endwhile + +" Allow backspacing over everything in insert mode. +set backspace=indent,eol,start + +set history=200 " keep 200 lines of command line history +set ruler " show the cursor position all the time +set showcmd " display incomplete commands +set wildmenu " display completion matches in a status line + +set ttimeout " time out for key codes +set ttimeoutlen=100 " wait up to 100ms after Esc for special key + +" Show @@@ in the last line if it is truncated. +set display=truncate + +" Show a few lines of context around the cursor. Note that this makes the +" text scroll if you mouse-click near the start or end of the window. +set scrolloff=5 + +" Do incremental searching when it's possible to timeout. +if has('reltime') + set incsearch +endif + +" Do not recognize octal numbers for Ctrl-A and Ctrl-X, most users find it +" confusing. +set nrformats-=octal + +" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries. +if has('win32') + set guioptions-=t +endif + +" Don't use Ex mode, use Q for formatting. +" Revert with ":unmap Q". +map Q gq + +" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo, +" so that you can undo CTRL-U after inserting a line break. +" Revert with ":iunmap ". +inoremap u + +" In many terminal emulators the mouse works just fine. By enabling it you +" can position the cursor, Visually select and scroll with the mouse. +if has('mouse') + set mouse=a +endif + +" Switch syntax highlighting on when the terminal has colors or when using the +" GUI (which always has colors). +if &t_Co > 2 || has("gui_running") + " Revert with ":syntax off". + syntax on + + " I like highlighting strings inside C comments. + " Revert with ":unlet c_comment_strings". + let c_comment_strings=1 +endif + +" Only do this part when Vim was compiled with the +eval feature. +if 1 + + " Enable file type detection. + " Use the default filetype settings, so that mail gets 'tw' set to 72, + " 'cindent' is on in C files, etc. + " Also load indent files, to automatically do language-dependent indenting. + " Revert with ":filetype off". + filetype plugin indent on + + " Put these in an autocmd group, so that you can revert them with: + " ":augroup vimStartup | au! | augroup END" + augroup vimStartup + au! + + " When editing a file, always jump to the last known cursor position. + " Don't do it when the position is invalid, when inside an event handler + " (happens when dropping a file on gvim) and for a commit message (it's + " likely a different one than last time). + autocmd BufReadPost * + \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit' + \ | exe "normal! g`\"" + \ | endif + + augroup END + +endif + +" Convenient command to see the difference between the current buffer and the +" file it was loaded from, thus the changes you made. +" Only define it when not defined already. +" Revert with: ":delcommand DiffOrig". +if !exists(":DiffOrig") + command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis + \ | wincmd p | diffthis +endif + +if has('langmap') && exists('+langremap') + " Prevent that the langmap option applies to characters that result from a + " mapping. If set (default), this may break plugins (but it's backward + " compatible). + set nolangremap +endif + +" Tell vim not to indent Python scripts with spaces, without +" (a) forgetting anything else (happens if we use a custom .vimrc, but hey!) +" (b) overriding system-wide vimrc files such as /etc/vim/vimrc.local +" (those are _system-wide_, so why should an application care about it?!) +" (c) be too invasive when it comes to patch indention files for Python itself +autocmd FileType python setlocal expandtab! tabstop=8 shiftwidth=8 softtabstop=0 +