Why does eclipse CDT extract function feature want to reformat unrelated code in my .cc file? - eclipse

I have some C++ code that contains 5 or so lines of code that I want to refactor into a function. When I right-click->refactor->extract function, the refactor generates the function correctly, but it insists also on reformatting a large chunk of code that has nothing to do with the code I'm refactoring. Furthermore, neither the reformatted code nor the generated function fits my current style (K&R modified by me) as near as I can tell.
Why does it do this?
Is there a way to get it to follow my code style?
Is there a way to turn it off?

Related

How to stop VS code from unfolding everything on block open syntax?

Not exactly sure how to phrase this but it is incredibly annoying that when I'm writing js for example and open a comment block (/*) or a template string(`) and everything that I have folded in the following lines gets unfolded because it thinks that my comment or template string block might just extend to the very end of the whole file.
At this point I'm already in the habit of writing the end of a comment block before the beginning and copy-pasting my template strings and then editing them rather than making new ones but it would be so much nicer if I could just write without having to worry about such things, notepad++ handled it well, is there any way to make vs code behave decently too?

How can I get colored output in VS Code output window?

This is really a two part question, but they are in the same vein, so I will ask in one post.
When I flip through various colors, I see that they also have the ability to change the color of the Output window. Which VS Code setting can I use to change the color of this output? To be specific, I am not asking about the terminal, I am inquiring about the output window that displays the output when using coderunner as an example. Please refer to the screenshot to see which window I am referring to.
Second question is I can see that the output does support multiple colors. I am trying to use the module cpprint from the python lib prettyprinter to print colored output to this window. When I run the script in a terminal, I am getting colors, but in the output window, I am not getting any colors. Will it be possible for me to get similar colored output in the output window as in the terminal? I am assuming the output window supports colors because the [Running]... and end are in colors.
The Python lib I was referring to
Thanks!
So, for long while now, we have had to resort to an IBM developed extension named Output Colorizer, however, this extension clashed with other extensions, and cuased an array of bugs/issues. I personally had to disable it because it was causing text to not print at all in my output window.
We now have a much more robust, built-in solution, and it doesn't require doing anything.
Visual Studio Code added syntax-highlighting support to the "Output Channel" as part of a Milestone that it had been working on, in its March 2022 Release.
The syntax highlighting is configured by a specified languages grammar.
The language grammar that is used will vary, depending on which output channel you use. The person who decided on the language syntax highlighting used for any given output-channel is the person who authored the extension that the output-channel belongs too.
Here is the link to the official release note
Because the output highlights syntax on a language basis, configuring what colors the new feature uses to color any given text, is done the same way you color syntax.
In Depth Explanation:
If numbers are set by your theme to render green (#00FF00), then, then numbers that are printed in the Output View Panel will also be green.
If the language defined constants true & false render as a pastel-red (#FF7799) when you are writing TypeScript, but when you have a Java file open, they render as a bright pastel-yellow-green (#BBEE88), then the way they render will be contingent on whether or not the output window was set to Java or TypeScript. Obviously an output window for an extension that's a tool for Java, will most likely highlight syntax as Java. A typescript-tool extension will likely highlight all syntax as if it were typescript.
Some People Might Prefer that the Feature be more Customizable
Some people might want a more customizable feature, but I think it would be a mistake, even if it were possible, to highlight the syntax in the output differently from the editor. In fact, thinking about it, it would be stupid to have done that. It makes perfect sense that it is the way it is.
Anyways, that is the end of the Color in the Output Channel, or at-least for now.

How to execute functions in Live editor in MATLAB

I recently started using Live editor in MATLAB and I inserted a function inside it. But, apparently, I cannot execute that particular section of code where I type function. Even the section break disappears.
Is it that using function is not suitable for live editor?
Apparently the MATLAB parser did not join the 20th century until partway through 2016, and could not interpret function definitions in scripts (live or otherwise) until R2016b. In the web-based docs, there is a notice at Add Functions to Scripts, but it took me a while to find this out because the builtin docs in R2016a or earlier do not explicitly contain this information. It is implied by the tutorials that tell you to create a new file for each function (which to me, a python programmer, sounds more like strange advice than a restriction).
Trying to define a function in a live script gives confusing errors. For example, if you create a cell with this content:
function y = myfunc(x)
y = 2*x;
end
It will underline the keyword function with a popup error that reads:
Parse error at FUNCTION: usage might be invalid MATLAB syntax.
Might be? Whom shall I ask? Upon running the cell, it prints an error after the first line:
All functions in a script must be closed with an end.
I eventually made this discovery myself thanks to a helpful message if the first thing you happen to do in a new empty live script is to start typing function on the first line; as soon as you hit the spacebar a message pops up at the top saying:
Functions and classes are not supported in the Live Editor. To continue, save the file as a plain text code file (.m).
It should work as when you add a function inside a script. For example, like this:
What function are you exactly trying to code?

Is there a quick way to show the code of a method declared in the Scala Console?

I frequently use the Scala console to evaluate and test code before I actually write it down in my project. If I want to know the contents of a variable, I can just enter it and scala evaluates it. But is there also a way to show the code of methods I entered?
I know there's the UP-key to show single lines, but what I was searching for is to show the whole code at once.
There's a file in your home directory named .scala_history that contains all of your recent REPL history. I regularly copy and paste code from this file into project source files. It's not exactly the same as showing the code for individual methods in the REPL, but it might help you accomplish the same goals.
See the comments by Paul Phillips in this issue for a discussion of some related functionality in the REPL (grouping statements in the history):
At some point I implemented the logic for this, but the real obstacle
is jline. It has enough trouble figuring out where the cursor is under
the simplest conditions. Start throwing big multiline blocks into the
history and it breaks down in tears. Would love to see this and
SI-2547 addressed by the community.
...
I expect to fix this soon too, but it depends on how well the recent
jline work goes. I implemented it long ago, and display issues are the
impediment.
Both of these comments are over two years old, so I wouldn't hold your breath.
I dont know a command to load all the code from command line.
What you can do is to :load path/to/my/file.scala to load some complex code and re- :load it when you changed the code in the file.

Modify Lisp function without rewriting it?

I wrote a Lisp function earlier that had an error. The first challenge was to figure out how to view the function again. That challenge is solved. Now that I see WHAT I have done wrong, I want to modify the contents of the defined function without rewriting the whole thing?
Seems like as intelligent as Lisp is, there HAS to be a way to do this, I just don't know what it is because I am fairly new to the language. Can this be done?
Judging from the question, I think that you have a strange setup. It seems to indicate that you are writing your functions directly at the REPL. Don't do that.
The usual setup is to have an IDE (for example, Emacs with Slime) where you edit a source file, and then "send" top-level forms (like function definitions) to the REPL.
Every useful REPL has a history functionality. It allows you to move in the history of your input backwards and forwards.
When I write code in the REPL simple keystrokes like m-p gets back earlier code. Some IDEs might even be able to locate source code in a Lisp listener with m-. .
In most REPLS you can also search incrementally backwards.
If you want a log of your input use the function DRIBBLE..
There are some more options, like retrieving the code from the function - when a Lisp IDE supports that.
There is the advice functionality in many Lisps, which lets you run additional code before or after or around an existing function. But the comment is right, why wouldn't you rewrite a function if you're still learning and trying things out? Do they charge you by the compile cycle?