매크로 정의
Aug 21 2020
구성 파일을 "모듈화"하는 중이며 elisp 매크로와 관련된 문제가 발생했습니다.
구성 모듈을 정의하는 방식으로 인해 다음과 같은 코드 블록이 생성되었습니다.
(with-eval-after-load (expand-file-name
"latex.el"
j/config-path)
(leader
:infix "o"
"e" '(ebib :which-key "ebib"))
(some-function x y z))
나는 그것을 많이 반복했기 때문에 더 읽기 쉬운 구성 파일을 갖도록 매크로를 정의하려고했습니다. elisp에서 처음으로 매크로를 작성했기 때문에 다음과 같은 결과를 얻었습니다.
(defmacro j/con-load (module &rest funcs)
"TODO doc goes here"
`(with-eval-after-load
(expand-file-name (concat ,module ".el" j/config-path))
funcs))
나는 그것을 부르려고 노력하고있다
(j/con-load "latex"
(leader
:infix "o"
"e" '(ebib :which-key "ebib"))
(some-function x y z))
하지만 작동하지 않습니다.
내가 여기서 뭘 잘못하고 있니?
답변
2 phils Aug 21 2020 at 09:55
M-x pp-macroexpand-last-sexp
당신의 친구입니다. 매크로가 확장되는 코드를 보여줍니다.
(with-eval-after-load
(expand-file-name
(concat "latex" ".el" j/config-path))
funcs)
Emacs가 funcs
라이브러리를로드 할 경우 (존재하지 않을 가능성이 있는) 변수를 평가하도록 지시합니다 ( </path/to/current/default-directory>/latex.el</value/of/j/config-path>
발생 가능성이 거의없는 것 같음).
@ q.undertow가 concat
사용법 을 다루었습니다 .
나머지, 당신은 아마 싶어 스플 라이스 당신 &rest
과 함께 확장 된 매크로에 인수를 ,@funcs
?
C-hig (elisp)Backquote
접합에 대한 자세한 내용은를 참조하십시오 .
3 q.undertow Aug 21 2020 at 09:02
한 가지 (그리고 다른 문제가 없다는 확신이 전혀 없습니다) expand-file-name
매크로 본문 의 호출 이 뒤섞입니다. 그것은해야한다
(expand-file-name (concat ,module ".el") j/config-path)
또한 매크로 확장시 연결을 평가할 수도 있습니다.
(expand-file-name ,(concat module ".el") j/config-path)
도움이 되었기를 바랍니다