Results 1 to 14 of 14
  1. #1
    Lounger
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    I am working, these days, on API documents. It contains loads of parameter names for coding part.

    While doing formatting, we need to apply code text style to parameter names.

    Is it possible to create a macro, which can select all the parameter names and apply code text to them.

    In our documents, format for parameter name is: abc_xyz_hij_klm

    Parameters must contain "_" (underscore) in their name, so can we use this 'underscore" feature to create some macro.

    Waiting for the suggestions

    regards

  2. #2
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    This should be easy to do with a simple Edit > Replace. Can you confirm the EXACT format of the parameter names.
    • Will there always be four groups of letters with three underscores?
    • Will each group of letters always have exactly 3 characters?
    • Will the letters always be lowercase?
    • Will there ever be numbers or any other characters in the parameter names?
    For example you could use the wildcard find string [a-z]@_[a-z]@_[a-z]@_[a-z]@ to locate any four strings of lowercase characters with _ characters in between and replace them with the required style.

    [attachment=84520:Replace.png]
    Attached Images Attached Images

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    There's a problem: [a-z]@_[a-z]@_[a-z]@_[a-z]@ stops finding at the first character after the last underscore:

    [attachment=84521:x.png]

    instead of going to the end of the word. You could use <[a-z]@_[a-z]@_[a-z]@_[a-z]@> instead - < stands for the beginning of a word, and > for the end of a word.
    Attached Images Attached Images
    • File Type: png x.png (3.9 KB, 0 views)

  4. #4
    Lounger
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    Actually, there is no fixed format for parameter name.

    * it can be a group of any number of letters separated by underscore
    * letters can be in UPPERCASE or lowercase
    * special characters can also be used in between the string

    The one thing that is constant is underscore.

    Few examples for you :
    **p_p_port_data
    ICF_FAILURE
    no_of_timer_list
    p_encoded_buf [IN]

    Hope, this will clear out things about their naming structure

    regards
    abhilasha

  5. #5
    Plutonium Lounger
    Join Date
    Nov 2001
    Posts
    10,550
    Thanks
    0
    Thanked 7 Times in 7 Posts
    The parameter
    p_encoded_buf [IN]
    appears to include a SPACE in the parameter name, this could be really problematic.

    Also
    **p_p_port_data
    will cause a problem because word treats ** as a separate word.

    I cannot think of any generic algorithm that would find all of these, but not match on other things that might occur in your text.

  6. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    As Stuart indicates, it will be difficult to write a macro that correctly identifies all parameters. You may be better off providing an easy way to apply the code style to selected text, for example a custom toolbar button (in the Commands tab of Tools | Customize..., select the Styles category, then select the style in the list on the right and drag it to a convenient location on a toolbar) and/or a keyboard shortcut.

  7. #7
    WS Lounge VIP
    Join Date
    Mar 2006
    Location
    Maryland, USA
    Posts
    690
    Thanks
    17
    Thanked 66 Times in 56 Posts
    [quote name='HansV' post='782570' date='01-Jul-2009 07:11']As Stuart indicates, it will be difficult to write a macro that correctly identifies all parameters. You may be better off providing an easy way to apply the code style to selected text, for example a custom toolbar button (in the Commands tab of Tools | Customize..., select the Styles category, then select the style in the list on the right and drag it to a convenient location on a toolbar) and/or a keyboard shortcut.[/quote]
    If you have a separate list of all the codes, you could use a macro that proceeds through the list searching for and replacing it with the same thing in the desired character style. I believe I've seen such a macro offered by some one on this list. I use a commercial one though--I've only used it with regular words and so don't know if there might be problems with your strings.

    --What say the macro mavens?

    Pam
    Pam Caswell

  8. #8
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    If abhilasha can provide such a list, it shouldn't be hard to write a macro.

  9. #9
    Lounger
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

    extremely sorry for late reply.

    Please find attached the document in which I have placed different types of parameter names which I always come across while doing formatting and need to apply code text style on them.

    if anything else u require , regarding the format of the parameter names , kindly revert.

    regards
    abhilasha


    [quote name='HansV' post='782750' date='02-Jul-2009 18:42']If abhilasha can provide such a list, it shouldn't be hard to write a macro.[/quote]
    Attached Files Attached Files

  10. #10
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Try the macro in the attached text file. Always test on a copy of your document(s) first!
    Attached Files Attached Files

  11. #11
    Lounger
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ya, I checked it on one of the document.....but it still leaves the scope of scanning the document to check whether the style applied to all the parameter names.

    In bulleted sentences it dosnt work.

    when I run the macro, almost to all the parameter names some Code Text+Arial+kern.....style gets applied,
    then I select all the instances and then re-applies the Code Text.



    [quote name='HansV' post='783466' date='08-Jul-2009 12:57']Try the macro in the attached text file. Always test on a copy of your document(s) first![/quote]

  12. #12
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    Can you post a sample document in which the macro doesn't work the way you want?

  13. #13
    Lounger
    Join Date
    Mar 2009
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Here I am attaching a document.

    I have copied some text in Normal style. Now when I execute the macro, the text remains in Normal style.


    [quote name='HansV' post='783482' date='08-Jul-2009 15:10']Can you post a sample document in which the macro doesn't work the way you want?[/quote]
    Attached Files Attached Files

  14. #14
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    When I run the macro in your document, Code Text is applied where it should be. Only the p- in "p-buf [OUT]" is not formatted as Code Text because it does not meet the conditions that you gave us: it contains a hyphen - instead of an underscore _.

    [attachment=84602:x.png]
    Attached Images Attached Images
    • File Type: png x.png (3.0 KB, 0 views)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •