From: Glenn Morris Date: Tue, 17 Sep 2013 07:39:54 +0000 (-0700) Subject: Add a major-mode for the *Messages* buffer X-Git-Tag: emacs-24.3.90~173^2^2~42^2~45^2~387^2~1590 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=90582f05bc41bb832716926be1593c66b8219151;p=emacs.git Add a major-mode for the *Messages* buffer Ref: http://lists.gnu.org/archive/html/emacs-devel/2010-02/msg00135.html * lisp/simple.el (messages-buffer-mode): New major mode. (messages-buffer): New function. * lisp/startup.el (normal-top-level): Switch mode of *Messages* buffer. * src/xdisp.c (message_dolog): If we create *Messages*, switch it to messages-buffer-mode. * lisp/emacs-lisp/ert.el (ert--force-message-log-buffer-truncation) (ert-run-test): Use `message-buffer' function. (ert--force-message-log-buffer-truncation): Ignore read-only. * lisp/help.el (view-echo-area-messages): Use `message-buffer' function. * lisp/mail/emacsbug.el (report-emacs-bug): Use `message-buffer' function. * lisp/gnus/gnus-util.el (gnus-message-with-timestamp-1): Use `message-buffer' function if available. Ignore read-only. * etc/NEWS: Mention this. --- diff --git a/etc/NEWS b/etc/NEWS index 7558fc53052..6042ed8bf5f 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -93,6 +93,10 @@ simply disabling Transient Mark mode does the same thing. ** `initial-buffer-choice' can now specify a function to set up the initial buffer. +** The *Messages* buffer is created in a new major mode `messages-buffer-mode', +and read-only. Code that might create the *Messages* buffer should +call the function `messages-buffer' to do so and set the mode. + ** `remember-notes' creates a buffer whose content is saved on kill-emacs. You may think of it as a *scratch* buffer whose content is preserved. In fact, it was designed as a replacement for *scratch* buffer and can diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 15afc3ad19e..ceae81b91e0 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,14 @@ +2013-09-17 Glenn Morris + + * simple.el (messages-buffer-mode): New major mode. + (messages-buffer): New function. + * startup.el (normal-top-level): Switch mode of *Messages* buffer. + * emacs-lisp/ert.el (ert--force-message-log-buffer-truncation) + (ert-run-test): Use `message-buffer' function. + (ert--force-message-log-buffer-truncation): Ignore read-only. + * help.el (view-echo-area-messages): Use `message-buffer' function. + * mail/emacsbug.el (report-emacs-bug): Use `message-buffer' function. + 2013-09-17 Stefan Monnier * subr.el (eval-after-load): Preserve evaluation order (bug#15389). diff --git a/lisp/emacs-lisp/ert.el b/lisp/emacs-lisp/ert.el index 98576687f3d..409e4faf4d5 100644 --- a/lisp/emacs-lisp/ert.el +++ b/lisp/emacs-lisp/ert.el @@ -785,7 +785,7 @@ This mainly sets up debugger-related bindings." "Immediately truncate *Messages* buffer according to `message-log-max'. This can be useful after reducing the value of `message-log-max'." - (with-current-buffer (get-buffer-create "*Messages*") + (with-current-buffer (messages-buffer) ;; This is a reimplementation of this part of message_dolog() in xdisp.c: ;; if (NATNUMP (Vmessage_log_max)) ;; { @@ -798,7 +798,8 @@ This can be useful after reducing the value of `message-log-max'." (end (save-excursion (goto-char (point-max)) (forward-line (- message-log-max)) - (point)))) + (point))) + (inhibit-read-only t)) (delete-region begin end))))) (defvar ert--running-tests nil @@ -818,7 +819,7 @@ Returns the result and stores it in ERT-TEST's `most-recent-result' slot." (setf (ert-test-most-recent-result ert-test) nil) (cl-block error (let ((begin-marker - (with-current-buffer (get-buffer-create "*Messages*") + (with-current-buffer (messages-buffer) (point-max-marker)))) (unwind-protect (let ((info (make-ert--test-execution-info @@ -837,7 +838,7 @@ Returns the result and stores it in ERT-TEST's `most-recent-result' slot." (ert--run-test-internal info)) (let ((result (ert--test-execution-info-result info))) (setf (ert-test-result-messages result) - (with-current-buffer (get-buffer-create "*Messages*") + (with-current-buffer (messages-buffer) (buffer-substring begin-marker (point-max)))) (ert--force-message-log-buffer-truncation) (setq should-form-accu (nreverse should-form-accu)) diff --git a/lisp/gnus/ChangeLog b/lisp/gnus/ChangeLog index fc8ff9fd695..2889ead69ed 100644 --- a/lisp/gnus/ChangeLog +++ b/lisp/gnus/ChangeLog @@ -1,3 +1,8 @@ +2013-09-17 Glenn Morris + + * gnus-util.el (gnus-message-with-timestamp-1): + Use `message-buffer' function if available. Ignore read-only. + 2013-09-16 Katsumi Yamaoka * message.el (message-expand-group, message-completion-in-region): diff --git a/lisp/gnus/gnus-util.el b/lisp/gnus/gnus-util.el index 1d2ab2da248..4f63f4bdbc0 100644 --- a/lisp/gnus/gnus-util.el +++ b/lisp/gnus/gnus-util.el @@ -514,11 +514,14 @@ but also to the ones displayed in the echo area." (> message-log-max 0) (/= (length str) 0)) (setq time (current-time)) - (with-current-buffer (get-buffer-create "*Messages*") + (with-current-buffer (if (fboundp 'messages-buffer) + (messages-buffer) + (get-buffer-create "*Messages*")) (goto-char (point-max)) - (insert ,timestamp str "\n") - (forward-line (- message-log-max)) - (delete-region (point-min) (point)) + (let ((inhibit-read-only t)) + (insert ,timestamp str "\n") + (forward-line (- message-log-max)) + (delete-region (point-min) (point))) (goto-char (point-max)))) str) (gnus-add-timestamp-to-message diff --git a/lisp/help.el b/lisp/help.el index 4ec0b99a593..c21d5b8c1d1 100644 --- a/lisp/help.el +++ b/lisp/help.el @@ -1,7 +1,6 @@ ;;; help.el --- help commands for Emacs -;; Copyright (C) 1985-1986, 1993-1994, 1998-2013 Free Software -;; Foundation, Inc. +;; Copyright (C) 1985-1986, 1993-1994, 1998-2013 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: help, internal @@ -412,7 +411,7 @@ With argument, display info only for the selected version." The number of messages retained in that buffer is specified by the variable `message-log-max'." (interactive) - (with-current-buffer (get-buffer-create "*Messages*") + (with-current-buffer (messages-buffer) (goto-char (point-max)) (display-buffer (current-buffer)))) diff --git a/lisp/mail/emacsbug.el b/lisp/mail/emacsbug.el index c1bc7e2e1ab..e045519e850 100644 --- a/lisp/mail/emacsbug.el +++ b/lisp/mail/emacsbug.el @@ -1,7 +1,7 @@ ;;; emacsbug.el --- command to report Emacs bugs to appropriate mailing list -;; Copyright (C) 1985, 1994, 1997-1998, 2000-2013 Free Software -;; Foundation, Inc. +;; Copyright (C) 1985, 1994, 1997-1998, 2000-2013 +;; Free Software Foundation, Inc. ;; Author: K. Shane Hartman ;; Maintainer: FSF @@ -160,7 +160,7 @@ Prompts for bug subject. Leaves you in a mail buffer." (report-emacs-bug-can-use-osx-open))) user-point message-end-point) (setq message-end-point - (with-current-buffer (get-buffer-create "*Messages*") + (with-current-buffer (messages-buffer) (point-max-marker))) (compose-mail report-emacs-bug-address topic) ;; The rest of this does not execute if the user was asked to diff --git a/lisp/simple.el b/lisp/simple.el index 593f36d1ee1..54630681a68 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -7344,6 +7344,18 @@ and setting it to nil." buffer-invisibility-spec) (setq buffer-invisibility-spec nil))) +(define-derived-mode messages-buffer-mode special-mode "Messages" + "Major mode used in the \"*Messages*\" buffer.") + +(defun messages-buffer () + "Return the \"*Messages*\" buffer. +If it does not exist, create and it switch it to `messages-buffer-mode'." + (or (get-buffer "*Messages*") + (with-current-buffer (get-buffer-create "*Messages*") + (messages-buffer-mode) + (current-buffer)))) + + ;; Minibuffer prompt stuff. ;;(defun minibuffer-prompt-modification (start end) diff --git a/lisp/startup.el b/lisp/startup.el index ec7d73306a2..059d7710320 100644 --- a/lisp/startup.el +++ b/lisp/startup.el @@ -1,7 +1,6 @@ ;;; startup.el --- process Emacs shell arguments -*- lexical-binding: t -*- -;; Copyright (C) 1985-1986, 1992, 1994-2013 Free Software Foundation, -;; Inc. +;; Copyright (C) 1985-1986, 1992, 1994-2013 Free Software Foundation, Inc. ;; Maintainer: FSF ;; Keywords: internal @@ -494,6 +493,7 @@ It is the default value of the variable `top-level'." (setq command-line-processed t) (let ((dir default-directory)) (with-current-buffer "*Messages*" + (messages-buffer-mode) ;; Make it easy to do like "tail -f". (set (make-local-variable 'window-point-insertion-type) t) ;; Give *Messages* the same default-directory as *scratch*, diff --git a/src/ChangeLog b/src/ChangeLog index b4ec77780e4..00b59e89e67 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2013-09-17 Glenn Morris + + * xdisp.c (message_dolog): If we create *Messages*, + switch it to messages-buffer-mode. + 2013-09-17 Paul Eggert Don't overuse 'const' in types of locals. diff --git a/src/xdisp.c b/src/xdisp.c index 4582002fa0e..b07aad51bc9 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -1,7 +1,6 @@ /* Display generation from window structure and buffer text. -Copyright (C) 1985-1988, 1993-1995, 1997-2013 Free Software Foundation, -Inc. +Copyright (C) 1985-1988, 1993-1995, 1997-2013 Free Software Foundation, Inc. This file is part of GNU Emacs. @@ -9538,7 +9537,20 @@ message_dolog (const char *m, ptrdiff_t nbytes, bool nlflag, bool multibyte) old_deactivate_mark = Vdeactivate_mark; oldbuf = current_buffer; - Fset_buffer (Fget_buffer_create (Vmessages_buffer_name)); + + /* Ensure the Messages buffer exists, and switch to it. + If we created it, set the major-mode. */ + { + int newbuffer = 0; + if (NILP (Fget_buffer (Vmessages_buffer_name))) newbuffer = 1; + + Fset_buffer (Fget_buffer_create (Vmessages_buffer_name)); + + if (newbuffer && + !NILP (Ffboundp (intern ("messages-buffer-mode")))) + call0 (intern ("messages-buffer-mode")); + } + bset_undo_list (current_buffer, Qt); oldpoint = message_dolog_marker1;