How to customize indentation in Geany - indentation

Based on geany documentation
Geany knows four types of auto-indentation:
None: Disables auto-indentation completely.
Basic: Adds the same amount of whitespace on a new line as on the last line.
Current chars:
Does the same as Basic but also indents a new line after an opening brace '{', and de-indents when typing a closing brace '}'. For Python, a new line will be indented after typing ':' at the end of the previous line.
Match braces:
Similar to Current chars but the closing brace will be aligned to match the indentation of the line with the opening brace.
I am developing new editor for new DSL. I don't have any kind of braces, so indentation must be based on strings. How can I apply auto-indentation to my custom syntax. Is there any short and easy way?

Scintilla can be the thing that you are looking for. Strategy which used while implementing folding inside LexDSL.cxx can be a solution for it. Level based implementation of code folding can also determine the deepness of the tab. Each level means new tab and using that strategy could make customization of indentation in geany be possible.

Related

RegEx for underlining text

How can I match one line of text with a regex and follow it up with a line of dashes exactly as many as characters in the initial match to achieve text-only underlining. I intend to use this with the search and replace function (likely in the scope of a macro) inside an editor. Probably, but not necessarily, Visual Studio Code.
This is a heading
should turn into
This is a heading
-----------------
I believe I have read an example for that years ago but can't find it; neither do I seem to be able to formulate a search query to get anything useful out of Google (including variations of the question's title). If you are I'd be interested in that, too.
The best I can come up with is this:
^(.)(?=(.*\n?))|.
Substitution
$1$2-
syntax
note
^(.)
match the first character of a line, capture it in group 1
(?=(.*\n?))
then look ahead for the rest of this line and capture it in group 2, including a line break if there's any
|.
or a normal character
But the text must has a line break after it, or the underline only stays on the same line.
Not sure if it is any useful but here are the test cases.

Unwanted highlighting on braces inside brackets in Vim when using c++

My vim editor highlights the pattern [{}] when I'm writing c++ code.
It highlights the braces in the same way it would highlight search matches, however the command :nohl doesn't yield anything.
Any ideas on how to turn this off?

Why doesn't Sublime Syntax match a text from A to B with new lines via regex?

I am trying to write a custom syntax (via YAML), where I would like to indicate comment area rule. So for instance: /* */ - is a common from-to indication of a comment section.
Forged the following code:
((?=/*)[\s\S]*?(?<=*/))
It works well here: https://regex101.com/r/EQqn7b/2/
However, having tried it in Sublime, it wouldn't match text in the case with new lines between the beginning and ending of the comment section area:
Here is how it looks in Sublime
(Colored in gray - is the text which was successfully matched by the above regex)
So the desired effect is to make both cases shown in picture earlier - matched by regex in Sublime.
Could somebody point me out what am I doing wrong or missing out?
Thanks!
Note: flag like (?s) - is treated as unrecognized, rendering it unusable
You're bumping into this (excerpt from the syntax documentation, emphasis mine):
match. The regex used to match against the text. YAML allows many strings to be written without quotes, which can help make the regex clearer, but it's important to understand when you need to quote the regex. If your regex includes the characters #, :, -, {, [ or > then you likely need to quote it. Regexes are only ever run against a single line of text at a time.
That is, your regex doesn't match across multiple lines because it's being fed the lines one at a time and not in the manner that you expect.
In order to support syntax constructs that span multiple lines, you need to use a second context. An example of that might look something like this (taken from the default C syntax):
- match: /\*
scope: punctuation.definition.comment.c
push:
- meta_scope: comment.block.c
- match: \*/
scope: punctuation.definition.comment.c
pop: true
This says that when the text /* matches, the parser should push a new anonymous context with it's own set of rules onto the parsing stack, which remains in effect until a match rule tells it to pop back to the context it was in to begin with.
The inner (anonymous) context has only a single match rules on */ with instructions to pop the context from the stack, which keeps any other syntax rules from matching until the end of the comment is seen.
This also shows scoping the /* and */ portions of the match as comment punctuation individually, while the meta_scope applies to the entire match (including the text that entered the context and the text that pops it off).
That makes the entire /* comment */ as a whole scope as comment.block.c while also applying a specific context to the characters that start and stop it, since your color scheme may want to color them differently, or a plugin may want to be able to detect comment delimiters, etc.
Within that inner context you can add as many extra match rules as you want. For example, you could include one that matches TODO to give it an additional scope so that your color scheme can target them and make them stand out, and so on.
I believe your solution is not working because you are not using MULTILINE/DOTALL in your solution. You either pass those parameters to the method doing the evaluation, or simply add (?s) at the beginning of your regular expression. See this post:
Sublime Text regex not detecting multiline tags

