Professional Documents
Culture Documents
$MGW_GIT_REPO/env/setup.sh
With this sed script trailing whitespaces can be removed from the whole file. It is strongly recommended to do whitespace cleanups in a separate commit.
And not to mix them with functional changes.
With the script below you can remove all trailing empty lines from a file, then add only one newline at the end.
For multiple files for which you can formulate a find expression, you can run these in one run as:
find <path/to/search> -name <name pattern> -type f -print0 | xargs -0 sed -i -e :a -e '/^\n*$/{$d;N;};/\n$/ba'
find <path/to/search> -name <name pattern> -type f -print0 | xargs -0 sed -i -e '$a\'
Here are ways to replace tabs with spaces. Open the files in vim and execute the following command within it. Or run the sed script (note that the
indentation might go wrong).
OR
It is strongly adviced that the plain git pull is not used. Instead the local repo should be updated like this:
OR
This will rebase your changes to the tip and there will be no merge-commits.
If you need to remove tabs or trailing whitespaces from your previous commit then you need to do this:
eclipse
Please see this link.
emacs
Use whitespace-mode
On your .emacs file add the following:
; Tabs as spaces
(setq-default indent-tabs-mode nil)
(setq tab-width 4)
To mark characters that exceed the agreed-upon standard line length, you can add lines-tail to whitespace-style. Add the below example to ~/.
emacs and substitute 100 for whatever your actual rule is. Substitute the list whitespace-style with the actual whitespace style that you want. This is
just an example, the full list of things available in whitespace-style can be found here.
erlang-mode
If you are writing Erlang code, load erlang-mode which is included in the OTP distribution. This will enable syntax highlighting for Erlang as well as the
ability to automatically do correct and "official" Erlang indentation for you.
Add the snippets for the features you want into your ~/.emacs
Installation alternative 1:
Load it by putting the directory from OTP with erlang.el in your load-path.
Loading erlang-mode
Installation alternative 2:
Install erlang-mode using MELPA or your other favourite emacs package archive, with M-x package-install RET erlang-mode RET
This method requires that you have already set up one or more package archives and that you have refreshed the contents so that your emacs knows
which packages exist. If the command didn't work, try running M-x package-refresh-contents RET first, and then run package-install again.
; Add these lines to automatically use erlang-mode for .upg.src and .app.src files
(add-to-list 'auto-mode-alist '("\\.app\\.src\\'" . erlang-mode))
(add-to-list 'auto-mode-alist '("\\.upg\\.src\\'" . erlang-mode))
You can do cleanup of common whitespace errors, such as removing tabs and trailing whitespaces, automatically. See above under "use whitespace
mode" on how to remove trailing whitespaces automatically upon saving.
You can add the following snippet to replace all tabs with spaces and clean up all incorrect whitespaces, both leading and trailing, automatically upon
saving:
; Defines the function fix-whitespace-upon-saving which adds before-save hooks for whitespace-cleanup and
untabify to the local buffer.
(defun fix-whitespace-upon-saving ()
(add-hook 'before-save-hook 'whitespace-cleanup nil t)
(add-hook 'before-save-hook (lambda () (untabify (point-min) (point-max))) nil t))
This is added as an erlang-mode-hook which means that it will only be effective when editing in erlang-mode. You can keep it in your .emacs config file
without having to worry about Makefiles or .go files being untabified.
Keep in mind that this can cause big diffs when you change a file that already has a lot of incorrect whitespaces from people who didn't bother setting up
their editors. You might want to invoke the functionality manually instead, in which case a good option could be to bind it to a shortcut.
; Defines the full-whitespace-cleanup function and binds it to the keyboard shortcut C-c C-g C-f
(defun full-whitespace-cleanup ()
(interactive)
(whitespace-cleanup)
(untabify (point-min) (point-max)))
nedit
$HOME/.nedit/nedit.rc
! some default the ruled in some projects, use your own settings
nedit.emulateTabs: 2
vim
Lines to add to your .vimrc file:
" 4 spaces indentation, no tabs
set tabstop=4
set shiftwidth=4
set expandtab