Kate (text editor) indentation, c++ - c++

I use the kate text editor for writing c++ code. I really like the editor except for its indentation behavior which drives me mad. I have the following problem: If I want to write code like
if( true )
{
//code
}
the indentation messes everything up initially: instead of inserting a tab and jumping to the position marked "//code" when hitting enter, kate just inserts a single blank space. So to describe it more in detail: You start from
if( true )
{//your cursor is here
}
and on pressing enter, kate produces something like
if( true )
{
[ ]//your cursor is here
}
where '[ ]' stands for a single blank space. But instead, I want kate to insert a tabulator to give the result indicated at the start. Or, to repeat it more verbosely, I want that kate gives me
if( true )
{
<tabulator>//your cursor is here
}
on hitting enter. I have played around with all settings and can not make it work. It drives me crazy. I selected "default identation mode normal", "Ident using tabulators" (8 characters). Does anybody know how to customize this behavior? I looked up the katerc file but couldn't find any options that would help me...
edit: I should add that it would be ok if kate would just give me
if( true )
{
//your cursor is here
}
on pressing enter. But this additional blank space is absolutely annoying.

Ok, I tried for half an hour, I don't know why I found out how to do it right AFTER posting the question :). So in case anybody has the same issue, here is the "solution": I missed that kate seems to have a global setting for the indentation mode as well as a local one for every file. In my case - for some reason - my file had special indentation options set. You can alter them via the menu bar by chosing "Tools -> Indentation". This local option overrides the global one! Or the global one is just the default for the local options, I don't know exactly...

You can create a config file .kateconfig and add the variables kate: replace-tabs off; tab-indents: true;
More on this in the manual.

Related

Indentation after for instruction in xcode doesn't work

