-
Notifications
You must be signed in to change notification settings - Fork 53
Enhancement: automatic vim no TAB configuration for all calc source except makefiles #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
If I don't reply to this tomorrow please remind me. I can't do anything with it today but I should be able to tomorrow though I hope to work more on the html files 'over there'. |
Question for you Landon: how do you want me to prioritise this along with the IOCCC ? As you know I am making good progress with that top priority issue but I still have a ways to go. I have to look at this issue more thoroughly tomorrow but depending on how you answer this question I will try and figure out how to process both issues. Of course the other issue I already know well but hopefully tomorrow I will have enough energy to parse this issue too. I will ask any questions if I come across anything that is unclear but as always I am happy to help where I can! ... and with that I will bid you a good night! |
Okay I quickly read the top comment and it seems good to me. The question is how do you want me to present any solution? An example portion of the .vimrc file maybe? Without looking at it I think this can be done relatively quickly but as always there might be something that comes up or that I haven't thought of or something else. The above question about prioritising this with the IOCCC also still stands of course. Going to bed now. Good night! |
Caveat about usage belowOkay this long command can list the files not excluded in your list of files to exclude. It seems it might be possible to use with find /usr/local/src/bin/calc -name '.git' -prune -o -name '.github' -prune -o \( ! -name Makefile ! -name Makefile.config ! -name Makefile.local ! -name Makefile.target ! -path cal/Makefile ! -path cscript/Makefile ! -path custom/Makefile ! -path help/Makefile ! -name rpm.mk \) and knowing you I would not be surprised if you have a more efficient way. But the purpose of course is to find a list of files to act on and which to not act on. [0] Otherwise you have to maintain a long list which might or might not be more efficient with vim but I can't say for sure. Another way of course is to set the defaults you want and then change the settings for the files that match but the way I'm pondering will just set the settings you need on those files. CaveatOf course you might not want to use shell commands. I also do not know if a certain setting (you know what I mean but I can't think of the name) that will prevent shell commands will cause this to fail or not. I would not be surprised if it did fail. Anyway this is a work in progress and might be called a workaround for the fact that you can have new files added etc. |
Okay doing something like the below in the .vimrc (with removed extraneous let exclude_files = glob("`find /usr/local/src/bin/calc -name '.git' -prune -o -name '.github' -prune -o ! -name Makefile ! -name Makefile.config ! -name Makefile.local ! -name Makefile.target ! -path cal/Makefile ! -path cscript/Makefile ! -path custom/Makefile ! -path help/Makefile ! -name rpm.mk`") allows one to do: :echo exclude_files which gives a list of the files. The question is how to get that to work in the events. I'm not sure of that yet. |
I have discovered how to refer to variables but the problem is that it wants to list a character at a time. Again this is just playing with the events in a way I have never had to deal with it. But if you put this in your .vimrc you will see that it will take a few seconds to load the buffer. Then it will echo a character at a time: let exclude_files = glob("`find /usr/local/src/bin/calc -name '.git' -prune -o -name '.github' -prune -o ! -name Makefile ! -name Makefile.config ! -name Makefile.local ! -name Makefile.target ! -path cal/Makefile ! -path cscript/Makefile ! -path custom/Makefile ! -path help/Makefile ! -name rpm.mk`")
for file in exclude_files
echo file
endfor
Which might explain why: for file in exclude_files
autocmd! BufNewFile,BufWritePre,BufReadPre file setf shiftwidth=4
endfor does not work. Perhaps there is another way to loop by line but I do not know yet. I must go afk a while though .. will try later to see if I can figure it out. |
But doing: let exclude_files = [ glob("`find /usr/local/src/bin/calc -name '.git' -prune -o -name '.github' -prune -o ! -name Makefile ! -name Makefile.config ! -name Makefile.local ! -name Makefile.target ! -path cal/Makefile ! -path cscript/Makefile ! -path custom/Makefile ! -path help/Makefile ! -name rpm.mk`") ]
does allow one to see it a line at a time. The |
I have some thought that it might be just doing it as one string with a newline after each so that it appears to be different lines but isn't. Adding a Anyway I must be away for a while and not sure if I can return to this today but if not then tomorrow. I'd like to get some of the other repo worked on today too but I'm doubting I will. |
I just remembered that I have some other things I need to take care of today so I will very likely have to stop for the day. There has to be a way other than the way I thought of some weeks ago. I have thought of another possibility but it's much more of a hack. It might work but I will have to play with that another time if necessary. It involves the after loading of the .vimrc file feature. But even that is a very vague thought at this time and by that I mean the feature just popped into my head. But perhaps some of the above will give you some thoughts or perhaps you might be against generating a list of files entirely. I can see that also being the case in which case something else will have to be done. |
Possible solution depending on your preferenceIs it okay to have to manually update the list of files that you don't want these settings for? If that's okay then I have an idea that might work: along the lines of what I brought up some weeks ago. The long list would through a single glob have the settings set up and then the much smaller list would have the settings undone. If that would work then I think it would be a lot easier but you would have to update the smaller list if new files have to be added. -- Must leave for now and probably the day. Good luck with the infrastructure project! Depending on the answer to this question and how I come along with the other things I have to take care of today I might be able to do it but I guess we will see. Let me know. It might be a case where the manual set up way is simpler and more efficient. |
Yes. The list of files under |
That should make it easier. The next question is what do you want the settings to be for the excluded files? Should the settings be set to the default? Or do you have something else in mind? |
First to recapAs stated in the TODO at the top, these files under
For all other files under Initially calc source (with the exception of the above list of files) can be modified to replace ASCII TAB characters with the appropriate number of SPACE characters. Then when editing files under FYI: The new calc source will use 4 character intention, so pressing the TAB key should add spaces to the next 4-character "tab stop". Thus, if we understand " Use 4-space indents
"
:set shiftwidth=4
" Intelligently use the tab key for indentation instead of for inserting tab characters
"
:set smarttab
" Use space characters, never tab characters
"
:set expandtab
" Set tab stops to be different from the indentation width.
"
:set tabstop=8
" Reduce the chance of tab characters masquerading as proper indents.
"
:set softtabstop=0 Settings for the exception filesFor files under
For those files we suspect we need: " Set tabstop to 8
"
:set tabstop=8
" Set shiftwidth to 4
"
:set shiftwidth=4
" Let the key (in insert mode) insert tab characters (and possibly tabs)
"
:set softtabstop=4
" Make the tab key insert tab characters
"
:set noexpandtab
" Make the key (in insert mode) insert spaces or tabs to go to the next indent tabstop
" when cursor is at the beginning of a line with only preceding whitespace characters.
"
:set smarttab etc.We are open to further suggestions and corrections in regards to both |
This comment is I believe excellent and I believe I can come up with a .vimrc set of commands to solve the problem for you. I can't do it just yet but I should be able to in a little while. If that all goes well I hope that I can do a bit of work on the other repo today too but if not I should be able to return to it tomorrow. I do have a zoom call today and of course other things I have to do too but I hope that at least this issue will be resolved for you. But for now I must take care of some other things. Anyway this comment I am replying to is (at a quick glance with the phone) exactly what I need so thank you! I can actually already picture what has to be done I just have to be at the laptop to do it! |
Sorry .. I keep putting in the wrong output for each. Trying again and then hopefully will get it right. I'm having a frustrating day (not related to this). Hold please .. |
SolutionBased on your comment above, comment 2144322942, if you add to your .vimrc towards the bottom (making sure no other autocmds that might affect the settings come after this) it should solve the problem: if has("autocmd")
augroup calc
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/* set shiftwidth=4 smarttab expandtab tabstop=8 softtabstop=0
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/Makefile* set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/*/Makefile set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/rpm.mk set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
augroup END
endif
If you were to then edit one of the included files (e.g. :set softtabstop you should get But if you were to open say one of the Makefiles then :set softtabstop (san typos of course .. config should have no typos: tested it all) then you should get the expected should show That should solve the problem though again if I have mixed up the order of the description that's likely a mistake in writing out what will happen (but of course if you ever had to change it or if for some reason I messed up the order in the config you could swap them). And with that I hope to look at the other repo a bit and then go afk a while. I still am not sure what files I'll be looking at next. I was pondering whether looking at the entry html files might be better. But now I think on it I remembered that there are comments to reply to and I think I better reply first. Let me know if this solves your problem here though! It should but of course there might be other settings you need. The above as you can see shows how to confirm settings too. UPDATE 0Btw there are other events you can look at if necessary but I think I got the important ones (and maybe some that aren't necessary). Try: :help BufReadPre and scroll in the help for example. UPDATE 1I will keep the directory there and the vim settings in my system for a bit to make sure things are okay so that if I have to make any fixes I can test it easily without having to re-download or add the settings back in. But if you let me know that this is what you need I will then delete that directory and the settings from my .vimrc file. Let me know please and hopefully it's all you need! It should also give you the idea of how it works. I will now look at the comments in the other thread and then I might be able to do some work there. If not I should be able to tomorrow. I might add that I believe this week (it will be Thursday anyway) that I go back to the doctor post surgery (I imagine I would have to go back one more time but it's possible that this is the last time too) so that will eat away time to work on the IOCCC repo. If I work on the entry index.html files I guess it'll look and feel like more progress is made and it would give time to add to the other files (thus not checking the files a second time). I think I'll do that but we'll see. Anyway I have other things to do before my appointment too so I'm not sure how much of that I will get done today. Still hopefully this issue is at least resolved and I can focus on the other ones tomorrow. |
Made a fix above .. edited in comment. |
E149: Sorry, no help for ButBufReadPre Was there a typo on "ButBufReadPre" @xexyl ? |
Probably remove the But. Not sure how that got there. So make it BufReadPre. If that doesn't work I will reply tomorrow morning. |
So far, things look good. As yes, ":help BufReadPre" was helpful. We will now close this issue with our thanks, @xexyl |
Under macOS vim, the solution outlined in issuecomment-2145594040 works very well. Under Debian Linux vim, it also works well. Under RHEL vim, the settings for the various Makefiles do not work. We at the bottom of the our """"""""""""""""""""""""""""""""""""""""""""""
"""""""" On tabs and vim
""""""""""""""""""""""""""""""""""""""""""""""
" See: //stackoverflow.com/questions/1878974/redefine-tab-as-4-spaces
"
" tabstop
"
" The width of a hard tabstop measured in "spaces" -- effectively the
" (maximum) width of an actual tab character.
"
:set tabstop=8
"
" shiftwidth
"
" The size of an "indent". It's also measured in spaces, so if your
" code base indents with tab characters then you want shiftwidth to
" equal the number of tab characters times tabstop. This is also used
" by things like the =, > and < commands.
"
:set shiftwidth=4
"
" softtabstop
"
" Setting this to a non-zero value other than tabstop will make the
" tab key (in insert mode) insert a combination of spaces (and possibly
" tabs) to simulate tab stops at this width.
"
:set softtabstop=4
"
" expandtab
"
" Enabling this will make the tab key (in insert mode) insert spaces
" instead of tab characters. This also affects the behavior of the
" retab command.
"
:set noexpandtab
"
" smarttab
"
" Enabling this will make the tab key (in insert mode) insert spaces
" or tabs to go to the next indent of the next tabstop when the cursor
" is at the beginning of a line (i.e. the only preceding characters
" are whitespace).
"
:set smarttab
""""""""""""""""""""""""""""""""""""""""""""""
"""""""" Special calc settings for calc source that is NOT a Makefile or *.mk
""""""""
"""""""" see: https://github.com/lcn2/calc/issues/151#issuecomment-2145594040
""""""""
"""""""" To test, try and see if 0 is the answer:
""""""""
"""""""" :set softtabstop
""""""""
""""""""""""""""""""""""""""""""""""""""""""""
if has("autocmd")
augroup calc
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/* set shiftwidth=4 smarttab expandtab tabstop=8 softtabstop=0
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/Makefile* set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/*/Makefile set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/rpm.mk set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
augroup END
endif NOTE: We explicitly set various tab related files to a "default" before the We test using the following command: vi ~/.vimrc /usr/local/src/bin/calc/{calc.c,Makefile,help/sin,help/Makefile} While going thru the various files, we look at:
For macOS and Debian Linux vim, we see that
In all other cases Under RHEL vim, however,
while it is 4 for files outside of What is wrong is that the Makefiles under RHEL Linux vim, have Changing, under RHEL Linux, the order of files visited does not change the situation. This still has the same problem: vi /usr/local/src/bin/calc/{Makefile,help/Makefile} ~/.vimrc /usr/local/src/bin/calc/{calc.c,help/sin} NOTE: The macOS vim version is: VIM - Vi IMproved 9.0 (2022 Jun 28, compiled Apr 13 2024 12:28:29) The Debian vim version is: VIM - Vi IMproved 9.0 (2022 Jun 28, compiled May 04 2023 10:24:44) The RHEL vim version is: VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Feb 09 2023 00:00:00) Under RHEL vim, as an experiment, if we change if has("autocmd")
augroup calc
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/Makefile* set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/*/Makefile set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
autocmd! BufNewFile,BufWritePre,BufReadPre /usr/local/src/bin/calc/rpm.mk set tabstop=8 shiftwidth=4 softtabstop=4 noexpandtab smarttab
augroup END
endif We find that QUESTIONWhat is it, under RHEL vim, that causes lines such as:
set We can expli
A3E2
citly |
Perhaps you can share your entire .vimrc file and I can test it under rocky linux. Not sure if I will see the same behaviour but since it's RH maybe I will. I am replying with the GitHub app which makes it harder to look at the comments so I can't see the version but I do know that at least some RH systems are behind so to say. Maybe that's related but I don't know. But if you share the vimrc file I would be happy to do some testing tomorrow. If for some reason you don't want to share it here you can email it to me. Perhaps I don't need the full file but want to make sure that I have the same state. I am glad it works in the other systems at least. Must get some sleep now. Good night! Will reply here and at the other repos tomorrow morning most likely before I have to leave for the ENT (but if not it's in my city so I should not be gone for very long). .. one thought that might be completely unrelated but one should not need to have the autocmd groups. That was just to keep it kind of organised. You might not need the check of having the feature too. Anyway I will get back tomorrow. Have a great sleep! |
Here is the UPDATE 0This may be an important clue: When we remove the entire UPDATE 1This may be an important clue too: Even when we copy |
I wonder what would happen if you installed a later version of vim in RH. If it works then we might be able to guess that the problem is the version. I know for me with CentOS (more so than with Rocky Linux) there were a lot of things like that. But Rocky Linux also is behind in some packages. Its pandoc is behind which is one of the reasons I have to generate html files for the IOCCC with the laptop (probably it would be fine under fedora but you know about that situation). The same problem with flex and bison though that I think I was able to easily work out (it wasn't necessary but I wanted to test it). Anyway I will look at this in more detail tomorrow. If you can install a later version in RH that would be a good test. I can likewise test this issue with Rocky Linux and if the problem is there too then it is maybe the version. In that case the question is if there are any workaround. Okay I typed more than I expected but I will be going now. I see you attached the rc file. Thanks! Will look at it tomorrow. Is it possible to do the version test too ? Anyway good night! Hopefully we can work this out soon. Is that a test you can do? |
Given issuecomment-2224269696, perhaps there is some system wide "Makefile-like" setting that is overriding vim settings? We can explicitly set That may be a configuration issue that a vim version upgrade might not fix? UPDATE 0We can copy any calc Makefile to We can manually do UPDATE 1We installed version 9.1.550 on both macOS and RHEL9. It seems that was some default behaviors that changed from Vim8 to Vim9. Now the Here is the updated |
I wondered about it. So would it work with the older version without the And you closed this issue so should I concern myself further with this? Let me know and I'll go from there! I'll check your vimrc file just as I'm curious what you have. |
It did. But the behavior of vim8 had different consequences for files it detected as Makefiles that changes the defaults even when that That is why we have switched to compiling the latest vim (9.1.something) from the vim repo. The compile and install is fairly straightforward and now we have a consistent vim9 environment across all platforms.
Comments in the |
PLEASE SEE THE ASSUMPTIONS NEAR THE BOTTOM OF THIS COMMENT
TODO
Inspired by @pmetzger's comment-1939127107 we wish to replace ASCII TAB characters with ASCII SPACE charcters in calc source code as part of the process to plan for calc v3 as noted in issue #103. This issue is here to develop a
vim(1)
framework to allow this to happen automatically.Some hints at a solution were suggested by @xexyl in comment-2093121295. We have not tested this solution.
vim and calc
We need a framework where, when using the
vim(1)
editor on calc source, we have the following modes in effect:Assumption 0: use of vim
ASSUMPTION: This issue is focused on the use of vim(1) as the editor to manage to the calc source.
We are aware that they are other fine editors besides vim. Indeed, we have used other editors in the past such as:
On accession we DO still use some of the above editors from time to time today. Editors have their strengths and their mis-feature weaknesses. We intend no disrespect to other editors. This issue is focused on use of vim(1) for calc.
Assumption 1: using SPACE instead of TAB
ASSUMPTION: This issue assumes that the calc source will NOT USE THE TAB CHARACTER.
We know is a long standing Tabs versus Spaces debate.
If you wish to debate the issue of using the TAB character in calc source, PLEASE COMMENT UNDER issue #103 instead of this issue. This issue assumes that the calc source will not use TABS. In particular if you wish to object to using SPACE characters instead of TAB characters, please feel free to comment under issue #103 (see #103).
Assumption 2: Not using TABS applies to ONLY calc source
ASSUMPTION: We do NOT want to do this for all files everywhere, only files under the calc source directory.
For purposes of discussion, assume that the calc source directory resides under:
Assumption 3: Not enabling via a local directory
.vimrc
fileASSUMPTION: We will NOT enable the use of a
.vimrc
file within the calc source tree.We do NOT want to enable local directory
.vimrc
files in general as this is dangerous. Someone could provide a tarball with an evil.vimrc
that could do things likeautocmd BufEnter * :silent! !echo rm -rf stuff
.While it might be permissible to enable the
.vimrc
files for the specific directory, but that could also be dangerous as some patch could alter that local.vimrc
file and create similar problems.Assumption 4: vim solution will not not part of the calc source
ASSUMPTION: We are NOT trying to configure this for everyone who happens to have a copy of the calc source.
We really need to configure vim just for ourselves. While we can document HOW we configured
vim(1)
for editing calc in some someone else wants to do the same. So we don't see a need for this configuration be enforce on anyone who happens to have a copy of the calc source.It is our guess that the solution will involve editing our own private
~/.vimrc
file under our home directory AND / OR file(s) under the~/.vim/
directory.We plan to, as part of the calc build process, issue warnings if TAB characters are found in the source source where they should not be. Those warnings will not prevent calc from being compiled.
Assumption 5: automatic use for calc source
ASSUMPTION: We want the NO TAB CHARACTERS mode to be automatically enabled whenever we edit the calc source.
We do NOT want to have to remember to execute some magic vim command to set this stuff, before editing files under that directory, we and others are likely to forget to execute such a magic command. We want it to be automatic.
While we plan as part of our release process, to verify that calc source does NOT contain tab characters, while we are working on the calc source tree, we want
vim(1)
to automatically enable no TABS for the calc source directory (assume/usr/local/src/bin/calc
for the sake of discussion).Assumption 6: Some calc files will have TAB characters
ASSUMPTION: Some files WILL CONTAIN TAB characters, just not C source.
Files such as Makefiles need TAB characters for commands related to a make rule. While some make tools allow for whitespace indented Makefiles, others do not. Because intending with spaces is not portable across various make tools, calc makefiles WILL continue to use TAB characters.
Calc source has the following make relate files that WILL CONTAIN TAB characters:
There may be other exceptions in the calc source tree, but for now assume that all files other than the above list WILL NOT CONTAIN TAB characters.
The text was updated successfully, but these errors were encountered: