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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

[Lisp] A macro that creates 2 functions?

  • 29-11-2005 9:15pm
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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