Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

[Lisp] A macro that creates 2 functions?

Options
  • 29-11-2005 10:15pm
    #1
    Registered Users Posts: 1,865 ✭✭✭


    The following is from a lisp script written for emacs to make it easy to create skeletons and abbreviations.

    I created the following macro:
    (defmacro define-skeleton-abbrev (description abbreviation abbrev-table &rest skeleton)
      (let ((name-of-skeleton (gensym)))
        `((define-skeleton ,name-of-skeleton ,description "" ,@skeleton)
          (define-abbrev ,abbrev-table ,abbreviation "" (quote ,name-of-skeleton)))))
    

    Here is an example of it being used:
    (define-skeleton-abbrev 
        "Print System.out.println()" "sopn" global-abbrev-table
        "System.out.println(" _ ");")
    

    By using (macroexpand .. ), it's being expanded to:
    ((define-skeleton G62217 "Print System.out.println()" "" "System.out.println(" _ ");") (define-abbrev global-abbrev-table "sopn" "" (quote G62217)))
    

    Which Emacs does not like.

    If I remove on of the set of brackets from the let clause in the macro, I get only define-abbrev returned from the macro.

    How can I 'return' two functions from a macro?


Comments

  • Registered Users Posts: 1,865 ✭✭✭Syth


    I figure this one out on my own.

    I needed the (progn ..) function.

    Replacing the above with:
    (defmacro define-skeleton-abbrev (description abbreviation abbrev-table &rest skeleton)
      (let ((name-of-skeleton (gensym)))
        `(progn (define-skeleton ,name-of-skeleton ,description "" ,@skeleton)
          (define-abbrev ,abbrev-table ,abbreviation "" (quote ,name-of-skeleton)))))
    
    and it works like I want.


Advertisement