Method setTextColor:range: on NSTextView is ridiculously slow - regex

I'm creating a simple editor in Mac OS X and I've come to the point where my editor needs to do some highlighting of code, for example, comments.
I am using Regex to find all comments, which I initially thought, was slow. Turns out, it does rather amazing job. For example, for 387 comments, regex needs "only" 0.008404 s to find them and returns array of NSRanges.
But here comes disaster. When I try to set different color to my text with method setTextColor:range: it completes very slow. It needs additional 9.872964 s (for those 387 comments I mentioned before) and it gets worse really fast when number of comments is increased.
So... Is there any way to do this faster? With NSAttributedStrings, perhaps?

I'm really sorry guys, but stackoverflow gave me suggestion on similar question (which I didn't found when I was searching).
It turns out you simply have to tell NSTextViews TextStorage that you will begin doing some editing. And when you finish, you commit those changes. Code looks like:
[textView.textStorage beginEditing];
// do some stuff here
[textview.textStorage endEditing];
Now I ran code with 456 comments, Regex needed 0.013887 s and coloring 0.215761 s, which is amazing drop!
Anyway, I hope someone will find that useful.

Related

Printing text in different colours in the Windows CMD

I am planning to make a console game in C++, kind of like Dwarf Fortress (although I don't know if it was coded in C++), but I have encountered a big problem.
I want to display different things in different colours on the screen at once. I also need to change something that has already been printed (so that I don't have to re-print everything and make the screen flash annoyingly, especially that I will want to make changes every second or so) and I found a way to do that with WriteConsoleOutput() and although I don't know yet exactly how to use it, I'll be reading into it soon.
As for the colours, I found a post here about some ANSI Escape things, but it
a) doesn't work, even when copying the linked code from github
b) I don't know if it'll work with attempts to over-write the console in specific places with WriteConsoleOutput()
So my request is: could someone please ELI5 to me what am I supposed to do and why, as well as present with a viable solution to this combination of two problems so that I can replicate something like this, with the possibilty of changing what the characters show.
Thanks in advance!

Regex help for somebody that realy need help - Visual basic

I'm actually starting creating a small language (in vb net, yes I know, maybe not a good idea).
I already started learning tutorials about regex, but apparently this function is saying me to get out).
I want to add some kind of commands, such as a command that allow you to arg. a /print command, something like:
/PRINT["Hello world";"blue";propety:{bold;italic}]
So, for me, the regex is :
"{{^\^{\|^#\^~\{}~\^]|\~^[}^\}^#~\[}~^\}^##{\~{^}^#\#~#}\^#}^]|\|}]#\|{"
So you understand that's not something I like writing.
Would you show me how to construct regex code for the first command I let?
Regex alone isn't the best way to create a language that, well, actually works.
Read this article for more info. I'm sure you can find better way to write a language if you really need to write it. In vb.net...
Anyway, if you insist on writing it in vb, I found a video that will help you with it.

GNU Radio simulation stuck

I have attached a screenshot of my design here:
when I start simulating it stuck and only plot a few vectors of data.
I think it's becasue of variable time shift block, it's a hierarchy block, when I connect a constant source to i'ts float input the design works perfectly but when I connect output of short to float it does not work,
I think it's becasue Argmax block produces one output for every vector but the variable time shift needs that output constantly.
how can i fix this?
I've written an answer to this question that you also posted on the discuss-gnuradio mailing list (archive):
Hi Mohammad,
to try, you could just use the repeat block.
Best regards, Marcus
I hope that solved your issue, since I haven't heard back from you :)

C.VIM not working

I have a simple question (that I don't seem to be able to answer),
I am a new VIM/Linux user, and since I do c++ development I decided to install the C.VIM plugin to speed up my development time. The problem is, it says in the plug-in (c++) menu that to do a switch statement I have to write \ss (for me the leader is ",", so it's ",ss") but when I do this it just puts me in insert mode and nothing happens. I know the plugin is well set up because when I open a new c++ file it generates a comment box where I can give the description of the program.
I would love it if I would be able to use the shortcuts, because using the menu just losses the point of using vim.
Oh and please, just keep in mind that I am new to vim, I still have hard time figuring out what means <c-r> + TAB (which is, if i'm not mistaking "ctrl-r <tab>"), so if you could just try to explain the solution clearly without to much jargon I would appreciate it. (while i'm here, does anyone know of a good vim tutorial where I could understands all of the vim jargon, thanks!)
I appreciate all the help.
I use this cheat sheet:
http://www.worldtimzone.com/res/vi.html
Please add the below line to .vimrc and
helptags ~/.vim/bundle/c.vim/doc
Note: I have pointed to my c.vim doc and I use bundle, it may differ for you :)

How can I highlight different types of file in dired mode in Emacs?

In a nutshell, I want to have different faces for some types of file in dired mode. I don't think it matters, but I am using Aquamacs.
The example I will use here is .tex files. If I can do it for .tex, then I can just apply the same structure to do create other faces for other types of files.
From what I understand, I have to create a variable, write a regular expression, then apply a hook. I read a bit about regex and so far I have
^(.+)\.tex$
I think my structure and regular expression are not really correct. I am not a programmer (though I have an interest on it), I have only been using Emacs for 2 weeks or so, so any help would be greatly appreciated.
What I need is at least the basic structure of what I have to do. I understand there may be modes already created that do something similar (such as maybe Wdired and Dired-X), and I would not complain if someone told me about them, but what I really want is to have an elisp code (either already written or that I can work on), as I plan on learning a bit of elisp to be able to write my own customisations and this would be a way to learn.
Thank you!
Since you want to learn how to do it, try checking out the extension dired+.el. This mode does a lot more than what you want, but it does add new faces. Specifically, look for the variable diredp-font-lock-keywords-1 and how it is used. That should get you going.
Other SO questions that seem relevant are:
Match regular expression as keyword in define-generic-mode
Highlighting correctly in an emacs major mode
A hello world example for a major mode in emacs?