2010-04-24 2 views
8

이 리스프 구문의 적절한 용어조차 모르겠다. 그래서 나는 질문을하기 위해 사용하는 단어가 의미가 있는지 알지 못한다. 그러나 문제는 당연한 것입니다.emacs : 매크로에 정의 된 코드에 edebug를 사용하려면 어떻게해야합니까?

그럼 알려 드리겠습니다. cc-mode (cc-fonts.el)에는 "matchers"라는 것이 있습니다.이 코드는 코드 영역의 글꼴을 지정하는 방법을 결정하는 코드입니다. 그렇게 간단 하긴하지만, matcher 코드는 backticks와 comma-atsign 및 쉼표만으로는 완전히 이해할 수없는 형태이며, 또한 c-lang-defcost에 내장되어 있습니다. 매크로. 모든 것을 호출해야할지 모르겠지만 그 코드에서 edebug를 실행하고 싶습니다.

봐 : 나는 코멘트를 다음 코드에 edebug를 실행할 수있는 내가 그 제외하고 그들을 부르지 만, 무엇을 그 일이 무엇을 알아 내기 위해 LISP 구문에 독서하고

(c-lang-defconst c-basic-matchers-after 
    "Font lock matchers for various things that should be fontified after 
generic casts and declarations are fontified. Used on level 2 and 
higher." 

    t `(;; Fontify the identifiers inside enum lists. (The enum type 
     ;; name is handled by `c-simple-decl-matchers' or 
     ;; `c-complex-decl-matchers' below. 
     ,@(when (c-lang-const c-brace-id-list-kwds) 
      `((,(c-make-font-lock-search-function 
       (concat 
       "\\<\\(" 
       (c-make-keywords-re nil (c-lang-const c-brace-id-list-kwds)) 
       "\\)\\>" 
       ;; Disallow various common punctuation chars that can't come 
       ;; before the '{' of the enum list, to avoid searching too far. 
       "[^\]\[{}();,/#=]*" 
       "{") 
       '((c-font-lock-declarators limit t nil) 
        (save-match-data 
        (goto-char (match-end 0)) 
        (c-put-char-property (1- (point)) 'c-type 
             'c-decl-id-start) 
        (c-forward-syntactic-ws)) 
        (goto-char (match-end 0))))))) 

, 그게 ;; Fontify the identifiers inside enum lists.입니까?

defun에서 edebug를 실행하는 방법을 알고 있습니다. 함수의 정의 내에서 edebug-defun을 호출하면됩니다. cc-mode matcher 코드 형식을 편집하기 위해해야 ​​할 일이 있습니까?

def-edebug-spec의 기능은 무엇입니까? 여기에서 사용하겠습니다. 그렇다면 어떻게?

답변

4

(elisp)Top > Debugging > Edebug > Edebug and Macros에 따르면 매크로를 디버그하는 방법을 debug 문으로 정의하거나 def-edebug-spec을 사용하여 Edebug에 알려줘야합니다. 이것은 평가되어야하는 매개 변수와 그렇지 않아야하는 매개 변수를 알려줍니다. 그렇게 할 수 있습니다. 사실 edebug에 이미 c-lang-defconst이 장착 된 것처럼 보입니다. 여기에 당신이 관심이 경우 정의는 다음과 같습니다 그러나

(def-edebug-spec c-lang-defconst 
    (&define name [&optional stringp] [&rest sexp def-form])) 

, 당신은 단지 신체가로 평가 무엇을보고 싶다면, 그렇게 할 수있는 다음 방법은 결과를 보려면 아래 macro-expand-last-sexp 같은 것을 사용하는 것입니다. 확장하려는 sexp 다음에 커서를 놓고 (C-x C-e처럼) M-x macro-expand-last-sexp RET을 실행하십시오. 그러면 확장 된 내용이 표시됩니다. ,(....)과 같은 것을 확장하려고하면 문제가 생길 수 있으므로 해당 섹스를 다른 곳으로 복사하고 , 또는 ,@을 삭제해야 할 수 있습니다.

(defun macro-expand-last-sexp (p) 
    "Macro expand the previous sexp. With a prefix argument 
insert the result into the current buffer and pretty print it." 
    (interactive "P") 
    (let* 
     ((sexp (preceding-sexp)) 
     (expanded (macroexpand sexp))) 
    (cond ((eq sexp expanded) 
      (message "No changes were found when macro expanding")) 
      (p 
      (insert (format "%S" expanded)) 
      (save-excursion 
      (backward-sexp) 
      (indent-pp-sexp 1) 
      (indent-pp-sexp))) 
      (t 
      (message "%S" expanded))))) 

나는 당신이하려는 일에 달려 있다고 생각합니다.

+0

오랜 시간이 지났지 만, edebug가 백틱 매크로 (')와 인라이닝을위한 특수 구조 (,,)를 올바르게 처리한다고 생각합니다. 정의 내에서 부 표현식에 대해서만 edebug를 사용하는 방법은 없습니다. 대신, 당신은 defun 또는 top-level 표현 전체를 계측해야합니다. – dlaliberte

4

또는 macroexpand-all을 사용하면 매크로 프리 코드로 전환하고 평소대로 디버그 할 수 있습니까?

역 따옴표은 ​​& 공동 최적 예에 의해 예시 될 수있다 :

(let ((a 1) 
     (b (list 2 3))) 
    `(a ,a ,b ,@b)) 
-> (a 1 (2 3) 2 3) 

백틱 (또는 역 인용 `)의 효과를 선택적으로 되돌릴 수있는 것을 제외하고는, 평가를 방지한다는 점에서 인용 (')과 유사한 쉼표 (,); ,@,과 같지만 목록이어야하는 인수가 결과 목록에 연결됩니다.

관련 문제