General XMetaL Discussion
XMetaL Community Forum › General XMetaL Discussion › Looking for Script to toggle capitalization
-
ghkrause November 24, 2008 at 11:57 pm
Looking for Script to toggle capitalization
November 24, 2008 at 11:57 pmParticipants 6Replies 7Last Activity 14 years, 4 months agoHello,
anyone eager to share her/his script on toggling capitalization. I would expect that prior to calling the script the cursor is within an element (may include inline tags) or some text is selected (even across element boundaries. The 4 capitalization modes are:
a) lowercase “block diagram of two counters”
b) sentence case “Block diagram of two counters”
c) title case “Block Diagram Of Two Counters”
d) upper case “BLOCK DIAGRAM OF TWO COUNTERS”
Case c would be skipped if only one word is present. The current case is evaluated:
IF second letter is uppercase THEN d)
ELSEIF first letter is lowercase THEN a)
ELSEIF first letter of second word is lowercase THEN b)
ELSE c)
A competing editor in the market offers such a function out of the box …mag3737 November 25, 2008 at 2:15 am
Reply to: Looking for Script to toggle capitalization
November 25, 2008 at 2:15 amOnce the script has concluded which case is currently assigned to the element, what is the behavior that it performs? Does it change case to the next in order on the list of four, or does it ask you which case to change to? (Or something else?)
sandvik November 25, 2008 at 4:03 pm
Reply to: Looking for Script to toggle capitalization
November 25, 2008 at 4:03 pm> c) title case “Block Diagram Of Two Counters”
Title case for this should be “Block Diagram of Two Counters”,
at least for US English. “A” and “of” and “the” and many other
little words are not capitalized unless leading the title.I implemented conversion of sentence case to title case
recently in XSL 2.0 (which doesn't translate to
.NET macros terribly well). You can use an external file of “little
words” that are not capitalized unless leading a title. Look up
each word to see if it should be capitalized. It's still a
heuristic. For example, if the doc includes Java or C API
names, NameOfItem is not the same as nameOfItem and
the conversion will mangle these unless you list every
lower-cased API name in the little-words file.– Craig
dcramer November 26, 2008 at 5:26 am
Reply to: Looking for Script to toggle capitalization
November 26, 2008 at 5:26 amI'd be content with the functionality you get in emacs:
Ctrl-u: Make the current word uppercase, starting where the cursor is. So if you have foobar and the cursor is on the b, you end up with fooBAR. If you have “foobar baz” with the cursor on the f and hit Ctrl+u twice, you have “FOOBAR BAZ”
Ctrl+c: Capitalize the current word. So if you have foobar and the cursor is on the b, you end up with fooBar. If you have “foobar baz” with the cursor on the f and hit Ctrl+c twice, you have “Foobar Baz”
Ctrl-l: Make the current word lowercase, starting where the cursor is. So if you have FOOBAR and the cursor is on the B, you end up with FOObar. If you have “FOOBAR BAZ” with the cursor on the f and hit Ctrl+l twice, you have “foobar baz”
ghkrause November 26, 2008 at 9:40 pm
Reply to: Looking for Script to toggle capitalization
November 26, 2008 at 9:40 pmSeems that my use case was not made clear. There should be [u]a single hotkey[/u] (not 3 as with emacs) [u]that cycles the capitalization[/u] of
– the selected text or
– the whole node if no character is selected but cursor is inside a tag and no punctuation marks
– the text between two punctuation marks prior and after cursor position.
After 4 key strokes all is back to the start (in case the text was following one of the capitalization rules already. The text the macro was operating on should be selected after each run to highlight what is thougt to be the sentence to operate on in case the keystroke is hit again.
Problem with title case: Well understood. [u]But I want to be pragmatic.[/u] Without a simple code I have to do all manually. Correcting “Of” to “of” isn't that difficult. We are [u]not[/u] talking of mass correction of content in elementwhich should be handled by a perfect XSLT handling all exceptions.
[u]My target:[/u] simple and short code (KISS) + real support for the person coping with a monotonous task.
Thank you for your patience trying to understand my issue 🙂Derek Read November 26, 2008 at 10:26 pm
Reply to: Looking for Script to toggle capitalization
November 26, 2008 at 10:26 pmI happen to have such a demo script. I will post it when I get a moment to clean it up and place it in the XMetaL Tips and Tricks section.
It may not do exactly what you are asking for here, but it would probably at least get you started.
ghkrause November 26, 2008 at 10:30 pm
Reply to: Looking for Script to toggle capitalization
November 26, 2008 at 10:30 pmCool!
I am looking forward to your sample code.
Anyone else??Derek Read November 28, 2008 at 1:26 am
Reply to: Looking for Script to toggle capitalization
November 28, 2008 at 1:26 amI've posted the example here:
[url=http://forums.xmetal.com/index.php?topic=73.0]http://forums.xmetal.com/index.php?topic=73.0[/url] -
AuthorPosts
- You must be logged in to reply to this topic.