How to Create a Temporary Function in Emacs Lisp

前端 未结 3 1065
北海茫月
北海茫月 2020-12-16 10:56

I\'m making some tedious calls to a bunch of functions, but the parameters will be determined at runtime. I wrote a simple function to keep my code DRY but giving it a name

3条回答
  •  盖世英雄少女心
    2020-12-16 11:11

    You can do this the ANSI Common Lisp way (though I think there are some Emacs devels that will give you nasty looks):

    (flet ((do-work (x y z)
                    (do-x x)
                    (do-y y)
                    ;; etc
                    ))
      (cond (test-1 (do-work 'a 'b 'c))
            (test-2 (do-work 'i 'j 'k))))
    

    Dunno if you'll first have to (require 'cl) (or cl-macs?) to use flet. If you want to define recursive functions you'll need to use labels IIRC.

提交回复
热议问题