aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/simple.el
diff options
context:
space:
mode:
authorMiles Bader2000-10-06 11:35:56 +0000
committerMiles Bader2000-10-06 11:35:56 +0000
commitf69aad2bcb71e2d13fd60f2b462753c41da5a9da (patch)
treee7b7c412395a9d61952091bfe5edee44b85e075d /lisp/simple.el
parent06933804966c0f99e052f18f135b500c4535f6de (diff)
downloademacs-f69aad2bcb71e2d13fd60f2b462753c41da5a9da.tar.gz
emacs-f69aad2bcb71e2d13fd60f2b462753c41da5a9da.zip
(display-message-or-buffer): New function.
(shell-command-on-region): Use `display-message-or-buffer'.
Diffstat (limited to 'lisp/simple.el')
-rw-r--r--lisp/simple.el104
1 files changed, 68 insertions, 36 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 4ef45839d6e..51107e20a29 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -1215,6 +1215,63 @@ specifies the value of ERROR-BUFFER."
1215 (shell-command-on-region (point) (point) command 1215 (shell-command-on-region (point) (point) command
1216 output-buffer nil error-buffer))))))) 1216 output-buffer nil error-buffer)))))))
1217 1217
1218(defun display-message-or-buffer (message
1219 &optional buffer-name not-this-window frame)
1220 "Display MESSAGE in the echo area if possible, otherwise in a pop-up buffer.
1221MESSAGE may be either a string or a buffer.
1222
1223A buffer is displayed using `display-buffer' if MESSAGE is too long for
1224the maximum height of the echo area, as defined by `max-mini-window-height'.
1225
1226If MESSAGE is a string, then the optional argument BUFFER-NAME is the
1227name of the buffer used to display it in the case where a pop-up buffer
1228is used, defaulting to `*Message*'. In the case where MESSAGE is a
1229string and it is displayed in the echo area, it is not specified whether
1230the contents are inserted into the buffer anyway.
1231
1232Optional arguments NOT-THIS-WINDOW and FRAME are as for `display-buffer',
1233and only used if a buffer is displayed."
1234 (cond ((and (stringp message) (not (string-match "\n" message)))
1235 ;; Trivial case where we can use the echo area
1236 (message "%s" message))
1237 ((and (stringp message)
1238 (= (string-match "\n" message) (1- (length message))))
1239 ;; Trivial case where we can just remove single trailing newline
1240 (message "%s" (substring message 0 (1- (length message)))))
1241 (t
1242 ;; General case
1243 (with-current-buffer
1244 (if (bufferp message)
1245 message
1246 (get-buffer-create (or buffer-name "*Message*")))
1247
1248 (unless (bufferp message)
1249 (erase-buffer)
1250 (insert message))
1251
1252 (let ((lines
1253 (if (= (buffer-size) 0)
1254 0
1255 (count-lines (point-min) (point-max)))))
1256 (cond ((or (<= lines 1)
1257 (<= lines
1258 (cond ((floatp max-mini-window-height)
1259 (* (frame-height) max-mini-window-height))
1260 ((integerp max-mini-window-height)
1261 max-mini-window-height)
1262 (t
1263 1))))
1264 ;; Echo area
1265 (goto-char (point-max))
1266 (when (bolp)
1267 (backward-char 1))
1268 (message "%s" (buffer-substring (point-min) (point))))
1269 (t
1270 ;; Buffer
1271 (goto-char (point-min))
1272 (display-buffer message not-this-window frame))))))))
1273
1274
1218;; We have a sentinel to prevent insertion of a termination message 1275;; We have a sentinel to prevent insertion of a termination message
1219;; in the buffer itself. 1276;; in the buffer itself.
1220(defun shell-command-sentinel (process signal) 1277(defun shell-command-sentinel (process signal)
@@ -1345,42 +1402,17 @@ specifies the value of ERROR-BUFFER."
1345 nil shell-command-switch command))) 1402 nil shell-command-switch command)))
1346 (setq success (and exit-status (equal 0 exit-status))) 1403 (setq success (and exit-status (equal 0 exit-status)))
1347 ;; Report the amount of output. 1404 ;; Report the amount of output.
1348 (let ((lines (save-excursion 1405 (if (with-current-buffer buffer (> (point-max) (point-min)))
1349 (set-buffer buffer) 1406 ;; There's some output, display it
1350 (if (= (buffer-size) 0) 1407 (display-message-or-buffer buffer)
1351 0 1408 ;; No output; error?
1352 (count-lines (point-min) (point-max)))))) 1409 (message (if (and error-file
1353 (cond ((= lines 0) 1410 (< 0 (nth 7 (file-attributes error-file))))
1354 (if (and error-file 1411 "(Shell command %sed with some error output)"
1355 (< 0 (nth 7 (file-attributes error-file)))) 1412 "(Shell command %sed with no output)")
1356 (message "(Shell command %sed with some error output)" 1413 (if (equal 0 exit-status) "succeed" "fail"))
1357 (if (equal 0 exit-status) 1414 (kill-buffer buffer)))))
1358 "succeed" 1415
1359 "fail"))
1360 (message "(Shell command %sed with no output)"
1361 (if (equal 0 exit-status)
1362 "succeed"
1363 "fail")))
1364 (kill-buffer buffer))
1365 ((or (= lines 1)
1366 (<= lines
1367 (cond ((floatp max-mini-window-height)
1368 (* (frame-height) max-mini-window-height))
1369 ((integerp max-mini-window-height)
1370 max-mini-window-height)
1371 (t
1372 1))))
1373 (message "%s"
1374 (with-current-buffer buffer
1375 (goto-char (point-max))
1376 (when (bolp)
1377 (backward-char 1))
1378 (buffer-substring (point-min) (point)))))
1379 (t
1380 (save-excursion
1381 (set-buffer buffer)
1382 (goto-char (point-min)))
1383 (display-buffer buffer)))))))
1384 (when (and error-file (file-exists-p error-file)) 1416 (when (and error-file (file-exists-p error-file))
1385 (if (< 0 (nth 7 (file-attributes error-file))) 1417 (if (< 0 (nth 7 (file-attributes error-file)))
1386 (with-current-buffer (get-buffer-create error-buffer) 1418 (with-current-buffer (get-buffer-create error-buffer)