2013-04-20 1 views
7

rgrep을 실행할 때 버퍼가 표시됩니다. 나는 내 결과를보고 싶다 - 다른 모든 정보는 나에게 무의미하다.emacs에서 rgrep/grep 출력의 헤더 정보를 제거 하시겠습니까?

-*- mode: grep; default-directory: "~/.emacs/" -*- 
Grep started at Sat Jan 20 12:42:21 

grep --exclude=.\#\* --exclude=\*.o --exclude=\*\~ --exclude=\*.bin --exclude=\*.lbin --exclude=\*.so --exclude=\*.a --exclude=\*.ln --exclude=\*.blg --exclude=\*.bbl --exclude=\*.elc --exclude=\*.lof --exclude=\*.glo --exclude=\*.idx --exclude=\*.lot --exclude=\*.fmt --exclude=\*.tfm --exclude=\*.class --exclude=\*.fas --exclude=\*.lib --exclude=\*.mem --exclude=\*.x86f --exclude=\*.sparcf --exclude=\*.dfsl --exclude=\*.pfsl --exclude=\*.d64fsl --exclude=\*.p64fsl --exclude=\*.lx64fsl --exclude=\*.lx32fsl --exclude=\*.dx64fsl --exclude=\*.dx32fsl --exclude=\*.fx64fsl --exclude=\*.fx32fsl --exclude=\*.sx64fsl --exclude=\*.sx32fsl --exclude=\*.wx64fsl --exclude=\*.wx32fsl --exclude=\*.fasl --exclude=\*.ufsl --exclude=\*.fsl --exclude=\*.dxl --exclude=\*.lo --exclude=\*.la --exclude=\*.gmo --exclude=\*.mo --exclude=\*.toc --exclude=\*.aux --exclude=\*.cp --exclude=\*.fn --exclude=\*.ky --exclude=\*.pg --exclude=\*.tp --exclude=\*.vr --exclude=\*.cps --exclude=\*.fns --exclude=\*.kys --exclude=\*.pgs --exclude=\*.tps --exclude=\*.vrs --exclude=\*.pyc --exclude=\*.pyo -i -nH -e grep *.el 

    init.el:236:(global-set-key (kbd "s-f") 'rgrep) 
    init.el:237:(global-set-key (kbd "C-f") 'lgrep) 

Grep finished (matches found) at Sat Jan 20 12:42:21 
+0

또는'''(추가 훅 '그렙 모드 - 후크 (내-그렙 모드 - 후크() (SETQ 잘라 내기 - 라인 t)를 DEFUN) : grep을 버퍼에 숨겨진 텍스트를 전환합니다 'my-grep-mode-hook)'을 사용하면 헤더 (및 다른 라인)는 랩핑하지 않으므로 눈에 띄지 않습니다. 래핑 된 선을보고 싶다면'toggle-truncate-lines'을 호출 할 수는 있습니다.하지만 그렇게 할 필요가 거의 없기 때문에이 접근법이 상당히 만족 스럽습니다. – phils

답변

10

헤더 삽입은 rgrep 내 깊은 compilation-start의 호출에 묻혀있다. 이러한 기능을 사용하여 헤더를 삽입하지 못하게하는 간단한 방법은 없습니다. 하지만 조언을 정의하여 버퍼의 처음 네 줄을 숨길 수 있습니다.

(defun delete-grep-header() 
    (save-excursion 
    (with-current-buffer grep-last-buffer 
     (goto-line 5) 
     (narrow-to-region (point) (point-max))))) 

(defadvice grep (after delete-grep-header activate) (delete-grep-header)) 
(defadvice rgrep (after delete-grep-header activate) (delete-grep-header)) 

나중에 C-X wN다시이 라인을 공개 확대 할 수 있습니다.

(defvar delete-grep-header-advice 
    (ad-make-advice 
    'delete-grep-header nil t 
    '(advice lambda() (delete-grep-header)))) 

(defun add-delete-grep-header-advice (function) 
    (ad-add-advice function delete-grep-header-advice 'after 'first) 
    (ad-activate function)) 

(mapc 'add-delete-grep-header-advice 
     '(grep lgrep grep-find rgrep zrgrep)) 
+0

나는이 파티에 매우 늦었지만,이 대답에 대해 1 톤을 감사한다! –

1

작은 또한 마이클 호프만의 대답 : 우리는 작은 버튼을 추가 할 수 있습니다 당신은 또한 lgrep, grep-findzrgrep 조언을하려면

, 당신은 프로그램은 다음과 같이 조언과 함께 위의 defadvice 매크로를 대체 할 수 있습니다

(defmacro with-grep-buffer-writable (&rest body) 
    `(save-excursion 
    (with-current-buffer grep-last-buffer 
     (setq buffer-read-only nil) 
     ,@body 
     (setq buffer-read-only t)))) 

(defun hide-grep-header (&rest ignored) 
    "Hides (by narrowing) the first few lines of a grep buffer leaving only 
the results. Additionally, a button is created to toggle the lines." 
    (with-grep-buffer-writable 
    ;;HACK: If we (goto-line 5), the button is inserted *after* the results. 
    (goto-line 4) 
    (end-of-line) 
    (insert "\n") 
    (narrow-to-region (point) (point-max)) 
    (insert-text-button "(...)" 
         'help-echo "Toggle display of grep invocation" 
         'action #'click-show-grep-button))) 

(defun click-hide-grep-button (button) 
    (with-grep-buffer-writable 
    (button-put button 'action #'click-show-grep-button) 
    (narrow-to-region (button-start button) (point-max)))) 

(defun click-show-grep-button (button) 
    (with-grep-buffer-writable 
    (button-put button 'action #'click-hide-grep-button) 
    (widen)) 
    ; HACK: goto-line won't have any effect because of save-excursion 
    (with-current-buffer grep-last-buffer 
    (goto-line 1))) 

(advice-add 'grep :after #'hide-grep-header) 
(advice-add 'rgrep :after #'hide-grep-header)