View Single Post
Old 04-21-2021, 10:56 AM   #75
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,108
Karma: 1954138
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by chaley View Post
It is a function, not a keyword, so it isn't highlighted. I thought about making it a keyword but decided against it to avoid clashes with identifiers in existing templates.

You are right, I forgot to add the function to the function list. I will do that.
Functions turn into blue once I add the parenthesis. I think adding to the function list would do it. e.g. In the screenshot below, the strcat is blue while the newline is not.

Quote:
Originally Posted by chaley View Post
Question: for most formatter calls the newline() function won't do anything because the result has all contiguous white space converted to a single blank. It is then stripped. For example the template result "\nA \r\t\n B " becomes "A B". I am thinking of changing that behavior for GPM templates (but not SFM templates), removing the conversion-to-one-blank step. If I do then the above string would become "A \r\t\n B" (the leading and trailing whitespace is stripped but internal whitespace is not modified). I could also do strip(' '), removing leading & trailing blanks but leaving other whitespace intact. In this case the example result would be "\nA \r\t\n B" This change would make the newline() function generally usable and would permit formatting using tabs. (Of course that would require adding a tab() function.)

It is possible that someone has GPM templates that depend on the current callapse-white-space behavior, but I think the chances are very low, and in any event the template can be changed not to depend on collapsing spaces together.

I lean toward removing collapsing internal white space and stripping only blanks. What do you think?

BTW: the above change would mean you don't need to set strip_results because it would still do the strip() that you are doing.
Sounds very good to me.

Quote:
Originally Posted by chaley View Post
Another thought: instead of newline() why not have character('name') where 'name' is the letter used in the escape? That lets us add more characters without risk of breaking things or needing to introduce more functions.

We could adapt names from the python standard escape sequence table.
Code:
\\ - backslash
\' - quote (')
\" - double_quote (")
\b - backspace
\n - newline (LF)
\r - return (CR)
\t - tab (TAB)
Examples:
Code:
character('newline') returns '\n'
character('return') returns '\r'
character('tab') returns '\t'
character('backspace') returns '\b'
character('backslash') returns '\\'
That is definitely much better.
Attached Thumbnails
Click image for larger version

Name:	2.png
Views:	249
Size:	69.4 KB
ID:	186719  
capink is offline   Reply With Quote