2011-01-13 36 views
12

Về cơ bản tôi muốn *Tin nhắn* bộ đệm luôn cuộn xuống cuối khi có thư mới đến.Trong emacs, tôi có thể thiết lập bộ đệm * Tin nhắn * để nó có đuôi không?

Tôi có thể làm điều đó không?

Tôi tìm thấy auto-revert-tail-mode nhưng hoạt động đối với bộ đệm đang truy cập tệp. Khi tôi thử nó trong Tin nhắn của bộ đệm, nó xuất hiện một lỗi:
auto-revert-tail-mode: This buffer is not visiting a file

+2

Khi con trỏ là ở phần cuối của bộ đệm đó, nó sẽ nằm ở đó ngay cả khi có thư mới. Tôi lấy nó không đủ cho bạn? –

+4

Có, trong Emacs 23.2.1 ít nhất, \ * Tin nhắn \ * đuôi theo mặc định, trừ khi bạn di chuyển điểm thủ công từ EOF (và di chuyển nó trở lại một lần nữa tiếp tục hành vi tailing). 'auto-revert-tail-mode' dường như không làm bất cứ điều gì rõ ràng là khác nhau. – phils

Trả lời

8

Đối với nhiều khung hình bạn có thể muốn:

(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

Tốt, nhưng bạn nên sử dụng 'get-buffer-window-list' thay vì walk-windows + một bộ lọc. –

1

Mã này có vẻ hơi quá đáng chút, nhưng là một sự đơn giản (goto-char (point-max)) đã không làm việc cho tôi:

(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

bạn rất sung mãn, ông Jackson. – Cheeso

+0

Biểu mẫu ở trên sử dụng cửa sổ đi bộ dường như thanh lịch hơn với tôi. –

+0

@ Nordlöw: tối thiểu, '(trong khi windows ...)' ở đây được viết tốt hơn như trong phiên bản 'walk-windows':' (mapc (lambda (w) (set-window-point w (điểm-max))) cửa sổ) '. – ntc2

0

i chạy 23.3 và vẫn còn quá nhiều lần khi tích hợp 'giải pháp' và nhược điểm ban đầu trên chức năng tin nhắn t đã không cắt nó, vì vậy tôi bọc mã trong một danh sách/chuyển đổi/hẹn giờ thiết lập và nó làm việc đẹp - không có nhiều thất vọng khi gỡ lỗi!

nó chung chung, do hoạt động trên bất kỳ đệm, mặc dù tôi chỉ thực sự sử dụng nó cho ..

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

..hope nó là hữu ích để một ai đó.

;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))))) 

chỉnh sửa: thay đổi chức năng để hiển thị đuôi ở dưới cùng của cửa sổ

+0

Cảm ơn vì điều này, nó chính xác là những gì tôi đang tìm kiếm :) –

+0

đặt nó lên trên github ở đây (chỉ để thuận tiện cho riêng tôi) http://github.com/mbriggs/buffer-tail.el –

2

Chỉ cần đặt điểm vào cuối của bộ đệm M>. Nếu bạn không tự di chuyển nó, nó sẽ ở đó - IOW, bạn sẽ luôn thấy đuôi.

+2

Khá chắc chắn đây không phải là ' t đúng ... nó chắc chắn không hoạt động trên bất kỳ emacs tôi có xung quanh. –

+1

@nicferrier Có, nó hoạt động. Xem các bình luận khác theo câu hỏi để biết thêm chi tiết về ý nghĩa của nó. Hãy chắc chắn rằng bạn sử dụng 'M->' và không chỉ các chuyển động của con trỏ khác, để có được điểm tại 'điểm-max'. – Drew

1

Dưới đây là một sửa đổi trên '/ s Trey' giải pháp Peter s

(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) 
Các vấn đề liên quan