해당 .cc 파일을 열 때 .h에서 프로토 타입 함수를 자동으로 삽입하도록 emacs를 어떻게 구성합니까?Emacs에서 .h의 프로토 타입 함수를 자동으로 삽입
답변
내가 멤버-기능 패키지를 사용하여 더 많은 C++ 코딩을 수행 할 때 내가이 일에 사용되는 것과 같은 것을 가지고
(require 'member-function)
;;expand member functions automatically when entering a cpp file
(defun c-file-enter()
"Expands all member functions in the corresponding .h file"
(let* ((c-file (buffer-file-name (current-buffer)))
(h-file-list (list (concat (substring c-file 0 -3) "h")
(concat (substring c-file 0 -3) "hpp")
(concat (substring c-file 0 -1) "h")
(concat (substring c-file 0 -1) "hpp"))))
(if (or (equal (substring c-file -2) ".c")
(equal (substring c-file -4) ".cpp"))
(mapcar (lambda (h-file)
(if (file-exists-p h-file)
(expand-member-functions h-file c-file)))
h-file-list))))
(add-hook 'c++-mode-hook c-file-enter)
당신은에서 회원-functions.el을 찾을 수 있습니다 : http://www.emacswiki.org/emacs/member-functions.el
난 당신이 CEDET의 상원 의원 "복사 태그"로 autoinsert
패키지를 결합 할 수 있다고 생각하지만,이 파일, 그것의 힘 구문 분석을 열 몇 elisp 프로그래밍을 필요로하고 반복하는 기능 이상의 태그 ...
비록 전체를 .h로 복사하고 싶다면 elisp도 포함되지만 더 쉬울 것입니다. auto-insert
함수를 통해 빈 파일을 삽입 한 다음 변수의 두 번째 요소 인 .h 파일 내용을 복사해야합니다 . 나는이 다시 잠시 해킹 쓴
(defun my-auto-insert-h-content()
(when buffer-file-name
(let ((h-filename (concat (file-name-sans-extension buffer-file-name) ".h")))
(when (file-exists-p h-filename)
(goto-char (point-min))
(insert-file-contents h-filename)))))
첫 번째 부분을 수행하는 방법에 대한 힌트를 좀 주시겠습니까? 이전에 lisp을 사용 했으므로 매크로를 작성하는 데 신경 쓰지 않아도됩니다. – Mark
https://github.com/alexott/emacs-configs/blob/master/rc/emacs-rc-auto-insert에서 설정을 살펴보십시오. .el - 템플릿 파일 (my가 https://github.com/alexott/emacs-configs/tree/master/auto-insert에 있음)과 함수로 구성된 cons에 파일 마스크 매핑을 제공해야합니다. 템플릿 파일을 새 파일에 삽입 한 후 실행 ... –
가 큰 아니다 ...하지만 출발점이 될 수있다 : 함수 뭔가처럼 보일 것이다. 이를 사용하려면 함수 구현을 삽입 할 .cc
파일에서 시작하여 .h
파일로 전환하고 함수 정의로 이동 한 다음 M-x my-c-make-function-from-prototype
으로 이동합니다. 물론 키에 바인딩되어 있습니다.
(require 'ffap)
(defun my-c-make-function-from-prototype()
"Turn a function prototype into a skeleton implementation."
(interactive)
(let (ret-val fcn-name args const namespaces start-of-fcn)
(save-excursion
(end-of-line)
(c-beginning-of-statement 1)
(beginning-of-line)
(when (re-search-forward
"\\s-*\\(.*\\)\\s-+\\([-a-zA-Z0-9_!=<>~]+\\)\\s-*[(]" nil t)
(setq ret-val (match-string 1))
(setq ret-val (replace-regexp-in-string "\\(virtual\\|static\\)\\s-*" "" ret-val))
(setq fcn-name (match-string 2))
(when (re-search-forward "\\([^)]*\\)[)]" nil t)
(setq args (match-string 1))
(setq args (replace-regexp-in-string "\\s-*=.+?," "," args))
(setq args (replace-regexp-in-string "\\s-*=.+?)" ")" args))
(setq args (replace-regexp-in-string "\\s-*=.+?$" "" args))
(if (looking-at "\\s-*const")
(setq const " const")
(setq const ""))
(condition-case nil
(while 't
(backward-up-list 1)
(when (re-search-backward
"\\(class\\|namespace\\|struct\\)\\s-+\\([a-zA-Z0-9_]+\\)" nil t)
(setq namespaces (concat (match-string 2) "::" namespaces))))
(error nil)))))
;; Switch to other file and insert implementation
(ff-get-other-file)
(setq start-of-fcn (point))
(insert (concat ret-val (unless (string= ret-val "") "\n") namespaces fcn-name "(" args ")" const))
(insert "\n{\n/** @todo Fill in this function. */\n}\n")
(unless (eobp)
(insert "\n"))
(indent-region start-of-fcn (point) nil)
(goto-char start-of-fcn)
(when (fboundp 'doxymacs-insert-function-comment)
(doxymacs-insert-function-comment))))
- 1. 캔버스 컨텍스트에 프로토 타입 함수를 추가하는 방법
- 2. 프로토 타입 js가 사용자 정의 함수를 호출합니다.
- 3. 프로토 타입 함수를 다른 ID 요소
- 4. 프로토 타입
- 5. 프로토 타입
- 6. 프로토 타입
- 7. 프로토 타입
- 8. 프로토 타입
- 9. 프로토 타입
- 10. .h의 포인터가 자동으로 NULL로 설정됩니까?
- 11. 프로토 타입 modalbox resizeToContent
- 12. 함수 프로토 타입 선언
- 13. 프로토 타입 hide/show
- 14. 이 대 프로토 타입
- 15. jQuery/프로토 타입 충돌
- 16. Node.js 필요가있는 프로토 타입 상속
- 17. 자바 스크립트 - 프로토 타입
- 18. 프로토 타입 변환
- 19. 프로토 타입 선택자
- 20. PHP에서의 프로토 타입 상속
- 21. 전 인스턴스화 프로토 타입
- 22. 프로토 타입 메뉴
- 23. 프로토 타입 생성자 전화는
- 24. jQuery를 사용한 프로토 타입
- 25. 자바 스크립트 프로토 타입
- 26. 프로토 타입 - 테이블 셀
- 27. 프로토 타입 신경 네트워크
- 28. node.js의 프로토 타입 상속
- 29. JavaScript 프로토 타입 draggable
- 30. 프로토 타입 : 이전 개체로?
Erm 물론 매크로입니다. 하지만 당신은 정말로 "누가 그런 매크로를 썼는가?"라고 물어 본다고 생각합니다. 나는 개인적으로 * 가장 중요한 * 일을 도구에 맡기지 않았습니다. 나는 지금 가버 릴 것이다. –
@ 한스 패 탄트 (Hans Passant) : 툴에 대해 왜 나쁜 생각인지 설명해 주시겠습니까? 난 그냥 같은 함수를 반복해서 다시 입력하고 싶지 않습니다 ... 또한 유용한 매크로를 알고 있다면 당신은 저를 소스로 보낼 수 있습니까? 어쩌면 나는 그것을 나의 필요에 맞게 조금 수정할 수있다. – Mark
@Mark - Guess Hans는 잘라내어 붙여 넣기가 가능한 편집기가 있으므로 두 번 입력 할 필요가 없습니다. –