I'm getting some surprising errors when I try to input a string using (read). Context: I'm building a mini language, with inputs deliminated using characters like {, }, :, etc.
Here's what happens, I run (read) and enter {9.I:{8.II:hello}{8.III:hi}} (an example input string from my mini language).
I then get 2 errors:
1:
too many colons in "{8.II"
2:
Package HELLO}{8.III does not exist.
It seems as though there's something extra going on in the (read) function that's tripping me up. Can someone point me in the right direction?
read is designed to read a valid Lisp S-expression. It's going to use Common Lisp's parser. If your language is sufficiently Lisp-like, you may be able to make it work for you, but given the example input you've shown, I doubt it's what you want.
You're probably looking for read-line, which reads a single line of text as a string and does not perform any additional parsing on it.
Very often (but not always) when I'm typing fast* Visual Studio Code ignores space characters following a colon.
For example, I go to type a hash or keyword argument list in Ruby:
myhash = {space: :nope}
and I get
myhash = {space::nope}
If I type more deliberately it doesn't happen.
In cases like above, auto-formatting doesn't save me either -- it doesn't parse because :: is ruby's module delimiter.
Is there anything I can do about it? In a project I know well it's literally enough to almost completely offset the productivity advantages of Intellisense.
(*) I'm not particularly fast, but I might get up to the equivalent of around 80wpm for a few lines of code at a time.
I figured it out! shift-space was bound to the Trigger Suggestcommand.
I'm making a custom .tmLanguage file to highlight the syntax I'm using correctly and generally make coding with it easier. I'm almost done, and I got the autocompletion working using a .sublime-completions file.
There's just one minor flaw I'd like to change. I have a pretty long list of functions, and almost all of them contain an abbreviation of the word 'parameter', PAR. When I start typing that word, the following are all in the list of completions:
PAR command
DEFPAR command
JDATA command (because the description contains PAR)
SPAA command (because there's a P in the command and an A and an R in the description)
What I want is only for the commands that begin with PAR to show up, so from the list above, only the first item.
So, like this:
In other words, I want the completions to show up based on the literal string I'm typing, and only from the trigger part of my completions file, before the \t only.
That completions file looks like this:
Highlighted in orange is what I want my completions list to be based on.
I hope this is understandable. Any help is greatly appreciated.
This is not possible. By design Sublime's autocomplete feature uses fuzzy matching, so if there are a number of options that all contain the same pattern, but you don't quite remember which one you want, you can type the pattern and have all of the options available. The more you type, the smaller the list of possible options becomes. This is a good thing®, otherwise you'd have to remember the exact command you're looking for, which kind of defeats the purpose of autocomplete and code hinting.
I want my emacs to globally replace
:>>:
with
»
during typing. Any other typing combination is ok, too. I just chose :...: because that made it easier for emacs to descern the "name" of the replacement. I have a couple of sequences I want to be replaced in this way, i.e.
:>>: with »
:<<: with «
:e/: with e-accent-acute
:e\: with e-accent-grave
and so on.
Maybe there is a mechanism in emacs I can use. But googling did not get anything useful, I probably did not use the right search terms.
One big issue seems to be that the » in question is a unicode char and the .emacs-file has problems with that?
Emacs supports many Input Methods (doc here).
For example, with the latin-1-prefix input method, you can type `e to get the grave accented e; ~< will give you the opening guillemet.
Call set-input-method and select latin-1-prefix for this.
The function describe-input-method will show you complete help for your current input method.
Another interesting input method is TeX, which substitutes TeX symbols on the fly, such as \Delta, ^1, ~n, etc.
Answer to related question here. Nice tutorials here or here.
Use Abbrev Mode. Set :>>: to map to » etc.. The mode will automatically substitute. To do this, edit the abbrev file to include your mapping, or simply create the mapping in Emacs and save it with M-x write-abbrev-file.
p.s. I think Emacs is Unicode safe ATM. I've been using various Unicode characters for a long time.
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.