Loading ...
Sorry, an error occurred while loading the content.

Re: [jasspa] template

Expand Messages
  • Bryan Schofield
    I can t explain your current problem, but I got to thinking about your original question about code snippets and came up with this as part the java editing
    Message 1 of 8 , Oct 20, 2006
    • 0 Attachment
      I can't explain your current problem, but I got to thinking about your original question about code snippets and came up with this as part the java editing package I'm working on. It's way to insert the contents of a file and perform arbitrary emf commands at the same time. Snippet files (as I call them) are placed in a snippets directory defined by %maje-snippets. The macro below, asks you to select a file then it inserts the contents executing any embedded emf.  Here is a snippet for adding a commons-logging "getLog" method to a class.

      ----- getlog.snp -----
      private Log getLog() {
          return LogFactory.getLog(this.getClass());
      }
      ;emf
      maje-insert-import "org.apache.commons.logging.Log"
      maje-insert-import "org.apache.commons.logging.LogFactory "
      ;endemf
      ----- end getlog.snp ----
      It inserts the text then executes the code between ;emf and ;endemf




      --------------------------------------------
      ; code snippets
      ; insert an arbitrary set of text and execute ME commands from
      ; a file. This macro prompts the user to select a snippet file (snp)
      ; , defaulting to the %maje-snippets directory.
      ; This file is loaded and inserted into the buffer. Any lines of text
      ; in the snippet between ";emf" and ":endemf" lines are considered
      ; executable code, and will be evaluated.
      ;
      ; ;emf/;endemf pairs can occur multiple times and at any location in the
      ; file.
      ; Example Snippet File:
      ;
      ; private Log getLog() {
      ;     return LogFactory.getLog (this.getClass());
      ; }
      ; ;emf
      ; maje-insert-import "org.apache.commons.logging.Log"
      ; maje-insert-import "org.apache.commons.logging.LogFactory"
      ; ;endemf
      ;
      define-macro maje-insert-snippet
          set-variable #l0 @ml61 "snippet" %maje-snippets
          set-variable #l1 $buffer-bname
          set-alpha-mark "~"
          !force 0 delete-buffer "*maje-snippet*"
          find-buffer "*maje-snippet*"
          insert-file #l0
          end-of-buffer
          insert-string "\n;endsnippet\n!emacro"
          beginning-of-buffer
          insert-string "0 define-macro maje-execute-snippet\n"
          !while &not &seq ";endsnippet" @wl
              !if &sin ";emf" @wl
                  !force search-buffer "eM" ";endemf"
              !else
                  beginning-of-line
                  insert-string "insert-string \""
                  end-of-line
                  insert-string "\\n\""
              !endif
              !force forward-line
          !done
          execute-buffer "*maje-snippet*"
          find-buffer #l1
          execute-named-command "maje-execute-snippet"
          restyle-buffer
          goto-alpha-mark "~"
          !force 0 delete-buffer "*maje-snippet*"
      !emacro

    • Steven Phillips
      Rick, You need to inform the hook that an abbreviation file is available, currently the hksql.emf has: set-variable .fhook-sql.setup ® /history/fhook/sql
      Message 2 of 8 , Oct 20, 2006
      • 0 Attachment
        Rick,

        You need to inform the hook that an abbreviation file is available, currently
        the hksql.emf has:

        set-variable .fhook-sql.setup ® "/history/fhook/sql" "ghix"
        set-variable .fhook-sql.setup-mask "aeghikmtux"

        Each of the "aeghikmtux" letters represents a feature supported by the hook,
        see the header in majormod.emf for a complete list of letters and their
        meaning. Missing from this list is 'b' for abbreviation support, so change
        the above to:

        set-variable .fhook-sql.setup ® "/history/fhook/sql" "bghix"
        set-variable .fhook-sql.setup-mask "abeghikmtux"

        And everything should work as expected. However this fix could cause problems
        when you next up-grade because you are editing the main, to reduce the risk I
        recommend you add the following line to your mysql.emf:

        set-variable .fhook-sql.setup-mask &cat .fhook-sql.setup-mask "b"

        restart ME, load an sql file and use major-mode-setup to enable it (you many
        need to restart ME for it to take effect).

        The reason this does not 'just work' is because the buffer hook support was
        never fully designed, its kind of evolved over 10+ years so its not as slick
        as perhaps it should be. This area probably needs an overhaul but time is not
        particularly agreeable to this.

        Steve

        > Subject: [jasspa] template
        > From: Rick Owen <rickowen@...>
        > Date: Friday, October 20, 2006, 12:18:37 PM
        > To: jasspa@yahoogroups.com
        >
        >
        > I tried to to set up an abbreviation file for sql, but I must be missing
        > something.  I created a file "sql.eaf" and placed in my user directory:
        >
        > C:\Documents and Settings\Rick Owen\Application Data\jasspa
        >
        >  
        >
        > I thought I would start simple so sql.eaf just includes the following lines:
        >
        >  
        >
        > if "if \p\rthen\rend if;\P"
        > el "else\r\p\P"
        > ei "if \p\rthen\relsif \p\rthen\rend if;\P"

        > when I try an abbreviation expansion I get the message: [Failed to find an expansion]
        >
        >  
        >
        > so then I tried the following:
        >
        > * copied sql.eaf to mysql.eaf in my user directory
        >
        > * copied sql.eaf to C:\Program Files\JASSPA\MicroEmacs\macros\
        >
        >  
        >
        > Neither of the above actions made any difference.
        >
        >  
        >
        > I am assuming that since .sql is already a major mode there is a hook for
        > loading the abbreviation file, so I didn't do anything in that respect.
        >
        >  
        >
        > Also, is there some place in the help that defines to meta-characters that
        > the abbreviation expansion recognizes?  I looked in several places and found
        > various bits and pieces about abbreviations, but nothing about their syntax.
        >
        >  
        >
        > Any help would be appreciated.
        >
        > Thanks,
        >
        > Rick.

        >
        > ----- Original Message ----
        > From: Bryan Schofield <schofield.bryan@...>
        > To: jasspa@yahoogroups.com
        > Sent: Monday, October 2, 2006 9:55:15 AM
        > Subject: Re: [jasspa] template

        >
        >
        > For simple code snippets I use abbrevs. See help on buffer-abbrev- file,
        > expand-abbrev, abbrev-list. Many languages already support abbrev mode by
        > default. By adding an languange .eaf file to your $user-path, ME should pick
        > it. For example, adding a cpp.eaf with your c++ abbrevs will make them
        > available to you when you're editing c++ files.

        > For complicated code snippets, like generating java getter and setters I
        > write little macros to do it. So that putting the cursor on a line that
        > defines property variable the macros know what the getters and setters
        > should be. For this, I usually record a macro, name it, and insert in a .emf
        > file for later use. See help on start-kbd-macro, end-kbd-macro,
        > name-kbd-macro, insert-macro, execute-named- command.

        > Cheers
        > -- bryan

        >
        > On 10/2/06, Rick Owen <rickowen@yahoo. com> wrote:
        >
        >
        >
        >
        > Is there a way to create code templates so that with a keystroke (or select
        > from a menu or whatever) I can insert a chunk of code.
        >
        >  
        >
        > Thanks,
        >
        > Rick.
        >  
        >

        >


        >

        >
        >
      • Rick Owen
        Steve, Thanks for your help on this -- I now can expand abbreviations. The only question I have now is where can I find a list of the meta-characters
        Message 3 of 8 , Oct 21, 2006
        • 0 Attachment
          Steve,

           

          Thanks for your help on this -- I now can expand abbreviations.  The only question I have now is where can I find a list of the "meta-characters" recognized by the abbreviation expansion process?  For example, I have used \p \r and \P in my abbreviations, but can only guess at what they mean.  I looked in abbrlist.emf and abbrev.emf, but didn't find any explanation there.

           

          Thanks,

          Rick.



          ----- Original Message ----
          From: Steven Phillips <bill@...>
          To: Rick Owen <jasspa@yahoogroups.com>
          Sent: Friday, October 20, 2006 3:50:29 PM
          Subject: Re[2]: [jasspa] template

          Rick,

          You need to inform the hook that an abbreviation file is available, currently
          the hksql.emf has:

          set-variable .fhook-sql.setup &reg "/history/fhook/ sql" "ghix"
          set-variable .fhook-sql.setup- mask "aeghikmtux"

          Each of the "aeghikmtux" letters represents a feature supported by the hook,
          see the header in majormod.emf for a complete list of letters and their
          meaning. Missing from this list is 'b' for abbreviation support, so change
          the above to:

          set-variable .fhook-sql.setup &reg "/history/fhook/ sql" "bghix"
          set-variable .fhook-sql.setup- mask "abeghikmtux"

          And everything should work as expected. However this fix could cause problems
          when you next up-grade because you are editing the main, to reduce the risk I
          recommend you add the following line to your mysql.emf:

          set-variable .fhook-sql.setup- mask &cat .fhook-sql.setup- mask "b"

          restart ME, load an sql file and use major-mode-setup to enable it (you many
          need to restart ME for it to take effect).

          The reason this does not 'just work' is because the buffer hook support was
          never fully designed, its kind of evolved over 10+ years so its not as slick
          as perhaps it should be. This area probably needs an overhaul but time is not
          particularly agreeable to this.

          Steve

          > Subject: [jasspa] template
          > From: Rick Owen <rickowen@yahoo. com>
          > Date: Friday, October 20, 2006, 12:18:37 PM
          > To: jasspa@yahoogroups. com
          >
          >
          > I tried to to set up an abbreviation file for sql, but I must be missing
          > something.  I created a file "sql.eaf" and placed in my user directory:
          >
          > C:\Documents and Settings\Rick Owen\Application Data\jasspa
          >
          >
           
          >
          > I thought I would start simple so sql.eaf just includes the following lines:
          >
          >  
          >
          > if "if \p\rthen\rend if;\P"
          > el "else\r\p\P"
          > ei "if \p\rthen\relsif \p\rthen\rend if;\P"

          > when I try an abbreviation expansion I get the message: [Failed to find an expansion]
          >
          >  
          >
          > so then I tried the following:
          >
          > * copied sql.eaf to mysql.eaf in my user directory
          >
          > * copied sql.eaf to C:\Program Files\JASSPA\ MicroEmacs\ macros\
          >
          >  
          >
          > Neither of the above actions made any difference.
          >
          >  
          >
          > I am assuming that since .sql is already a major mode there is a hook for
          > loading the abbreviation file, so I didn't do anything in that respect.
          >
          >  
          >
          > Also, is there some place in the help that defines to meta-characters
          that
          > the abbreviation expansion recognizes?  I looked in several places and found
          > various bits and pieces about abbreviations, but nothing about their syntax.
          >
          >  
          >
          > Any help would be appreciated.
          >
          > Thanks,
          >
          > Rick.

          >
          > ----- Original Message ----
          > From: Bryan Schofield <schofield.bryan@ gmail.com>
          > To: jasspa@yahoogroups. com
          > Sent: Monday, October 2, 2006 9:55:15 AM
          > Subject: Re: [jasspa] template

          >
          >
          > For simple code snippets I use abbrevs. See help on buffer-abbrev- file,
          > expand-abbrev, abbrev-list. Many languages already support abbrev mode by
          > default. By adding an languange .eaf file to your $user-path, ME should pick
          > it. For example,
          adding a cpp.eaf with your c++ abbrevs will make them
          > available to you when you're editing c++ files.

          > For complicated code snippets, like generating java getter and setters I
          > write little macros to do it. So that putting the cursor on a line that
          > defines property variable the macros know what the getters and setters
          > should be. For this, I usually record a macro, name it, and insert in a .emf
          > file for later use. See help on start-kbd-macro, end-kbd-macro,
          > name-kbd-macro, insert-macro, execute-named- command.

          > Cheers
          > -- bryan

          >
          > On 10/2/06, Rick Owen <rickowen@yahoo. com> wrote:
          >
          >
          >
          >
          > Is there a way to create code templates so that with a keystroke (or select
          > from a menu or whatever) I can insert a chunk of code.
          >
          >  
          >
          > Thanks,
          >
          > Rick.
          >  
          >

          >

          >

          >
          >


        • Steven Phillips
          Rick, See the help pages for buffer-abbrev-file and execute-string, Steve
          Message 4 of 8 , Oct 21, 2006
          • 0 Attachment
            Rick,

            See the help pages for buffer-abbrev-file and execute-string,

            Steve

            > Subject: [jasspa] template
            > From: Rick Owen <rickowen@...>
            > Date: Saturday, October 21, 2006, 3:09:08 PM
            > To: jasspa@yahoogroups.com
            >
            > Steve,
            >
            >  
            >
            > Thanks for your help on this -- I now can expand abbreviations.  The only
            > question I have now is where can I find a list of the "meta-characters"
            > recognized by the abbreviation expansion process?  For example, I have used
            > \p \r and \P in my abbreviations, but can only guess at what they mean.  I
            > looked in abbrlist.emf and abbrev.emf, but didn't find any explanation there.
            >
            >  
            >
            > Thanks,
            >
            > Rick.
            >


            >
            >
            > ----- Original Message ----
            > From: Steven Phillips <bill@...>
            > To: Rick Owen <jasspa@yahoogroups.com>
            > Sent: Friday, October 20, 2006 3:50:29 PM
            > Subject: Re[2]: [jasspa] template

            >
            >
            > Rick,

            > You need to inform the hook that an abbreviation file is available, currently
            > the hksql.emf has:

            > set-variable .fhook-sql.setup ® "/history/fhook/ sql" "ghix"
            > set-variable .fhook-sql.setup- mask "aeghikmtux"

            > Each of the "aeghikmtux" letters represents a feature supported by the hook,
            > see the header in majormod.emf for a complete list of letters and their
            > meaning. Missing from this list is 'b' for abbreviation support, so change
            > the above to:

            > set-variable .fhook-sql.setup ® "/history/fhook/ sql" "bghix"
            > set-variable .fhook-sql.setup- mask "abeghikmtux"

            > And everything should work as expected. However this fix could cause problems
            > when you next up-grade because you are editing the main, to reduce the risk I
            > recommend you add the following line to your mysql.emf:

            > set-variable .fhook-sql.setup- mask &cat .fhook-sql.setup- mask "b"

            > restart ME, load an sql file and use major-mode-setup to enable it (you many
            > need to restart ME for it to take effect).

            > The reason this does not 'just work' is because the buffer hook support was
            > never fully designed, its kind of evolved over 10+ years so its not as slick
            > as perhaps it should be. This area probably needs an overhaul but time is not
            > particularly agreeable to this.

            > Steve

            >> Subject: [jasspa] template
            >> From: Rick Owen <rickowen@yahoo. com>
            >> Date: Friday, October 20, 2006, 12:18:37 PM
            >> To: jasspa@yahoogroups. com
            >>
            >>
            >> I tried to to set up an abbreviation file for sql, but I must be missing
            >> something.  I created a file "sql.eaf" and placed in my user directory:
            >>
            >> C:\Documents and Settings\Rick Owen\Application Data\jasspa
            >>
            >>  
            >>
            >> I thought I would start simple so sql.eaf just includes the following lines:
            >>
            >>  
            >>
            >> if "if \p\rthen\rend if;\P"
            >> el "else\r\p\P"
            >> ei "if \p\rthen\relsif \p\rthen\rend if;\P"

            >> when I try an abbreviation expansion I get the message: [Failed to find an expansion]
            >>
            >>  
            >>
            >> so then I tried the following:
            >>
            >> * copied sql.eaf to mysql.eaf in my user directory
            >>
            >> * copied sql.eaf to C:\Program Files\JASSPA\ MicroEmacs\ macros\
            >>
            >>  
            >>
            >> Neither of the above actions made any difference.
            >>
            >>  
            >>
            >> I am assuming that since .sql is already a major mode there is a hook for
            >> loading the abbreviation file, so I didn't do anything in that respect.
            >>
            >>  
            >>
            >> Also, is there some place in the help that defines to meta-characters that
            >> the abbreviation expansion recognizes?  I looked in several places and found
            >> various bits and pieces about abbreviations, but nothing about their syntax.
            >>
            >>  
            >>
            >> Any help would be appreciated.
            >>
            >> Thanks,
            >>
            >> Rick.

            >>
            >> ----- Original Message ----
            >> From: Bryan Schofield <schofield.bryan@ gmail.com>
            >> To: jasspa@yahoogroups. com
            >> Sent: Monday, October 2, 2006 9:55:15 AM
            >> Subject: Re: [jasspa] template

            >>
            >>
            >> For simple code snippets I use abbrevs. See help on buffer-abbrev- file,
            >> expand-abbrev, abbrev-list. Many languages already support abbrev mode by
            >> default. By adding an languange .eaf file to your $user-path, ME should pick
            >> it. For example, adding a cpp.eaf with your c++ abbrevs will make them
            >> available to you when you're editing c++ files.

            >> For complicated code snippets, like generating java getter and setters I
            >> write little macros to do it. So that putting the cursor on a line that
            >> defines property variable the macros know what the getters and setters
            >> should be. For this, I usually record a macro, name it, and insert in a .emf
            >> file for later use. See help on start-kbd-macro, end-kbd-macro,
            >> name-kbd-macro, insert-macro, execute-named- command.

            >> Cheers
            >> -- bryan

            >>
            >> On 10/2/06, Rick Owen <rickowen@yahoo. com> wrote:
            >>
            >>
            >>
            >>
            >> Is there a way to create code templates so that with a keystroke (or select
            >> from a menu or whatever) I can insert a chunk of code.
            >>
            >>  
            >>
            >> Thanks,
            >>
            >> Rick.
            >>  
            >>

            >>

            >>

            >>
            >>


            >
            >
          Your message has been successfully submitted and would be delivered to recipients shortly.