I want to change Doxygen macros and function arguments formatting. Whatever this formatting is trying to achieve can be done with #param, which will describe function parameters way better in the section down below. Also, explicitly saying void as function arguments formats it with some strange spacing, while right above it Doxygen understood that nop(void) is equal to nop(), which just drives me crazy.
I think that macro / function arguments formatting should be a configurable option. I want to change mine formatting from multiline to one line, since I don't see the benefits of doing otherwise.
#define ADD(a, b) a + b
int add(int a, int b)
I couldn't find anything about function arguments formatting. About void people said to use aliases, but gave no examples, so I am stuck here. Hope I gave enough info on what I am trying to achieve!
I am a freshman with respect to learning emacs lisp and I'm therefore reading the emacs lisp manual. When i read 6.6 Char-Tables, I was confused about how to use the char-table. In that chapter, I can't find a good example to use char-table.
Of course, elisp has the syntax-table which consists of the char-table and syntax-table can do a lot of things.
I want to know how to make a good use of char-table and in which cases I would use it.
Thanks
I'm not very familiar with Emacs Lisp programming, but alone from the description of the data structure I was immediately thinking of keymaps. And, as it turns out, I was right.
Especially the use of "parent" char-tables makes sense in this context: For example, when activating a mode, that mode probably has a keymap with the keybindings it provides. Before setting the current keymap to the mode's keymap, the current keymap is probably made the parent of the mode's keymap. That way, when the mode's keymap does not provide a mapping, the previous keymap(s) can be queried for an appropriate mapping.
Here's how I'd implement char-tables in C, as a rough sketch:
struct char_table {
void * data[256 /* or how many char codes there are */];
struct char_table * parent;
};
void * lookup(
struct char_table * table,
char /* or a more suitable type for char codes */ key) {
void * result = table.data[key /* plus possibly some calculation */];
if (!result && table.parent) {
result = lookup(table.parent, key);
}
return result;
}
Emacs's char-tables are simply a special kind of array that's indexed by characters rather than by integers. There are many characters in Unicode, so it's worth having a special implementation of such an array where many ranges of characters share the same value.
I'm working with some matlab code and using good block comments to head off certain sections of the document, but it sure would be nice to just collapse the whole lot of sections once I'm done fleshing them out. General purpose code formatting region blocks may be a future feature request for Matlab too I suppose.
I recently discovered section breaks, but it looks too granular for my purposes one of which is to group a set of related functions. As far as I can see sections cannot embrace function definitions. By comparison C#'s #region code block formatting is general purpose and supports arbitrary nesting of any source content whatsoever.
There are a number of MATLAB constructs that can be folded with +/- signs in the editor. The closest thing to what you are looking for is maybe code-folding using sections, delimited by %%.
It's not enabled by default in MATLAB, you need to go to:
HOME > Preferences > Editor/Debugger > Code Folding
There you'll see the list of enabled constructs - check the sections.
Now delimit you code with sections and fold away!
%%
Some code
Some code
%%
Code in another section
...
In functions, the MATLAB editor displays a warning when a defined variable is not subsequently used before the function ends or before the variable is overwritten. This obviously tells me that the editor has a way of searching for occurrences of given variables in the code.
Can I do this manually? The Find function is obviously limited here, since it only searches the body of text in the editor window (including comments) for matches of the search string. This makes it very inconvenient when searching for variables with short names (such as the by me commonly used "a").
I cannot tell you about previous versions of the built-in editor, but at least from 2011b, the righthand side margin of the editor creates color tags for:
Warnings, tagged in orange
Errors, tagged in red color
Variable/function occurrence: tagged in dark gray, for selected text.
The third of them is what you are looking for. You just have to double click on a variable name or a function name to select it and your Matlab editor will automatically highlight the rest of the occurrences of the very same identifier, tagging them on the righthand side ribbon with the grey mark I mentioned above.
You can limit the search to match case and whole word, which will give you only this variable, either in comment or not.
BTW, you shouldn't use variable names like a,b,c. It makes the code harder to read and to maintain. Even if you have dummy variables like in loops and temporary ones, use for example indexFiles, or tempValue
You can also use some regular expression to match the variable names in your code.
If you'll assume that any variable name is separated from the rest of the code by any of linefeed tab space ! " # $ % & ' ( ) * + , - . / : ; < = > ? [ \ ] ^ `` { | } ~, then you can create a small function that takes the function name as input and outputs the lines in which the variable name is mentioned. However, this approach doesn't separate function names and variable names, but you should have some standard for separating them anyway. I use this approach to change variable names of my MATLAB code (but my code for that is written in awk, not in MATLAB).
And I wonder what you'll do when you have a complex program with thousands or tens of thousands of lines of code and your variables are named a, b, c and so on...
Is there any diff/merge tool for programming languages, that works in a syntax-aware way (like XML Diff Tool), doing more than compare line-by-line (and optionally ignoring whitespace).
I'm interested in a program actually following the language syntax and delimeters, suggesting changes without breaking syntactic correctness, or bundling statements separated over multiple lines. Example behavior would be:
*upon finding an if(){ which introduces an extra nesting level automatically bundle the closing brace } several lines below with it.)
*keep matching syntax elements together, avoid silliness like removing a block tends to create:
int function_A()
{
int ret;
ret = something;
ret += something_else;
return ret;
}
int function_B()
{
if(valid)
{
int ret;
ret = something;
ret += something_else;
return ret;
}
else return -1;
}
Personally, I'd love to find software capable of handling C++ syntax, but knowing about solutions for other languages would be interesting too.
Semantic Merge.
Languages supported, from the website:
We started with C# and Vb.net, then added Java. Now C is already supported and then we’ll focus on C++, Objective-C and JavaScript, depending on your
feedback
While KDiff3 does not compare syntax elements in a grammar context, it does have a higher granularity than "the whole line changed", and it will highlighting exactly what parts within a line that is changed.
And in my experience it has a very good algorithm for detecting changes. Given your example above, it correctly compares function_A and function_B out of the box:
And even so, should the algorithm fail to match what you want, for instance like the following:
you can always override manually by placing sync marks where you want to have it perform the comparision.
Alternative 1:
Alternative 2:
Sounds like you'd be interested in Bram Cohen's (BitTorrent creator) Patience Diff algorithm (which is used in the bazaar version control system).
See The diff problem has been solved and especially Patience Diff Advantages:
Excerpt from second link:
Another advantage of patience diff is that it frequently doesn't match lines which just plain shouldn't match. For example, if you've completely rewritten a section of code it shouldn't match up the blank lines in each version, as this example shows. Finally, there's this example:
void func1() {
x += 1
}
+void functhreehalves() {
+ x += 1.5
+}
+
void func2() {
x += 2
}
Which is straightforward and obvious, but frequently diff algorithms will interpret it like this:
void func1() {
x += 1
+}
+
+void functhreehalves() {
+ x += 1.5
}
void func2() {
x += 2
}
Beyond Compare does some of what you're asking. It doesn't maintain syntactical correctness or compare language blocks at a time, but it can do the following:
Some understanding of language syntax, so it can do syntax highlighting of compared files, and it can also recognize and optionally ignore unimportant differences (like comments, including multiline comments).
Support for using external conversion programs for loading and saving data. Out of the box, it supports using this to prettify XML and HTML before comparing it. You could set up GNU Indent to standardize syntax before comparing two C files.
Optional line weights to let you give a higher weight to matching, e.g., closing braces. I've not tried this feature.
Replacements, to ignore for a single session every place where old_variable_name on the left was replaced with new_variable_name on the right.
It's by far the best diff-and-merge tool that I've used. It's also cross platform, cheap ($30 for standard, $50 for pro), and has a very generous evaluation period, so it's worth a try.
See our SmartDifferencer tools.
SmartDifferencers are language specific, driven by production quality language parsers, build ASTs, and compare the trees. This makes them completely indepedent of text layout and intervening comments; remarkably, they are immune to changes in the text of literals (radix, move decimal point+change exponent, different escape sequences) if the actual value represented by the literal isn't different. The result is reported in language syntax terms, and plausible editing actions (move, copy, insert, delete, rename-identifier-within-block).
There are versions for C#, Java, C++, Python, and a variety of other languages. There are examples of each of these at the website.
A SmartDifferencer exists for C, but parsing C files without the full compiler command line is sometimes problematic, so sometimes it fails and you have to fall back to more primitive compare tools, like diff. We are working to improve this situation.
Please look at Compare++.
It can do language-aware structured comparison for C/C++, Java, C#, Javascript, CSS, ...
and Optionally ignore comment, pure formatted, white-space and case changes and have unique ability to align moved sections such as C++ function, Java namespace, C# method, CSS selector, ...
If you are using eclipse, the integrated compare editor provides syntax aware diff/merge, at least for Java. Check "Open Structure Compare automatically" under the "General/Compare/Patch" preferences, then choose "Java Structure Compare" in the compare editor.
Look at https://en.wikipedia.org/wiki/Comparison_of_file_comparison_tools especially column Structured comparison.
Currently there are only two tools who understand language structure.
Compare++ (Works great for C++)
Pretty Diff (Language aware code comparison tool for several web based languages. It also beautifies, minifies, and a few other things..)
Unfortunately many tools have this column still empty.