I've been using xcode for some months and this has never happened before, i'm not sure whether i pressed something i shouldn't have or meddled with the settings. Basically i write something like for(int i=1;i<=n;i++) and press enter, and the cursor is on the next line above the instruction, so there's no visual subordination of what I'm about to write next.
If i press the tab key before writing a new instruction below and then write for instance cout<<n-i<<endl;, the moment I press ; , the entire thing is moved in the same column(if that makes sense) again. This doesn't happen with other instructions like while or if. Help?
Normally indentation occurs when you open a block, as in type {. If you're using a blockless if then the code editor has to figure out after the fact what you're doing.
I'm not able to reproduce your problem, but here are a few tips :
To format a selection in the editor
Main menu : Editor > Structure > Re-indent ( or ^I )
To remove the automatic formatting when pressing ;
User Preferences : Text Editing > Automatic indent for : Uncheck the “;” box

Paranthesis closure in Geany for c++

After typing
int func(){
And pressing enter I'm getting like this , since I have enabled auto close plugin
int func(){
//cursor stays here }
But what i need is
int func(){
//cursor stays here
}
I'm able to achieve the required indentation by changing snippets.conf, but I have to press c and Tab, where
c=%brace_open%%cursor%%brace_close%
brace_open={\n\t
brace_close=\n}\n
Auto-close plugin settings:
is there any other way of achieving ?? Thanks in advance.
I haven't been able to figure out how to get exactly what you've indicated, but the Autoclose plugin can get close. Typing int func(){ and pressing Enter gives the following, where the | character represents the cursor location:
int func(){
|
}
EDIT:
My Autoclose settings are as shown below. But that turns out not to be the whole story. See after the image for more.
While looking into this some more, I discovered some strange behavior. I don't know if it's at the root of your problem or not, but it's maybe something to consider.
Autoclose worked as I described when pressing Enter on the main keyboard, but not when pressing Enter on the keypad, with or without NumLock enabled. In the latter case, I got the same result you did.
I normally use an antique IBM Model M keyboard, so to eliminate any chance of the problem being caused by the keyboard itself, I tried a modern USB keyboard with keypad. The results were exactly the same.
Having a suspicion as to what was happening, and since it's open source, I pulled down the Autoclose source code and took a look. And found...
static gboolean
auto_close_chars(
AutocloseUserData *data,
GdkEventKey *event)
{
...
else if (ch == GDK_Return)
{
return improve_indent(sci, editor, pos);
}
...
}
A general search for GDK_Return turned up gdkkeysyms.h that defines all of the GDK key codes. In that, there's GDK_Return and also GDK_KP_Enter, where "KP" means "keypad". Since Autoclose doesn't recognize GDK_KP_Enter, it'll fail to respond to pressing Enter on the keypad.
So, if you're using a full keyboard with keypad, it should work ok so long as Enter on the main keyboard is being used. On the other hand, If you're using a laptop where there's only one Enter key, all bets are off.
Check out https://plugins.geany.org/autoclose.html for autoclose plugin. This will solve your problem.
In Linux you can directly install it by
sudo apt-get install geany-plugin-autoclose

How do I change terminal display? Visual Code on Mac

When Running my code I really only want to display the code I'm working on. I don't want to display what seems to be the folder address. Is there a way to not display that?
I mean when im running my code. I want to see the answer to my code only so to just display
28
.... not the folder name desktop/cpp etc etc
I noticed you were having some trouble with VS-Code.
Here's a good list of commands which can complete your task.
I noticed you stated that you were on a Mac as well, so more than likely the CTRL + option won't be necessary; try the " ⌘ + " instead!
To remove / hide the folder explorer window, simply hit "⌘ + b"
To remove / hide the terminal as well, try using "⌘ + `"
Edit:
I noticed you were also having some issues with the output of your code. The "addresses" to your output are symbols that ( usually ) address incorrect operations.
Try doing something like this when writing out your function:
printf( "i%\n" ); // <- Adding a newline to the operation deducts the symbol.
I hope this helps-

Opening code written in emacs on Xcode appears badly indented

This is my first post on stack overflow, so please forgive me for any mistakes.
I learned c++ with Xcode and recently started working with a group that uses Emacs. This group has a huge code in c++ and so I did a CMake interface to generate a project in Xcode. What happened is that the code appears badly indented in Xcode. For instance, these lines in emacs:
if ( argc > 4 ) {
std::string argument( argv[arg_index++] );
// NOTE: file_name should NOT be "aboveCrack" or "belowCrack"
if ( argument == "aboveCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EAboveSurface;
}
else if ( argument == "belowCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EBelowSurface;
}
else {
// argument 4 is comp. crack surface output name
got_file_name = true;
postCompSurface_file_name = argument;
}
}
if ( !got_file_name && argc > 5 ) {
got_file_name = true;
postCompSurface_file_name = argv[arg_index++];
if ( argc > 6 ) {
// get comp. crack surface output style
postCompSurface_style = argv[arg_index++];
}
}
Look like this in Xcode:
if ( argc > 4 ) {
std::string argument( argv[arg_index++] );
// NOTE: file_name should NOT be "aboveCrack" or "belowCrack"
if ( argument == "aboveCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EAboveSurface;
}
else if ( argument == "belowCrack" ) {
surf_to_draw = CrackMn3DGraphDX2::EBelowSurface;
}
else {
// argument 4 is comp. crack surface output name
got_file_name = true;
postCompSurface_file_name = argument;
}
}
if ( !got_file_name && argc > 5 ) {
got_file_name = true;
postCompSurface_file_name = argv[arg_index++];
if ( argc > 6 ) {
// get comp. crack surface output style
postCompSurface_style = argv[arg_index++];
}
}
Which is impossible to program with.
I searched and apparently it has something to do with the tabs in Emacs. Based on this, one fix I could find was to open each file in Emacs and do C-x h (mark all) followed by M-x untabify. This transforms the tabs in spaces and everything looks good in Xcode.
The problems with this idea are that it requires to change the files one by one and it won't stop this from happening again in the future.
Therefore, my question is: is there a way to open the Emacs indented files in Xcode preserving the indentation?
Many thanks!
Nathan Shauer
The first setting that you need to put in your .emacs is: (setq-default indent-tabs-mode nil). This will make sure emacs uses spaces instead of tabs for indentation.
Also, I created a tiny function:
(defun rag/untabify-buffer ()
;; get rid of all the tabs in a buffer
(interactive)
(untabify (point-min) (point-max))
nil)
Add this to before-save-hook and this will make sure all the files will be untabified when you make a change and save a file. Once you've untabified all files, you can remove the hook
No. While it is possible to use emacs to make these changes or even a number of other tools which can automate such changes, it won't really fix your problem as you will likely have to do it every time you check out the code from version control. Depending on the version control system used, it is also possible that doing such formatting changes will result in the code appearing to be modified, which will result in larger checkins and make other useful tools less useful because more will appear to have been changed than was actually changed. This will likely frustrate other project members.
There are two basic approaches, but one depends on the version control solution being used by the project. The first solution is to get the project to agree on a coding standard which specifies either that normal spaces must be used for indentation or that tabs are to be used. The problems you are seeing are primarily due to a mix. Emacs is able to handle this sort of mixed formatting quite well, but other editors, like Xcode are not so smart.
The other approach, which can work quite well because it doesn't rely on everyone following the standard is to configure the version control system to translate tabs as part of the checkin process into spaces. How this is done depends on the version control system being used.
Essentially, this is a problem which needs to be addressed at the project or version control level. Anything you do will only need to be repeated every time you do a fresh pull from version control for any files which have been modified. Fix it at the repository level and the issue will go away.

cursor blinking removal in terminal, how to?

I use the following lines to output my simulation's progress info in my c++ program,
double N=0;
double percent=0;
double total = 1000000;
for (int i; i<total; ++i)
{
percent = 100*i/total;
printf("\r[%6.4f%%]",percent);
}
It works fine!
But the problem is I see the terminal cursor keeps blinking cyclically through the numbers, this is very annoying, anyone knows how to get rid of this?
I've seen some programs like wget or ubuntu apt, they use progress bar or percentages too, but they seems no blinking cursor issue, I am wondering how did they do that?
Thanks!
You can hide and show the cursor using the DECTCEM (DEC text cursor enable mode) mode in DECSM and DECRM:
fputs("\e[?25l", stdout); /* hide the cursor */
fputs("\e[?25h", stdout); /* show the cursor */
Just a guess: try to use a proper number of '\b' (backspace) characters instead of '\r'.
== EDIT ==
I'm not a Linux shell wizard, but this may work:
system("setterm -cursor off");
// ...display percentages...
system("setterm -cursor on");
Don't forget to #include <cstdlib> or <iostream>.
One way to avoid a blinking cursor is (as suggested) to hide the cursor temporarily.
However, that is only part of the solution. Your program should also take this into account:
after hiding the cursor and modifying the screen, before showing the cursor again move it back to the original location.
hiding/showing the cursor only keeps the cursor from noticeably blinking when your updates take only a small amount of time. If you happened to mix this with some time-consuming process, your cursor will blink.
The suggested solution using setterm is not portable; it is specific to the Linux console. And running an executable using system is not really necessary. But even running
system("tput civis");
...
system("tput cnorm");
is an improvement over using setterm.
Checking the source-code for wget doesn't find any cursor-hiding escape sequences. What you're seeing with its progress bar is that it leaves the cursor in roughly the same place whenever it does something time-consuming. The output to the terminal takes so little time that you do not notice the momentary rewrite of the line (by printing a carriage return, then writing most of the line over again). If it were slower, then hiding the cursor would help — up to a point.
By the way — this cursor-hiding technique is used in the terminal drivers for some editors (vim and vile).
Those apps are probably using ncurses. See mvaddstr
The reason the cursor jumps around is because stdout is buffered, so you don't know actually how many characters are being printed at some point in time. The reason wget does not have a jumping cursor is that they are actually printing to stderr instead, which is unbuffered. Try the following:
fprintf(stderr, "\r[%6.4f%%]", percent);
This also has the advantage of not cluttering the file if you are saving the rest of the output somewhere using a pipe like:
$ ./executable > log.data
Press insert key...if that doesn't work then press the fn key in your keyboard.
This will definitely work
Hope this helps