Dymola, whitespace and version control - tortoisesvn

I opened a Modelica library in Dymola, changed one line, closed Dymola and clicked "Save all", now TortoiseSVN is showing several hundred changed files instead of just one file with the one line changed I intended to do. All these changes are either whitespace, or line breaks, introduced by Dymola it seems.
Of course I can now be careful to only commit the file I have changed (and revert the rest), but that makes committing more time-consuming and error-prone than it needs to be. Or I can just commit it all, but that makes it hard for my colleagues to review the change. Also, it feels like it is not deterministic, so a later commit might just revert parts back. I sometimes even revert all changes, then use a text editor to change just the one line. All this makes version control unnecessarily complicated.
When I look at the commits and diffs for e.g. the Modelica Standard library:
https://github.com/modelica/ModelicaStandardLibrary/commits/master
The diffs are nice and small and readable usually. Is there a trick to avoid the whitespace issue?
How I can I turn off all autoformatting by Dymola? Is there a technical reason to do it in the first place?

You can reduce (but not entirely prevent) this behavior as follows:
Increase the maximum line length, e.g. to 130
In the GUI: Options > Text Editor > Max line length
From the command line: Advanced.MaxLineLength=130
Let Dymola format your whole library one time
Open the text view of the top-level package
Mark everything with Ctrl+A
Auto-format with Ctrl+Shift+L or Right-Click > Auto-Format
Save everything with Ctrl+Shift+S
Now go through the changes. Most will be useful, but sometimes spaces are removed, which you usually like to keep (especially before import and extends statements. They are sometimes moved to the very left)
Commit the changes
From now on try to save individual models only, not packages
(When packages are saved, Dymola sometimes reformats the nested classes)

There are some things you can do to make pretty git commits for Modelica code:
Use a text editor instead of a graphical editor. You have absolute control of what you change.
Use a graphical editor that does not change whitespace. I'm not sure of other alternatives, but OpenModelica/OMEdit will preserve existing indentation as much as possible (it can also be used to minimize diffs from changes in other tools, but it works less and less well the more changes there are).
Use a formatter as a pre-commit hook (indenting all files according to some settings in the formatter; but then you can't manually change whitespace).
Hope someone on stackoverflow has more alternatives than this.

Related

set tab-stop = 2 in vim permanently for a file

How to set the tab size as 2 for a file permanently in vim as whenever I open a file in other editors like nano or upload the file in github then my indentations are all incorrent whenever I try to resize the tab to 2 for an existing file which has all incorrect indentations. The tab-stop=2 does not permanently resizes the tab and I see all incorrect indentation when I open the same file in nano or view it in github.
Tabs don't have an inherent size so it is up to each program to decide how to display them and there is simply no way to guarantee that a tab will always look the same everywhere.
This is precisely the main issue people have with tabs: you can tell $SOME_TOOL and $SOME_OTHER_TOOL that a tab takes two spaces but that setting can't possibly be carried over to every tool.
Modelines are editor-specific (and they are too intrusive anyway) and Editorconfig is not universally supported so there is really no universal solution beyond using spaces for indentation.

Unwanted text appears every time I close a bracket in VIM using VimTex

I am typesetting a latex file in VIM using the Vimtex plugin.
Every time I close a bracket, this text shows up automatically in the <++>.
For example:
\section{This is one}<++>
\section{The variable $V_L$<++> explains things}<++>
\begin{equation}
<+content+>
\label{<+label+>}
\end{equation}<++>
LaTeX compiles my text with those printed out in the pdf so I have to manually remove the every time. This behavior goes from $$ to {} to others also and even inside certain areas when using autocompletion features wit F5.
I did look add this question but it did not provide much help as to how to solve my issue.
How can I prevent the from being added to my tex files?
If they are a feature meant for something I do not understand, how do I prevent them from compiling in my pdf's?
This part of the documentation on the vim-latex (not Vimtex) repo on github
explains how the macro system works, how it's useful and solely meant for editing
NOTE: Place Holders
-------------
Almost all macros provided in Latex-Suite implement Stephen Riem's
bracketing system and Gergely Kontra's JumpFunc() for handling
place-holders. This consists of using "place-holders" to mark off
locations where the next relevant editing has to be done. As an example,
when you type EFI in |insert-mode|, you will get the following: >
\begin{figure}[<+htpb+>]
\centering
\includegraphics{<+file+>}
\caption{<+caption text+>}
\label{fig:<+label+>}
\end{figure}<++>
The text <+htpb+> will be selected and you will be left in |select-mode|
so that you can continue typing straight away. After having typed in the
placement specifier, you can press <Ctrl-J> (while still in insert-mode).
This will take you directly to the next "place-holder". i.e, <+file+> will
be visually selected with Vim in select mode again for typing in the file
aaaa. This saves on a lot of key presses.
Note: Upon testing I realized that the placeholder only appears when the bracketing is empty.

How do I configure Kate to automatically detect spaces/tabs indentation?

I mess with software written by completely unrelated groups of people, and it all uses completely different indentation standards. I'm okay with having to set the indentation width, but there's nothing more annoying than opening up a file with tabs, making some changes, and finding that my changes used spaces for indentation instead.
All the software I write uses four-space indentation. Then I go to make a Quake 3 mod and the entire codebase uses tabs. When I make changes I have to be incredibly careful to set my indentation settings first or I'm going to have to manually rewrite the indentation before committing, every single time.
I went through the settings and couldn't find anything. The tabs-and-spaces mode literally doesn't do anything special and just sets it to tabs mode instead (after a reset). I went through google and all I found was this extremely unhelpful mailing list message. Detecting consistent indentation isn't that difficult, other text editors manage it fine, it doesn't have to be perfect, it just has to work most of the time.
If Kate has a setting for this, where is it, and if it doesn't, when is it going to get such a setting? If I can't make Kate do this I'm going to have to switch off of it. I already went through Notepad++ and Geany, but they both have serious problems with doing regexes on extremely large files (say, tens of megabytes of text) or with rendering monospace non-european text.
Unfortunately, kate does not support this right now. There is a bug report for this from 2005, but noone implemented that yet (yes, 13 years ago).
What Kate does support though are Kate modeline (also called document variables). For instance, you can write in your text document e.g.:
// kate: replace-tabs on; indent-width 4;
And then the document containing this comment will automatically use 4 spaces and use spaces to indent.
Instead of writing these kind of comments into files, you can also write this into files called .kateconfig. You can find more information about .kateconfig files and modelines in this article.

Vim won't write file without a "!" sometimes (E13)

Very often (as in multiple times an hour), when I save my file :w, vim tells me "E13: File exists (add ! to override)"
I don't know why it does this, I can't reliably reproduce it, it feels random.
This is my vimrc, note that it sets nobackup, nowritebackup, and noswapfile, and there is a function to strip trailing whitespace that gets run when I save a file.
Also, I tend to have 20 vims open at once, all backgrounded, often editing the same file. Also not improbable that I have the same buffer open in multiple windows (ie :vsp) and might open it, then reopen it with the e command a lot, possibly from a relative filepath, or possibly from an absolute one (the cmap %/ <C-R>=expand("%:p:h")."/"<CR>). No idea if any of this matters. Next time I have this issue, I'll check my ls and report anything odd.
Update:
When I tried to save "lib/seeing_is_believing/wrap_expressions.rb" (note that this is a different file than the one in the gif), this happened again. Here is the ss, it's buffer 3:
Update2 (for #mMontu)
I just realized that there are two errors happening here. The one in the screenshot is the readonly thing. The one in the gif is the more common one, E13: File exists (add ! to override)
The one I just hit is E13 File exists, for this one, readonly is not set:
Update 3
I'm pretty sure the problem is the ZoomWin plugin. I had switched it up to a newer version, and it simply didn't work right. So I stopped using it for a bit, and didn't have this issue. Then switched it back, b/c I miss its functionality (it's my favourite vim plugin), and the problems started again. Possibly it's ZoomWin in conjunction with NerdTree window. Probably not the lib authors' faults, vim in general seems fragile and buggy. Maybe I'll try NeoVim, see if they've done a better job. Maybe it's time to try Atom or Emacs again.
It seems that if there were read errors opening the file, Vim will print an error on :w. This can be seen by running :f:
"MANIFEST.in" [Read errors] 1 line --100%--
The errors aren't necessarily errors in reading the contents of file; they can be caused by a plugin.
I think the main problem is that the file has been modified externally, see http://vim.wikia.com/wiki/Have_Vim_check_automatically_if_the_file_has_changed_externally to reload it whenever this happens

Vim editing *diff file*, updating diff ranges automatically

Suppose I generate diff of my project before commit, let say using svn. Having one diff for all files in project is a very nice way to review changes before committing them. However sometimes I wish to edit those changes without reopening each file, simple edit the diff and have it reapplied. So I have made such key map(I have setup svn diff to use unified format with fair amount of surrounding lines):
map scde :w! tmpdiff<cr>:!svn revert -R .<cr>:!patch -p0 <tmpdiff<cr>
It works, but only partially; you can edit added lines, but if you mark lines as removed or want to add another line you get some trouble since specified diff ranges do not match with actual text present in the diff. One can update them for simple changes like adding a line, however it is tedious and quickly gets complicated if you make more sophisticated changes. Is there a way to edit diff in so that range would automatically update correctly? I have found that emacs has some diff mode for this(however I have not tried it), however I was unable to find solution for my needs using vim. Maye there someone can give some suggestions?
take a look at rediff. It automatically fixes the offsets within a patch file.

Resources