home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / misc / log-messages.el < prev    next >
Encoding:
Text File  |  1991-03-30  |  4.2 KB  |  121 lines

  1. ;From rpotter@grip.cis.upenn.edu Sun Nov  4 00:59:02 1990
  2. ;From: rpotter@grip.cis.upenn.edu (Robert Potter)
  3. ;Subject: Re: repeating last message
  4. ;Date: 18 Oct 90 23:31:00 GMT
  5. ;Organization: GRASP Lab
  6. ;Status: RO
  7. ;
  8. ;
  9. ;Douglis) writes:
  10. ;> to my knowledge, there's no way to get emacs to redisplay a message.
  11. ;> i saw some stuff in the elisp archive for "meshook", which saves
  12. ;> messages in a buffer, but it seems to rely on another package "hooks"
  13. ;> that isn't in the archive.  anyone have anything that saves/displays
  14. ;> old messages, or a pointer to "hooks"?
  15. ;
  16. ;
  17. ;I guess I'll take this opportunity to get around to posting this
  18. ;package I whipped up last month.  It's probably a reinvented wheel,
  19. ;but at least it seems to work well.
  20. ;
  21. ;    -Robert
  22. ;
  23.  
  24. ;; -*-Emacs-Lisp-*-
  25.  
  26. ;;; log-messages.el - facility to log the output of the "message" function.
  27. ;;; 
  28. ;;; Have you ever been frustrated by not being able to read an emacs message
  29. ;;; because it gets overwritten by another message?  Then this package is for
  30. ;;; you.  By setting the user variable "log-messages" to non-nil, you can have
  31. ;;; the messages logged for you in the buffer "*Message Log*".
  32. ;;; 
  33. ;;; The variable "non-logged-message-regexps" lets you filter out messages you
  34. ;;; know you don't want logged.  I'm not sure how useful this really is, but
  35. ;;; it's there if you want it.
  36. ;;; 
  37. ;;; Unfortunately, some messages you see in the minibuffer are not produced
  38. ;;; using the "message" function, so they will not be logged.
  39. ;;; 
  40. ;;; CAUTION: This file overwrites the function "message".
  41.  
  42. ;;; Copyright (C) 1990 Robert Potter.
  43. ;;;
  44. ;;; Author: Robert Potter (rpotter@grip.cis.upenn.edu)
  45. ;;;
  46. ;;; This program is free software; you can redistribute it and/or modify
  47. ;;; it under the terms of the GNU General Public License as published by
  48. ;;; the Free Software Foundation; either version 1, or (at your option)
  49. ;;; any later version.
  50. ;;;
  51. ;;; This program is distributed in the hope that it will be useful,
  52. ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  53. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  54. ;;; GNU General Public License for more details.
  55. ;;;
  56. ;;; A copy of the GNU General Public License can be obtained from this
  57. ;;; program's author or from the Free Software Foundation, Inc., 675 Mass Ave,
  58. ;;; Cambridge, MA 02139, USA.
  59.  
  60. (require 'cl)
  61. (provide 'log-messages)
  62.  
  63. ;;
  64. ;; user variables
  65. ;; 
  66.  
  67. (defvar log-messages t
  68.   "*If non-nil, the output of the \"message\" function will be logged in the
  69. buffer \"*Message Log*\".")
  70.  
  71. (defvar non-logged-message-regexps
  72.   '("Mark set"
  73.     "Undo!"
  74.     "\\(Failing \\|Wrapped \\)?I-search\\( backward\\)?: .*"
  75.     "I-search\\( backward\\)?: .*"
  76.     "(No changes need to be saved)"
  77.     "<<< Press Space to bury the buffer list >>>"
  78.     ""
  79.     "fill-prefix: \".*\""
  80.     "Type .* to restore old contents of help window\\."
  81.     "Type .* to continue editing\\.")
  82.   "*A list of regexps that match messages to leave out of the message log.
  83. For best efficiency, keep them in decreasing order of likelihood.")
  84.  
  85.  
  86. ;;
  87. ;; specific code
  88. ;;
  89.  
  90. ; save the old version of "message" in "message-no-log" before defining the new
  91. ; one
  92. (when (not (fboundp 'message-no-log))
  93.   (setf (symbol-function 'message-no-log)
  94.     (symbol-function 'message)))
  95.  
  96. (defun message (&rest ARGS)
  97.   "Print a one-line message at the bottom of the screen.
  98. The first argument is a control string.
  99. It may contain %s or %d or %c to print successive following arguments.
  100. %s means print an argument as a string, %d means print as number in decimal,
  101. %c means print a number as a single character.
  102. The argument used by %s must be a string or a symbol;
  103. the argument used by %d or %c must be a number.
  104.  
  105. This version will log the message in the buffer \"*Message Log*\" if the
  106. variable \"log-messages\" is non-nil.  Use \"message-no-log\" if you really
  107. want the old version."
  108.   (let ((msg (apply 'format ARGS)))
  109.     (when (and log-messages
  110.            (not (some (function (lambda (REGEXP)
  111.                       (and (eq 0 (string-match REGEXP msg))
  112.                        (= (match-end 0) (length msg)))))
  113.               non-logged-message-regexps)))
  114.       (save-excursion
  115.     (set-buffer (get-buffer-create "*Message Log*"))
  116.     (goto-char (point-max))
  117.     (insert msg ?\n)
  118.     (sit-for 0)))
  119.     (message-no-log "%s" msg)))
  120.  
  121.