Mercurial > hg > xemacs-beta
comparison lisp/simple.el @ 3929:94ecba3ecd77
[xemacs-hg @ 2007-04-30 16:16:48 by stephent]
Improve echo area resizing. <87wszthlwi.fsf@uwakimon.sk.tsukuba.ac.jp>
author | stephent |
---|---|
date | Mon, 30 Apr 2007 16:16:52 +0000 |
parents | 6b2ef948e140 |
children | 38ef5a6da799 |
comparison
equal
deleted
inserted
replaced
3928:ab912e9a7ace | 3929:94ecba3ecd77 |
---|---|
4125 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)" | 4125 ;; "^Parsed [0-9]+ of [0-9]+ ([0-9]+%)" |
4126 ) | 4126 ) |
4127 "List of regular expressions matching messages which shouldn't be logged. | 4127 "List of regular expressions matching messages which shouldn't be logged. |
4128 See `log-message'. | 4128 See `log-message'. |
4129 | 4129 |
4130 Ideally, packages which generate messages which might need to be ignored | 4130 Adding entries to this list slows down messaging significantly. Wherever |
4131 should label them with 'progress, 'prompt, or 'no-log, so they can be | 4131 possible, messages which might need to be ignored should be labeled with |
4132 filtered by the log-message-ignore-labels." | 4132 'progress, 'prompt, or 'no-log, so they can be filtered by |
4133 log-message-ignore-labels." | |
4133 :type '(repeat regexp) | 4134 :type '(repeat regexp) |
4134 :group 'log-message) | 4135 :group 'log-message) |
4135 | 4136 |
4136 (defcustom log-message-ignore-labels | 4137 (defcustom log-message-ignore-labels |
4137 '(help-echo command progress prompt no-log garbage-collecting auto-saving) | 4138 '(help-echo command progress prompt no-log garbage-collecting auto-saving) |
4144 "The function to call to display echo area buffer." | 4145 "The function to call to display echo area buffer." |
4145 :type 'function | 4146 :type 'function |
4146 :group 'log-message) | 4147 :group 'log-message) |
4147 | 4148 |
4148 (defcustom undisplay-echo-area-function nil | 4149 (defcustom undisplay-echo-area-function nil |
4149 "The function to call to undisplay echo area buffer." | 4150 "The function to call to undisplay echo area buffer. |
4150 :type 'function | 4151 WARNING: any problem with your function is likely to result in an |
4151 :group 'log-message) | 4152 uninterruptible infinite loop. Use of custom functions is therefore not |
4153 recommended." | |
4154 :type '(choice (const nil) | |
4155 function) | |
4156 :group 'log-message) | |
4157 | |
4158 (defvar undisplay-echo-area-resize-window-allowed t | |
4159 "INTERNAL USE ONLY. | |
4160 Guards against `undisplay-echo-area-resize-window' infloops. | |
4161 Touch this at your own risk.") | |
4162 | |
4163 (defun undisplay-echo-area-resize-window () | |
4164 "Resize idle echo area window to `resize-minibuffer-idle-height'. | |
4165 If either `resize-minibuffer-idle-height' or `resize-minibuffer-mode' is nil, | |
4166 does nothing. If `resize-minibuffer-window-exactly' is non-nil, always resize | |
4167 to this height exactly, otherwise if current height is no larger than this, | |
4168 leave it as is." | |
4169 (when (default-value undisplay-echo-area-resize-window-allowed) | |
4170 (setq-default undisplay-echo-area-resize-window-allowed nil) | |
4171 (let* ((mbw (minibuffer-window)) | |
4172 (height (window-height mbw))) | |
4173 (with-boundp '(resize-minibuffer-idle-height) | |
4174 (and resize-minibuffer-mode | |
4175 (numberp resize-minibuffer-idle-height) | |
4176 (> resize-minibuffer-idle-height 0) | |
4177 (unless (if resize-minibuffer-window-exactly | |
4178 (= resize-minibuffer-idle-height height) | |
4179 (<= resize-minibuffer-idle-height height)) | |
4180 (enlarge-window (- resize-minibuffer-idle-height height) | |
4181 nil mbw)))) | |
4182 (setq-default undisplay-echo-area-resize-window-allowed t)))) | |
4152 | 4183 |
4153 ;;Subsumed by view-lossage | 4184 ;;Subsumed by view-lossage |
4154 ;; Not really, I'm adding it back by popular demand. -slb | 4185 ;; Not really, I'm adding it back by popular demand. -slb |
4155 (defun show-message-log () | 4186 (defun show-message-log () |
4156 "Show the \" *Message-Log*\" buffer, which contains old messages and errors." | 4187 "Show the \" *Message-Log*\" buffer, which contains old messages and errors." |
4233 erasing it from the echo area if it's currently displayed there. | 4264 erasing it from the echo area if it's currently displayed there. |
4234 If a message remains at the head of the message-stack and NO-RESTORE | 4265 If a message remains at the head of the message-stack and NO-RESTORE |
4235 is nil, it will be displayed. The string which remains in the echo | 4266 is nil, it will be displayed. The string which remains in the echo |
4236 area will be returned, or nil if the message-stack is now empty. | 4267 area will be returned, or nil if the message-stack is now empty. |
4237 If LABEL is nil, the entire message-stack is cleared. | 4268 If LABEL is nil, the entire message-stack is cleared. |
4269 STDOUT-P is ignored, except for output to stream devices. For streams, | |
4270 STDOUT-P non-nil directs output to stdout, otherwise to stderr. \(This is | |
4271 used only in case of restoring an earlier message from the stack.) | |
4238 | 4272 |
4239 Unless you need the return value or you need to specify a label, | 4273 Unless you need the return value or you need to specify a label, |
4240 you should just use (message nil)." | 4274 you should just use (message nil)." |
4241 (or frame (setq frame (selected-frame))) | 4275 (or frame (setq frame (selected-frame))) |
4242 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame))))) | 4276 (let ((clear-stream (and message-stack (eq 'stream (frame-type frame))))) |
4291 (run-hook-with-args 'remove-message-hook | 4325 (run-hook-with-args 'remove-message-hook |
4292 (car (car log)) (cdr (car log)))) | 4326 (car (car log)) (cdr (car log)))) |
4293 (setq log (cdr log))))) | 4327 (setq log (cdr log))))) |
4294 | 4328 |
4295 (defun append-message (label message &optional frame stdout-p) | 4329 (defun append-message (label message &optional frame stdout-p) |
4330 "Add MESSAGE to the message-stack, or append it to the existing text. | |
4331 LABEL is the class of the message. If it is the same as that of the top of | |
4332 the message stack, MESSAGE is appended to the existing message, otherwise | |
4333 it is pushed on the stack. | |
4334 FRAME determines the minibuffer window to send the message to. | |
4335 STDOUT-P is ignored, except for output to stream devices. For streams, | |
4336 STDOUT-P non-nil directs output to stdout, otherwise to stderr." | |
4296 (or frame (setq frame (selected-frame))) | 4337 (or frame (setq frame (selected-frame))) |
4297 ;; If outputting to the terminal, make sure output from anyone else clears | 4338 ;; If outputting to the terminal, make sure output from anyone else clears |
4298 ;; the left side first, but don't do it ourselves, otherwise we won't be | 4339 ;; the left side first, but don't do it ourselves, otherwise we won't be |
4299 ;; able to append to an existing message. | 4340 ;; able to append to an existing message. |
4300 (if (eq 'stream (frame-type frame)) | 4341 (if (eq 'stream (frame-type frame)) |
4301 (set-device-clear-left-side (frame-device frame) nil)) | 4342 (set-device-clear-left-side (frame-device frame) nil)) |
4302 ;; Add a new entry to the message-stack, or modify an existing one | |
4303 (let ((top (car message-stack))) | 4343 (let ((top (car message-stack))) |
4304 (if (eq label (car top)) | 4344 (if (eq label (car top)) |
4305 (setcdr top (concat (cdr top) message)) | 4345 (setcdr top (concat (cdr top) message)) |
4306 (push (cons label message) message-stack))) | 4346 (push (cons label message) message-stack))) |
4307 (raw-append-message message frame stdout-p) | 4347 (raw-append-message message frame stdout-p) |
4308 (if (eq 'stream (frame-type frame)) | 4348 (if (eq 'stream (frame-type frame)) |
4309 (set-device-clear-left-side (frame-device frame) t))) | 4349 (set-device-clear-left-side (frame-device frame) t))) |
4310 | 4350 |
4311 ;; Really append the message to the echo area. no fiddling with | 4351 ;; Really append the message to the echo area. No fiddling with |
4312 ;; message-stack. | 4352 ;; message-stack. |
4313 (defun raw-append-message (message &optional frame stdout-p) | 4353 (defun raw-append-message (message &optional frame stdout-p) |
4314 (unless (equal message "") | 4354 (unless (equal message "") |
4315 (let ((inhibit-read-only t)) | 4355 (let ((inhibit-read-only t)) |
4316 (with-current-buffer " *Echo Area*" | 4356 (with-current-buffer " *Echo Area*" |
4317 (insert-string message) | 4357 (insert-string message) |
4318 ;; (fill-region (point-min) (point-max)) | 4358 ;; #### This needs to be conditional; cf discussion by Stefan Monnier |
4319 (enlarge-window | 4359 ;; et al on emacs-devel in mid-to-late April 2007. One problem is |
4320 (- | 4360 ;; there is no known good way to guess whether the user wants to have |
4321 (ceiling | 4361 ;; the echo area height changed on him asynchronously, especially |
4322 (/ (- (point-max) (point-min)) | 4362 ;; after message display. |
4323 (- (window-width (minibuffer-window)) 1.0))) | 4363 ;; There is also a problem where Lisp backtraces get sent to the echo |
4324 (window-height (minibuffer-window))) | 4364 ;; area, thus maxing out the window height. Unfortunately, it doesn't |
4325 nil (minibuffer-window))) | 4365 ;; return to a reasonable size very quickly. |
4326 ;; Conditionalizing on the device type in this way is not that clean, | 4366 ;; It is not clear that echo area and minibuffer behavior should be |
4327 ;; but neither is having a device method, as I originally implemented | 4367 ;; linked as we do here. It's OK for now; at least this obeys the |
4328 ;; it: all non-stream devices behave in the same way. Perhaps | 4368 ;; minibuffer resizing conventions which seem a pretty good guess |
4329 ;; the cleanest way is to make the concept of a "redisplayable" | 4369 ;; at user preference. |
4330 ;; device, which stream devices are not. Look into this more if | 4370 (when resize-minibuffer-mode |
4331 ;; we ever create another non-redisplayable device type (e.g. | 4371 ;; #### interesting idea, unbearable implementation |
4332 ;; processes? printers?). | 4372 ;; (fill-region (point-min) (point-max)) |
4373 ;; | |
4374 ;; #### We'd like to be able to do something like | |
4375 ;; | |
4376 ;; (save-window-excursion | |
4377 ;; (select-window (minibuffer-window frame)) | |
4378 ;; (resize-minibuffer-window)))) | |
4379 ;; | |
4380 ;; but that can't work, because the echo area isn't a real window! | |
4381 ;; We should fix that, but this is an approximation, duplicating the | |
4382 ;; resize-minibuffer code. | |
4383 (let* ((mbw (minibuffer-window frame)) | |
4384 (height (window-height mbw)) | |
4385 (lines (ceiling (/ (- (point-max) (point-min)) | |
4386 (- (window-width mbw) 1.0))))) | |
4387 (and (numberp resize-minibuffer-window-max-height) | |
4388 (> resize-minibuffer-window-max-height 0) | |
4389 (setq lines (min lines | |
4390 resize-minibuffer-window-max-height))) | |
4391 (or (if resize-minibuffer-window-exactly | |
4392 (= lines height) | |
4393 (<= lines height)) | |
4394 (enlarge-window (- lines height) nil mbw))))) | |
4333 | 4395 |
4334 ;; Don't redisplay the echo area if we are executing a macro. | 4396 ;; Don't redisplay the echo area if we are executing a macro. |
4335 (if (not executing-kbd-macro) | 4397 (if (not executing-kbd-macro) |
4398 ;; Conditionalizing on the device type in this way isn't clean, but | |
4399 ;; neither is having a device method, as I originally implemented | |
4400 ;; it: all non-stream devices behave in the same way. Perhaps | |
4401 ;; the cleanest way is to make the concept of a "redisplayable" | |
4402 ;; device, which stream devices are not. Look into this more if | |
4403 ;; we ever create another non-redisplayable device type (e.g. | |
4404 ;; processes? printers?). | |
4336 (if (eq 'stream (frame-type frame)) | 4405 (if (eq 'stream (frame-type frame)) |
4337 (send-string-to-terminal message stdout-p (frame-device frame)) | 4406 (send-string-to-terminal message stdout-p (frame-device frame)) |
4338 (funcall redisplay-echo-area-function)))))) | 4407 (funcall redisplay-echo-area-function)))))) |
4339 | 4408 |
4340 (defun display-message (label message &optional frame stdout-p) | 4409 (defun display-message (label message &optional frame stdout-p) |
4341 "Print a one-line message at the bottom of the frame. First argument | 4410 "Print a one-line message at the bottom of the frame. First argument |
4342 LABEL is an identifier for this message. MESSAGE is the string to display. | 4411 LABEL is an identifier for this message. MESSAGE is the string to display. |
4343 Use `clear-message' to remove a labelled message. | 4412 Use `clear-message' to remove a labelled message. |
4413 STDOUT-P is ignored, except for output to stream devices. For streams, | |
4414 STDOUT-P non-nil directs output to stdout, otherwise to stderr. | |
4344 | 4415 |
4345 Here are some standard labels (those marked with `*' are not logged | 4416 Here are some standard labels (those marked with `*' are not logged |
4346 by default--see the `log-message-ignore-labels' variable): | 4417 by default--see the `log-message-ignore-labels' variable): |
4347 message default label used by the `message' function | 4418 message default label used by the `message' function |
4348 error default label used for reporting errors | 4419 error default label used for reporting errors |