2010-02-05 7 views
6

작은 크기로 컴파일 버퍼의 자동 축소를 구현하고 싶지만 (창을 닫을 때는 닫지 않습니다) 창에 대한 컴파일이 성공하면 최소 크기로 축소됩니다.이맥스는 프로그래밍 방식으로 창 크기를 변경합니다.

get-buffer-create은 버퍼를 반환합니다. 해당 버퍼와 연결된 창에서 어떻게 shrink-window을 사용할 수 있습니까? 또한 이전 창 크기를 저장할 수있는 방법이 있습니까?

이맥스 isp 프로그래밍에 대한 나의 첫 번째 진출이다. 도움을 주셔서 감사합니다.

답변

8

이 문제를 해결하는 방법에는 두 가지가 있다고 생각합니다.

는 는 후크`컴파일 - 마무리 기능 '을 사용하는 것이다

편집 처리가 완료 될 때 호출 unctions [F 목록]. 각 함수는 컴파일 버퍼, 및 프로세스 완료 방법을 설명하는 문자열의 두 인수로 호출됩니다.

(add-hook 'compilation-finish-functions 'my-compilation-finish-function) 
(defun my-compilation-finish-function (buffer resstring) 
    "Shrink the window if the process finished successfully." 
    (let ((compilation-window-height (if (string-match-p "finished" resstring) 5 nil))) 
    (compilation-set-window-height (get-buffer-window buffer 0)))) 

내가 그 솔루션을 가지고있는 유일한 문제는 그것이 성공 문자열을 찾을 수에 의해 결정 결과 문자열에 "완료"할 수 있다는 가정이다 :이 같은 솔루션에 이르게

.

'compilation-handle-exit - 에 exit-status를 명시 적으로 전달하는 다른 방법이 있습니다. 나는 출구 상황이 0이 아닌 경우 이 창을 축소시키는이 충고를 썼다.

(defadvice compilation-handle-exit (around my-compilation-handle-exit-shrink-height activate) 
    (let ((compilation-window-height (if (zerop (car (ad-get-args 1))) 5 nil))) 
    (compilation-set-window-height (get-buffer-window (current-buffer) 0)) 
    ad-do-it)) 

참고 : 두 번째 컴파일을 할 때 *compilation* 윈도우가 계속 표시되면, 실패에 따라 더 큰 크기를 조정할 수 없습니다. 크기를 조정하려면 nil 대신 높이를 지정해야합니다.

(if (string-match-p "finished" resstring) 5 (/ (frame-height) 2)) 

nil(/ (frame-height) 2)

로 대체 : 아마도이 원하는대로 (첫 번째 예제를 변경)하는 것
관련 문제