General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Looking for Script to toggle capitalization

  • ghkrause

    Looking for Script to toggle capitalization

    Participants 6
    Replies 7
    Last Activity 13 years, 7 months ago

    Hello,
    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 …

    Reply

    mag3737

    Reply to: Looking for Script to toggle capitalization

    Once 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?)

    Reply

    sandvik

    Reply to: Looking for Script to toggle capitalization

    > 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

    Reply

    dcramer

    Reply to: Looking for Script to toggle capitalization

    I'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”

    Reply

    ghkrause

    Reply to: Looking for Script to toggle capitalization

    Seems 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 element which should be handled by a perfect XSLT handling all exceptions.<br />[u]My target:[/u] simple and short code (KISS) + real support for the person coping with a monotonous task.<br />Thank you for your patience trying to understand my issue 🙂

    Reply

    Derek Read

    Reply to: Looking for Script to toggle capitalization

    I 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.

    Reply

    ghkrause

    Reply to: Looking for Script to toggle capitalization

    Cool!
    I am looking forward to your sample code.
    Anyone else??

    Reply

    Derek Read

    Reply to: Looking for Script to toggle capitalization

    I'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]

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support