Regex that selects line break after certain number of characters

I'm looking for a regex string that selects each line break that follows a certain number of characters (in my case 19).
This would select the whole line--but I would only want the line break selected that fulfills this condition:
.{19,}[^\n]
Any help would be greatly appreciated (I obviously don't really know my way around regexs.)
Essentially what I'm trying to do is a search&replace with a text-editor that supports regex to get rid off line-breaks from an OCRd book. My somewhat heuristic approach is that every line shorter than 19 characters is likely a paragraph break (It's a very small book) and should keep the line break while all other lines should have the break taken out.
Example:
This is a line that wraps
around
This one isn't.
Here begins a new paragraph
The line break after 1. should be taken out, so the word "around" moves up. The line break after line 3 shouldn't since it's too short--so the transition to the next paragraph (line 4) is not taken out.
I hope this makes sense? (since I'm not using a programming language, I'm assuming /K won't work--at least it doesn't in the editor I'm currently using).
Thanks!
One very useful tool with regexp is a regexp tester, such as Regex 101
That way you can see what your regex is doing. Make sure to clarify which one you are using (I program mostly in Ruby which acts a bit different then some others).
In yours, .{19,} looks for 19 or more characters, if you want EXACTLY 19, remove the comma.
.{19}
then since you don't want those 19 (or 19 plus?) characters you can use:
.{19}\K\n
\K 'forgets' what has been matched so far and moves on from that point. Very useful if your regex allows it (Ruby does not, if I recall correctly?) if you want 19 chars from the beginning of the line:
^.{19,}\K\n
and don't forget the multiline and global options if you want all matches.
demo
ALSO! Be sure to read Crayon Violent's comment above for more good advice (and an important Windows fact!)

Regular Expression for removing indentation

I have a requirement to remove indentation from a numbered paragraph. I currently do this with a couple of regular expressions and some code, but would like to accomplish it with one or more regular expressions. The paragraph looks like this:
1. THE FIRST LINE OF THE PARAGRAPH
ANOTHER LINE IN THE PARAGRAPH
AN INDENTED LINE WITHIN THE PARAGRAPH
This needs to be transformed to retain the indentation within the paragraph, but remove the indentation of the entire paragraph as measured by the indentation of the first line.
THE FIRST LINE OF THE PARAGRAPH
ANOTHER LINE IN THE PARAGRAPH
AN INDENTED LINE WITHIN THE PARAGRAPH
The following regex accomplishes the task by replacing matches with empty strings. (note that there are no tabs expected in this content, just spaces):
(\A *\d+\. *|^ {0,5})
But it requires that the indention length of 5 characters be set explicitly. I would like a generic way of doing this that would work with any indentation length. Any ideas for how one or more regular expressions (applied cumulatively) could accomplish this?
I am using the .NET regular expression engine with multiline mode turned on.
As other have indicated, regex (alone) probably aren't the correct tool for the job.
The major problem is that in order to strip the correct amount of spaces from all the further lines, you somehow need to store how wide was the first indentation. This is something that I'm not sure is doable with a regex engine alone.
If your desire for a regex based approach is just to have a quick one-liner than I think you can hack something like the following (I'm not familiar with .NET so I'll just provide you with a python solution):
re.sub(r"^([\d\. ]+)(.*)$",
lambda m: re.sub("^" + " "*len(m.group(1)),
"",
m.group(2),
flags=re.MULTILINE),
paragraph,
flags=re.MULTILINE|re.DOTALL)
The idea is to have the outer regex isolate the indentation of the first line, while the inner regex takes care of removing the correct amount from subsequent lines.
In order for this to work the indentation must be made exclusively of spaces (i.e. no tabs) otherwise you'll have to do some assumptions on how many spaces a tab is made of.
That said you would probably better off implementing a custom parser to do the job. It would surely be cleaner and probably more efficient too.
I am not sure how you thought it would work, but your regex matches everything under the sun due to the right side of the |.
Try this:
^((?:\d+\.)? +)
Use something like http://www.regexr.com/ to test it out.