Call function in another lisp file

前端 未结 4 989
死守一世寂寞
死守一世寂寞 2021-01-15 17:26

I have to write a game in Lisp. In order to make it clear, I wanted to split the code in different .lisp files.

How can I call a function out of a function in the ot

4条回答
  •  天涯浪人
    2021-01-15 18:02

    This is for Emacs Lisp (aka elisp)

    Create a file at this location: ~/.emacs.d/init.el

    Create a file at this location: ~/.emacs.d/file1.el

    Create a file at this location: ~/.emacs.d/file2.el

    Now, open up ~/.emacs.d/init.el and write (and then save):

    (load "~/.emacs.d/file1.el")
    
    (load "~/.emacs.d/file2.el")
    
    (defun run-both-functions ()
      (interactive)
        (switch-to-buffer "*Messages*")
        (first-function)
        (sit-for 2)
        (second-function))
    

    Now, open up ~/.emacs.d/file1.el and write (and then save):

    (defun first-function ()
        (message "My name is Fred."))
    

    Now, open up ~/.emacs.d/file2.el and write (and then save):

    (defun second-function ()
        (message "My name is George."))
    

    Now, restart Emacs and type: M-x run-both-functions RET

    Any functions that you put into any of the three (3) files mentioned above will be accessible to other functions. You will note that run-both-functions includes an (interactive) statement, which means that the user can call the function with M-x or a keyboard shortcut.

提交回复
热议问题