How to insert code into a vimoutliner file? - linux

How to insert code into a vimoutliner document (.otl)? Is there something like:
<code>
...
</code>

You can insert a "preformatted body text" block by starting a line with ;, e.g.:
Hello world
This is "Hello world" in Ruby
; def hello(name)
; puts "Hello, #{name}!"
; end
According to the docs:
The preformatted text marker, ;, is used to mark text that should not be
reformatted nor wrapped by VO or any post-processor. A post-processor would
use a fixed-space font, like courier, to render these lines. A post-processor
will probably not change the appearance of what you have written. This is
useful for making text picture, program code or other format-dependent text.
You can also use < for a "user-defined preformatted text" block, which allows you to give a "style" to the block (e.g. to label which language it's in):
Hello world
This is "Hello world" in Haskell
<Haskell
<hello :: String -> IO ()
<hello name = putStrLn ("Hello " ++ name ++ "!")
As implied by the docs, what actually happens to those text blocks depends to what you're doing with your outlines once written - if you're using some tool to process them into another form, you'd want to check what that tool does with preformatted text blocks. I use a custom-written tool that takes the user-defined preformatted blocks and outputs syntax-highlighted HTML <code> tags.

Related

How could I create a string pattern in Lua to find encapsulated text similar to markdown?

I'm still getting used to the concept of string patterns, and I've run into an issue regarding them. I'm trying to create a simple program that searches a string of text, for certain characters encapsulated in whatever the brackets may be. Here's an example:
local str = "Hello <<world>>, my <<name>> is <<John>>"
-- Match patterns with << ... >>
for noun in str:gmatch("<<.->>") do
print(noun)
end
This program will search through the string, matching everything that starts with << and ends with >>, and everything in between. Good, that's what I want. However, let's say I wanted a different pattern that only got text between one of those tags instead of two (< and > instead of << and >>). This is where I run into a problem:
-- Allow easy customization control over brackets
local matchNouns = {"<<", ">>"}
local matchOther = {"<", ">"}
local str = "<Hello> <<world>>, <my> <<name>> <is> <<John>>"
local function printOtherMatches(str)
-- Get opening and closing brackets
local open, close = unpack(matchOther)
-- Concatenate opening and closing brackets with
-- pattern for finding all characters in between them
for other in str:gmatch(open .. ".-" .. close) do
print(other)
end
end
printOtherMatches(str)
The program above will print everything between < and > (the matchOther elements), however it also prints text captured with << and >> as well. I only want the iterator to return patterns that explicitly match the opening and closing tags. So the output from above should print:
<Hello>
<my>
<is>
Instead of:
<Hello>
<<world>>
<my>
<<name>>
<is>
<<John>>
Basically, just like with markdown how you can use * and ** for different formats, I'd like to create a string pattern for that in Lua. This was my attempt of emulating that kind of pattern sequence. If anyone has any ideas, or insight on how I could achieve this, I'd really appreciate it!
-- Allow easy customization control over brackets
local matchNouns = {"<<", ">>"}
local matchOther = {"<", ">"}
local delimiter_symbols = "<>" -- Gather all the symbols from all possible delimiters above
local function printMatches(str, match_open_close)
-- Get opening and closing brackets
local open, close = unpack(match_open_close)
-- Concatenate opening and closing brackets with
-- pattern for finding all characters in between them
for other in str:gmatch(
"%f["..delimiter_symbols:gsub("%p", "%%%0").."]"
..open:gsub("%p", "%%%0")
.."%f[^"..delimiter_symbols:gsub("%p", "%%%0").."]"
.."(.-)"
.."%f["..delimiter_symbols:gsub("%p", "%%%0").."]"
..close:gsub("%p", "%%%0")
.."%f[^"..delimiter_symbols:gsub("%p", "%%%0").."]"
) do
print(other)
end
end
local str = "<Hello> <<world>>, <my> <<name>> <is> <<John>>"
printMatches(str, matchOther)
Here's one possibility:
local s = '<Hello> <<world>>, <my> <<name>> <is> <<John>>'
for s in s:gmatch '%b<>' do
if not s:sub(2,-2):match '%b<>' then print(s) end
end

Optional lines in Ultisnips using parameters

I am trying to have some additional lines inserted in snippets based on a parameter. I am not sure how design such snippet.
snippet 'mysnip' 'snippets with optional lines'
This snippet line1 is inserted by default
<This line1a should be inserted if parameter1 is true>
This snippet line2 is inserted by default
<This line2a should be inserted if parameter1 is true>
endsnippet
It is not very clear to me how/where you want to enter your parameters.
One option is to define two snippets, one called mysnip and the other one mysnip1 - in this case you pass the parameter in the snippet name, and the definition of these two snippets should be straightforward.
Another option is to just define one snippet mysnip, and pass the parameter somewhere within this snippet. A working example could look like this:
snippet mysnip1
${1:Change this snippet line to have the text "True" (without quotes).}
This line is always present. `!p
if t[1]=="True":
snip += "A line displayed when $1 has the text True.
`
endsnippet
You can fake this using regular expression triggers. It only works if you do not want to have tabstops in your optional arguments though:
snippet /mysnip([a-z]*)/ "Optionals" r
this is always here!`!p
if "a" in match.group(1):
snip += "only when a"
if "b" in match.group(1):
snip += "only when b"`
endsnippet
If you type mysnip it will just be the first line, mysnipb the first and thirdm and mysnipab will be all of it.
Can't you put your optional lines in a variable that your snippet engine will expand?
In case it doesn't join automatically empty lines produced from a empty variable, you may have to have your variable contain a newline character and put it or the line before/after.

Importing String with variables from Txt file

I need to import text from txt file with some variables. I use BufferedReader and File Reader. In code I have :
String car = "vw golf";
String color = "nice sunny blue color";
And in my txt file:
I have nice " +car+ " which has "+color+".
My expected output :
I have nice vw golf which has nice sunny blue color.
My actual output is :
I have nice " +car+ " which has "+color+".
If I've understood correctly, what you want to do is replace " + car + " with the value of your car string and likewise for colour. You've tried to do this by writing your text file as if it were a command to be evaluated. However, that won't happen - it will just be outputted as is. I'm going to assume you are using c#. What you need to do is, prior to outputting your string, parse it to replace the markers with the variables. I would recommend you get rid of the double quotes in your text file. You could then do something like this:
string text = this.ReadTextFromFile();
string ammended = text.Replace("+car+", car);
As mentioned, this is assuming you remove the double quotes from your text file so it reads:
I have nice +car+ which has +color+.
Also, you don't need to use the + symbols, but I suppose they are a good way of designating a unique token to be replaced. You could use {car} in the file and then likewise in the Replace startment, for example.
I may not have properly understood what you wanted to do, of course!
Edit: Incase of confustion,
this.ReadTextFile();
was just a short hand way of saying that the text variable contains the contents as read from your text file.

Rich Text Format Tags for Hiding and Un-hiding

I would like to hide part of the text in my RichTextBox. I know that \v is the start of a hiding section. But how do I unhide ? For example if I want to hide the word "big" in the string "hello big world" so that "hello world" is visible:
text : "hello big world"
RTF so far : "hello \v big world"
result : "hello "
wanted result -> : "hello world"
doesn't work : "hello \v big\v world"
Is there a way ?
Solution by Alex K. is probably better but I'm adding this solution I just found because it also works. \plain resets the text style back to defaults:
hello \v big\plain world
Yet another solution (actually used by the RichTextBoxes): \v0 disables just the hiding
hello \v big\v0 world
You need to use curly braces to group the code;
"hello {\v big} world"

text with redundant side chars formatting in emacs

I did lots of search without luck. I think even this is easy but it could help, so here it goes.
Here the goal is to format a kind of Java String to plain text.
For example, consider a String in java code,
logger.LogText( "Hi, this is 1st line " + "\n" +
"speak sth. in 2nd line " + "\n" +
"answered...? ");
and i want to copy from the whole String and paste to my plain text file, then run
M-x some-format-function-by-template-on-selection
and i got a result
Hi, this is 1st line
speak sth. in 2nd line
answered...?
Is there a built-in command for this?
It's not have to use template, but don't you think it's cool?
Currently i try to use 'align' to work around.
The built-in commands are the regexp functions :-)
(defun my-reduce-to-string (start end)
"Extract a quoted string from the selected region."
(interactive "r")
(let* ((text1 (replace-regexp-in-string ".*?\"\\([^\"]+\\)\"[^\"]*" "\\1"
(buffer-substring start end)))
(text (replace-regexp-in-string "\\\\n" "\n" text1)))
(delete-region start end)
(insert text)))
Note that this is a destructive function -- it replaces the text in the buffer as requested.

Resources