2011-01-13 2 views
12

기본적으로 내가 원하는 것 *메시지* 버퍼는 새로운 메시지가 도착할 때 항상 맨 아래로 스크롤합니다.emacs에서 * Messages * 버퍼가 꼬리가되도록 설정할 수 있습니까?

그럴 수 있습니까?

나는 auto-revert-tail-mode을 찾았지만 파일을 방문하는 버퍼에서 작동합니다. 내가 메시지 버퍼에 그것을 시도 할 때 , 그것은 오류 튀어 :
auto-revert-tail-mode: This buffer is not visiting a file

+2

통해 수정합니다. 나는 너에게 충분하지 않니? –

+4

예, Emacs 23.2.1 이상에서 \ * Messages \ *는 EOF에서 수동으로 포인트를 이동시키지 않는 한 기본적으로 꼬리를 가집니다 (다시 꼬리 끌기 동작을 다시 시작 함). 'auto-revert-tail-mode'는 분명히 다른 것을 수행하는 것으로 보이지 않습니다. – phils

답변

8

프레임 당신은 아마 원하는 :

(defadvice message (after message-tail activate) 
    "goto point max after a message" 
    (with-current-buffer "*Messages*" 
    (goto-char (point-max)) 
    (walk-windows (lambda (window) 
        (if (string-equal (buffer-name (window-buffer window)) "*Messages*") 
         (set-window-point window (point-max)))) 
        nil 
        t))) 
+0

니스,하지만 walk-windows + 필터 대신'get-buffer-window-list'를 사용해야합니다. –

1

이 코드는 조금 잔인한 것 같다을하지만, 간단한 (goto-char (point-max)) 나를 위해 작동하지 않는 : 여러 들어

(defadvice message (after message-tail activate) 
    "goto point max after a message" 
    (with-current-buffer "*Messages*" 
    (goto-char (point-max)) 
    (let ((windows (get-buffer-window-list (current-buffer) nil t))) 
     (while windows 
     (set-window-point (car windows) (point-max)) 
     (setq windows (cdr windows)))))) 
+1

당신은 미스터 잭슨입니다. – Cheeso

+0

위의 양식은 산책 창을 사용하는 것이 나에게 더 우아 해 보입니다. –

+0

@ Nordlöw : 최소한 walk-windows 버전과 같이'(while windows ...)'가 더 낫습니다.'(mapc (lambda (w) (set-window-point w)))) 창)'. – ntc2

0

i는 23.3 실행하고 너무 많은 경우는 여전히 어디 내장 된 '솔루션'및 메시지 기능 나타나서에 orginal 한 defadvice t는 그것을 자르지 않았으므로 목록/토글/타이머 설정에서 코드를 래핑하고 멋지게 작동합니다 - 디버깅 할 때 더 이상 좌절감을 느끼지 마십시오!

(toggle-buffer-tail "*Messages*" "on") 

그것이 사람에게 유용 ..hope .. 일반의 I는 정말 그것을 사용하지만, 그래서 어떤 버퍼에서 작동합니다.

;alist of 'buffer-name/timer' items 
(defvar buffer-tail-alist nil) 
(defun buffer-tail (name) 
    "follow buffer tails" 
    (cond ((or (equal (buffer-name (current-buffer)) name) 
     (string-match "^ \\*Minibuf.*?\\*$" (buffer-name (current-buffer))))) 
     ((get-buffer name) 
     (with-current-buffer (get-buffer name) 
     (goto-char (point-max)) 
     (let ((windows (get-buffer-window-list (current-buffer) nil t))) 
      (while windows (set-window-point (car windows) (point-max)) 
     (with-selected-window (car windows) (recenter -3)) (setq windows (cdr windows)))))))) 

(defun toggle-buffer-tail (name &optional force) 
    "toggle tailing of buffer NAME. when called non-interactively, a FORCE arg of 'on' or 'off' can be used to to ensure a given state for buffer NAME" 
    (interactive (list (cond ((if name name) (read-from-minibuffer 
     (concat "buffer name to tail" 
     (if buffer-tail-alist (concat " (" (caar buffer-tail-alist) ")") "") ": ") 
    (if buffer-tail-alist (caar buffer-tail-alist)) nil nil 
      (mapcar '(lambda (x) (car x)) buffer-tail-alist) 
     (if buffer-tail-alist (caar buffer-tail-alist)))) nil))) 
    (let ((toggle (cond (force force) ((assoc name buffer-tail-alist) "off") (t "on")))) 
    (if (not (or (equal toggle "on") (equal toggle "off"))) 
     (error "invalid 'force' arg. required 'on'/'off'") 
     (progn 
     (while (assoc name buffer-tail-alist) 
      (cancel-timer (cdr (assoc name buffer-tail-alist))) 
      (setq buffer-tail-alist (remove* name buffer-tail-alist :key 'car :test 'equal))) 
     (if (equal toggle "on") 
      (add-to-list 'buffer-tail-alist (cons name (run-at-time t 1 'buffer-tail name)))) 
     (message "toggled 'tail buffer' for '%s' %s" name toggle))))) 

편집 : 변경된 기능은 그냥 버퍼 M->의 끝 부분에 포인트를 넣어 창

+0

고마워, 정확히 내가 무엇을 찾고 있었는지 :) –

+0

여기 github에 올려 놓으십시오. (단지 내 자신의 편의를 위해서) http://github.com/mbriggs/buffer-tail.el –

2

의 하단에 꼬리를 표시합니다. 수동으로 움직이지 않으면 그대로 남아있을 것입니다. IOW, 항상 꼬리를 보게 될 것입니다.

+2

확실히이 isn ' 사실 ... 그것은 내가 가지고있는 이맥 중 어떤 것에도 확실히 작동하지 않는다. –

+1

@nicferrier 네, 작동합니다. 의미에 대한 자세한 내용은 질문 아래의 다른 주석을 참조하십시오. 'point-max'에 포인트를 얻기 위해'M->'을 사용하고 다른 커서 이동 만 사용하면 안된다. – Drew

1

여기에 커서가 그 버퍼의 끝에있는 경우, 새로운 메시지가 도착해도이 유지 피터의/트레이의 솔루션

(defun modi/messages-auto-tail (&rest _) 
    "Make *Messages* buffer auto-scroll to the end after each message." 
    (let* ((buf-name "*Messages*") 
     ;; Create *Messages* buffer if it does not exist 
     (buf (get-buffer-create buf-name))) 
    ;; Activate this advice only if the point is _not_ in the *Messages* buffer 
    ;; to begin with. This condition is required; otherwise you will not be 
    ;; able to use `isearch' and other stuff within the *Messages* buffer as 
    ;; the point will keep moving to the end of buffer :P 
    (when (not (string= buf-name (buffer-name))) 
     ;; Go to the end of buffer in all *Messages* buffer windows that are 
     ;; *live* (`get-buffer-window-list' returns a list of only live windows). 
     (dolist (win (get-buffer-window-list buf-name nil :all-frames)) 
     (with-selected-window win 
      (goto-char (point-max)))) 
     ;; Go to the end of the *Messages* buffer even if it is not in one of 
     ;; the live windows. 
     (with-current-buffer buf 
     (goto-char (point-max)))))) 
(advice-add 'message :after #'modi/messages-auto-tail) 
관련 문제