+ Reply to Thread
Page 2 of 12 FirstFirst 1234 ... LastLast
Results 11 to 20 of 120

Thread: Subcode.vdm : The Macro Subroutines Project

  1. #11
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi Peter,

    Sorry about the problems you encountered. It was not the fault of the subroutines, just wrote that macro too quickly. The attached should work as advertised. You use the ESC key to exit and the enter key to select. You will notice a message on the status line saying as much.

    The macro is designed only to open files in user_macro\vdmhelp. For a more general file open macro, use the keyopen.vdm in subcode2.zip or use one of Pauli's excellent macros.

    Scott
    Attached Files Attached Files
    Last edited by Scott Lambert; October 26th, 2015 at 04:14 PM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  2. #12
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    312
    Quote Originally Posted by Scott Lambert View Post
    Hi Peter,

    Sorry about the problems you encountered. It was not the fault of the subroutines, just wrote that macro too quickly. The attached should work as advertised. You use the ESC key to exit and the enter key to select. You will notice a message on the status line saying as much.

    The macro is designed only to open files in user_macro\vdmhelp. For a more general file open macro, use the keyopen.vdm in subcode2.zip or use one of Pauli's excellent macros.

    Scott
    Hi Scott,

    Thanks for the new macro. I shall download it and get back to you later

    You refer to Pauli's excellent macros. I am using his Execute Highlighted Buffer macro. I no longer remember the exact reference. Here is that I have on my user-mnu.:

    2
    Execute The Highlighted Macro in the current buffer.
    Reg_Copy_Block(100,Block_Begin,Block_End) Call(100)

    Thanks as always.

    -peter

  3. #13
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi Peter,

    I missed this post until now:

    //
    // "USER_MENU" Deletes EXTRA(path) from FILENAME & puts result to T reg 85.
    // Chooses a .mnu file without extension name & puts the result into the T reg 84.
    // Then it sets the USER_MENU configuration string to this name.

    //
    :USER_MENU:
    Get_Filename(89,`"|(USER_MACRO)\user-mnu\*.mnu"`) //Get by point and shoot an .mnu file
    // and place it into T-reg 89.
    Reg_Load(124,@89) //Load the content of T-Reg 89 into the "{USER}" register.
    Buf_Switch(20)
    Reg_Set(90,`"`) // Place the quotation charecter into T-reg 90.
    Reg_Set(90,@89,APPEND) // Append T-reg 89 to T-reg 90. In other words prepand the " character.
    Reg_Set(90,`"`,APPEND) // Finally append the " character to the T-reg 90.
    File_Open(@90) // Open the file whose complete file name is in T_Reg 90.
    Reg_Set(91,FILE_ONLY) // Put the FILE_ONLY predefined string into T-Reg 91.
    // In other words, delete extension.
    File_Close(NOMSG) // Close this file.
    Buf_Close(20) // Close this buffer.
    Reg_Set(85,"&U-")
    Reg_Set(85,@91,APPEND)
    Config_String(USER_MENU,@85)
    Return

    Nice macro. Attached is a version that uses subcode.vdm. Notice how much smaller it is.

    Scott
    Attached Files Attached Files
    Last edited by Scott Lambert; October 31st, 2015 at 09:07 AM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  4. #14
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi,

    The attached subcode4.zip includes the regdiv subroutine. Regdiv performs floating point division and divides #11 by #10 and returns answer in t-reg 20. Number of decimal places can be set via #12, default is 8. Regdiv does proper standard rounding. T-reg 20 will be empty if division by zero is attempted.

    Scott
    Attached Files Attached Files
    Last edited by Scott Lambert; October 31st, 2015 at 10:18 AM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  5. #15
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    312

    Another proposed subroutine.

    Quote Originally Posted by Scott Lambert View Post
    Hi Peter,

    I missed this post until now:

    //
    // "USER_MENU" Deletes EXTRA(path) from FILENAME & puts result to T reg 85.
    // Chooses a .mnu file without extension name & puts the result into the T reg 84.
    // Then it sets the USER_MENU configuration string to this name.

    //
    :USER_MENU:
    Get_Filename(89,`"|(USER_MACRO)\user-mnu\*.mnu"`) //Get by point and shoot an .mnu file
    // and place it into T-reg 89.
    Reg_Load(124,@89) //Load the content of T-Reg 89 into the "{USER}" register.
    Buf_Switch(20)
    Reg_Set(90,`"`) // Place the quotation charecter into T-reg 90.
    Reg_Set(90,@89,APPEND) // Append T-reg 89 to T-reg 90. In other words prepand the " character.
    Reg_Set(90,`"`,APPEND) // Finally append the " character to the T-reg 90.
    File_Open(@90) // Open the file whose complete file name is in T_Reg 90.
    Reg_Set(91,FILE_ONLY) // Put the FILE_ONLY predefined string into T-Reg 91.
    // In other words, delete extension.
    File_Close(NOMSG) // Close this file.
    Buf_Close(20) // Close this buffer.
    Reg_Set(85,"&U-")
    Reg_Set(85,@91,APPEND)
    Config_String(USER_MENU,@85)
    Return

    Nice macro. Attached is a version that uses subcode.vdm. Notice how much smaller it is.

    Scott
    Hi Scott,

    A big thank you for your subroutine. It sure simplified my macro.

    Now, I would like to submit another subroutine. Specifically, the one tht searches for a word. That is to say, for astring
    of letters.

    At first I thought that it is in the On-Line_Help. First I thought to try the Search"|W") command. However, here W stands for White Space. Then I found a macro/subroutine in Chapter 3 of the Macro Language Manual.

    The following is a slight adaptation:

    -------------------------------------------------------------------------------------

    Search("|A",ADVANCE)
    repeat (ALL)
    { if ((Cur_Char >= 'A' && Cur_Char <= 'Z') || (Cur_Char >= 'a' && Cur_Char <= 'z')) {Char(1)} else {break} }

    -----------------------------------------------------------------------------------------------

    Actually, it would be ice if you could copy other examples as well from the Manual. Most of the time they are simple, so your subroutine.vdm would have something for beginning vedit users as well.


    I simply copied it from the Vedit Macro Language Manual Chapter 3. At the same time the ( ) string had to be replaced by the string, (). Similarly for the Logical or string, | | had to be replaced by ||. To automate this procedure, I edited the
    ClipclatchX.vdm. So, just use the {Misc. More Macros, Clipclatch} Menu command with the attache ClipclatchX.vdm.


    Happy Clipcatching.

    -peter

    OOPs, I forgot to rename ClipclatchX.vdm to ClipclatchX.txt

    I shall do it in my next message.
    Attached Files Attached Files

  6. #16
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi Peter,

    Here is the most generalized "simple" code to grab a word from the buffer:

    reg_empty(20)
    search("|A",noerr) // search for a letter
    if(return_value==0) {return}
    block_begin(cur_pos) // start block on letter
    search("|!|A",noerr) // search for non-letter
    if(return_value==0) {return}
    block_end(cur_pos) // end block on non-letter
    reg_block_copy(20,block_begin,block_end) // put word in t-reg 20

    if t-reg 20 is empty, no more words for your macro to process.

    Note the pattern matching code |! mean NOT, so |!|A means "not a letter".

    Reminder: search is case insenitive, unless you use the case parameter.

    Note: if above code is in a loop, you might want to change {return} to {break} in both cases.

    Now the above, if the buffer contains filenames, it will return the filename as a word and then the extension as a word, the code below tests if the non-letter is a dot followed by non-whitespace |!|W, if so, it searches for another non-letter, so it will return filename.ext as a single word.

    reg_empty(20)
    search("|A",noerr) // search for a letter
    if(return_value==0) {return} // if none
    block_begin(cur_pos) // start block on letter
    search("|!|A",noerr) // search for non-letter
    if(return_value==0) {return} // if none
    match(".|!|W",noerr) // match a dot followed by non-whitespace
    if(return_value==0) { // if found, do
    char(1) // advance off dot
    search("|!|A",noerr) // search for another non-letter
    if(return_value==0) {char(-1)} // if not found go back one character
    }
    block_end(cur_pos) // end block on non-letter
    reg_block_copy(20,block_begin,block_end) // put word in t-reg 20

    Note: if above code is in a loop, you might want to change {return} to {break} in both cases.

    You could add more code for other non-letters such as the underscore (so, you would grab words like reg_set, call_file) or the apostrophe(so you would grab words like Peter's, Scott's, it's).

    And that does not even consider that the macro will grab the word ten, but not 10. As you can see it gets complex really fast.

    I have written the code off the cuff on the forum (no testing), so sorry in advance for typos / errors in the code.

    Scott
    Last edited by Scott Lambert; November 4th, 2015 at 10:26 AM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  7. #17
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    312
    Quote Originally Posted by Scott Lambert View Post
    Hi Peter,

    Here is the most generalized "simple" code to grab a word from the buffer:

    reg_empty(20)
    search("|A",noerr) // search for a letter
    if(return_value==0) {return}
    block_begin(cur_pos) // start block on letter
    search("|!|A",noerr) // search for non-letter
    if(return_value==0) {return}
    block_end(cur_pos) // end block on non-letter
    reg_block_copy(20,block_begin,block_end) // put word in t-reg 20

    if t-reg 20 is empty, no more words for your macro to process.

    Note the pattern matching code |! mean NOT, so |!|A means "not a letter".

    Reminder: search is case insenitive, unless you use the case parameter.

    Note: if above code is in a loop, you might want to change {return} to {break} in both cases.

    Now the above, if the buffer contains filenames, it will return the filename as a word and then the extension as a word, the code below tests if the non-letter is a dot followed by non-whitespace |!|W, if so, it searches for another non-letter, so it will return filename.ext as a single word.

    reg_empty(20)
    search("|A",noerr) // search for a letter
    if(return_value==0) {return} // if none
    block_begin(cur_pos) // start block on letter
    search("|!|A",noerr) // search for non-letter
    if(return_value==0) {return} // if none
    match(".|!|W",noerr) // match a dot followed by non-whitespace
    if(return_value==0) { // if found, do
    char(1) // advance off dot
    search("|!|A",noerr) // search for another non-letter
    if(return_value==0) {char(-1)} // if not found go back one character
    }
    block_end(cur_pos) // end block on non-letter
    reg_block_copy(20,block_begin,block_end) // put word in t-reg 20

    Note: if above code is in a loop, you might want to change {return} to {break} in both cases.

    You could add more code for other non-letters such as the underscore (so, you would grab words like reg_set, call_file) or the apostrophe(so you would grab words like Peter's, Scott's, it's).

    And that does not even consider that the macro will grab the word ten, but not 10. As you can see it gets complex really fast.

    I have written the code off the cuff on the forum (no testing), so sorry in advance for typos / errors in the code.

    Scott
    Hi Scotts,

    Thanks for generalizing the Macro Language example that I have sent you.

    Now, I wold like to give you my motivation. Specifically, I would like to adapt your Extract_Latex_Commands.vdm to the case of the Berry definition of a type (a) Latex Command. This says that a Latex Command is the backslash character followed by a string of letters. When I asked for that macro, I was not aware of the Berry definition. In fact I was not aware of any definition. You did a great job of guessing that definition. In short, your macro was searching for a latex command with the help of the Search("|S") Vedit command. In other words, once you found the backslash you did look for the first separator.

    Now I would like to test whether the stuff after the backslash is a word or not.

    At first I thought that I would replace your Search("|S") by the macro that I have found in the Manual. In the meantime, I have learned on my own that
    "As you can see it gets complex really fast."

    In short, I would appreciate if you would do this replacement for me.

    PS. I am also thinking about automating/partially automating the task of extracting Vedit Commands from various files.
    This is my pseudo code. Search the file for words and then use the Command_Check command to check whether the word is a Vedit command. Oops. This works for the argument of a Vedit Command. The command checks whether the argument is a string or not. So, I was glad to read in your message that Reg_Set is not a word ! So, the Word_Search subroutine will have to be generalized to include strings like Reg_Set.

    Philosophy: In the definition of a Vedit command the none letter character "_" did sneak in. In the defintion of a Latex Command the character "\" did sneak in.

    Thanks as always.

    -peter

    -peter
    Last edited by rejto12; November 4th, 2015 at 11:47 AM. Reason: corect typos

  8. #18
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    312
    Quote Originally Posted by Scott Lambert View Post
    Hi Peter,

    Here is the most generalized "simple" code to grab a word from the buffer:

    reg_empty(20)
    search("|A",noerr) // search for a letter
    if(return_value==0) {return}
    block_begin(cur_pos) // start block on letter
    search("|!|A",noerr) // search for non-letter
    if(return_value==0) {return}
    block_end(cur_pos) // end block on non-letter
    reg_block_copy(20,block_begin,block_end) // put word in t-reg 20

    if t-reg 20 is empty, no more words for your macro to process.

    Note the pattern matching code |! mean NOT, so |!|A means "not a letter".

    Reminder: search is case insenitive, unless you use the case parameter.

    Note: if above code is in a loop, you might want to change {return} to {break} in both cases.

    Now the above, if the buffer contains filenames, it will return the filename as a word and then the extension as a word, the code below tests if the non-letter is a dot followed by non-whitespace |!|W, if so, it searches for another non-letter, so it will return filename.ext as a single word.

    reg_empty(20)
    search("|A",noerr) // search for a letter
    if(return_value==0) {return} // if none
    block_begin(cur_pos) // start block on letter
    search("|!|A",noerr) // search for non-letter
    if(return_value==0) {return} // if none
    match(".|!|W",noerr) // match a dot followed by non-whitespace
    if(return_value==0) { // if found, do
    char(1) // advance off dot
    search("|!|A",noerr) // search for another non-letter
    if(return_value==0) {char(-1)} // if not found go back one character
    }
    block_end(cur_pos) // end block on non-letter
    reg_block_copy(20,block_begin,block_end) // put word in t-reg 20

    Note: if above code is in a loop, you might want to change {return} to {break} in both cases.

    You could add more code for other non-letters such as the underscore (so, you would grab words like reg_set, call_file) or the apostrophe(so you would grab words like Peter's, Scott's, it's).

    And that does not even consider that the macro will grab the word ten, but not 10. As you can see it gets complex really fast.

    I have written the code off the cuff on the forum (no testing), so sorry in advance for typos / errors in the code.

    Scott
    Hi Scott,

    I tested your macro. After correcting a totally harmless typo it ran like a charm. Here are the details:


    // Word_Find_Mark.vdm
    // By Scott Lambert2015-11-04.
    //
    //
    // USAGE: Finds and Marks a Word and puts it into T-Reg 20.
    //
    //
    reg_empty(20)
    search("|A",noerr) // search for a letter
    if(return_value==0) {return}
    block_begin(cur_pos) // start block on letter
    search("|!|A",noerr) // search for non-letter
    if(return_value==0) {return}
    block_end(cur_pos) // end block on non-letter
    //reg_block_copy(20,block_begin,block_end) // put word in t-reg 20
    reg_copy_block(20,block_begin,block_end) // put word in t-reg 20

    Now I have some questions:
    1.: Should it be a macro or a subroutine ?
    2.: I compared it to the one I sent you. I used the if-then-else Vedit statement. You do not use it. I have a hunch that Vedit has a built in special case. In any way, I would appreciate your commenting your line

    f(return_value==0) {return}

    3.: I used the option {break}. You use the option {return}. Actually, I took it from your macro, Extract_Latex_Command.vdm
    May be there {return} would be better too ?

    Now comes the main point:
    Could you replace Search("|S") in your Extract_Latex_Commands,vdm by the Word_Find_Mark.vdm/subroutine ?
    Actually, this is more delicate, since in the Extract...vdm the marking is seperate from Search("|S")

    Of course, my preference would be to combine the Search and Mark codes into a single Subroutine, as you have done.



    Thanks as always,

    -peter

  9. #19
    Senior Member
    Join Date
    Aug 2011
    Location
    British Columbia, Canada
    Posts
    383
    Hi Peter,

    Glad the code worked after correcting my typo.

    "1.: Should it be a macro or a subroutine ?"

    I would consider it a subroutine, or a code excerpt from a proposed future macro, or just a coding example. It is not a macro, because really to be useful, a complete macro must do something with the word in t-reg 20 and perhaps provide an user interface depending on purpose.

    "I would appreciate your commenting your line
    if(return_value==0) {return}
    "
    if(return_value==0) {return} // if character not found, return

    "3.: I used the option {break}. You use the option {return}. Actually, I took it from your macro, Extract_Latex_Command.vdm May be there {return} would be better too ?"

    If code is part of a subroutine, use return

    if code is part of a complete macro, and not a subroutine, you would want your macro to end execution as it is most likely at or near the end of file. Using return may be correct, really depends on the code.

    if code is in a loop, use break.

    In the code, I gave you in last message, I used "|!|A" to find the end of the word, however I could have used "|S" instead, and the code would have worked just as well. Scribe in its submacro getword.vdm uses the "|S". Getword.vdm performs basically the same function for Scribe as we are discussing.

    The one of the differences between using "|S" and "|!|A" is "|S" does not consider the underscore as a word separator, where as "|!|A" does. This is why Scribe considers things like reg_set and call_file as one word. If you used the "|S" in our code of the previous message, it too would grab stuff like reg_set and call_file.

    To do what I think you want, the code needs to be context sensitive, so I am thinking it should get the file extension of file in buffer via predefined string value ext_only.

    So, if the extension is vdm, the code would grab words with an underscore like call_file

    If the extension was tex, after finding a letter it would check if previous character was a \ In this case, would you want just the word in t-reg 20 or the \ and the word in t-reg 20 ??

    Other extensions (htm ?) could be added in the future.

    Comments?

    Scott
    Last edited by Scott Lambert; November 4th, 2015 at 05:24 PM.
    Using Vedit 6.21.3, (32 bit), dated 9/12/11 running on Windows 7 (64 bit).

  10. #20
    Senior Member
    Join Date
    Nov 2014
    Location
    Minneapolis, MN
    Posts
    312

    Back to Extract_Latex_Commands.vmd

    Hi Scott,

    "1.: Should it be a macro or a subroutine ?"

    >I would consider it a subroutine, or a code excerpt from a proposed future macro, or just a coding example.

    Great, so it is a subroutine.

    Then could you use it to streamline your previous macro Extract_Latex_Commands.vdm ?

    Just to be on the safe side, I am attaching your macro.

    ----------------------------------------------------------------------------------------------
    #10=buf_num
    #11=buf_free
    buf_switch(#11)
    file_open("|(user_home)\latex2e.txt")
    buf_switch(#10)
    goto_line(59)
    repeat(all) {
    search("* \",advance+noerr)
    if(return_value==0) {break}
    if(cur_line>=846) {break}
    block_begin(cur_pos)
    search("|S",noerr)
    if(return_value==0) {break}
    block_end(cur_pos)
    reg_copy_block(10,block_begin,block_end)
    buf_switch(#11)
    reg_ins(10)
    ins_newline(1)
    buf_switch(#10)
    }

    ----------------------------------------------------------------

    >It is not a >macro, because really to be useful, a complete macro must do something with the word in t-reg 20 and >perhaps provide >an user interface depending on purpose.

    >So, if the extension is vdm, the code would grab words with an underscore like call_file

    Yes, exactly. My bookkeeping was different. I wanted to make sure that the Latex version does not grab something like
    \Reg_Set. So, I was concentrating only on that issue. But if you can treat the vedit case as well, even better.

    >If the extension was tex, after finding a letter it would check if previous character was a \ In this case, would you want >just the word in t-reg 20 or the \ and the word in t-reg 20 ??

    My personal preference would be to keep the backslash.

    >Other extensions (htm ?) could be added in the future.
    At present my hands are full with .vdm and .tex
    Yes, I would like to treat other extensions as well. I believe it is the extension .texi; it stands for tex information and it is
    very close to a .txt file. In short, I expect that the adjustments will be really minor.

    >Comments ?

    Yes I have one. I would like to add a Statline_Message like "Yes this block is a possible command"
    to the macro. My reason is that your original macro was silent. Since these commands will be repeated fast,
    the message will be unreadable. Nevertheless, the flickering would reassure the user that macro is working.

    I accidentally erased your reference to your getword.vdm Scribe macro.Aha, so this is that I was missing.


    Thanks, as always.

    -peter

+ Reply to Thread

Posting Permissions

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