]> code.delx.au - gnu-emacs/blobdiff - lisp/simple.el
(turn-on-auto-fill): Mark it as an option for `text-mode-hook'.
[gnu-emacs] / lisp / simple.el
index 94cff99ee576145266d852e1bc41ca5626f28c89..18f8bc9a4b949205ebc0d546d6c90e5f07c63d7b 100644 (file)
@@ -1,6 +1,6 @@
 ;;; simple.el --- basic editing commands for Emacs
 
-;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 1998
+;; Copyright (C) 1985, 86, 87, 93, 94, 95, 96, 97, 98, 1999
 ;;        Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
@@ -517,29 +517,40 @@ Each language environment may show different external character components."
                     pos total percent beg end col hscroll)
          (message "point=%d of %d(%d%%)  column %d %s"
                   pos total percent col hscroll))
-      (let* ((coding-system buffer-file-coding-system)
-            (encoding
-             (encode-coding-string (char-to-string char) coding-system t))
-            (encoding-string-hex
-             (mapconcat (lambda (ch) (format "0x%x" ch)) encoding " "))
-            (encoding-msg
-             (if (and coding-system
-                              (not (and (= (length encoding) 1)
-                                        (= (aref encoding 0) char))))
-                 (format "(0%o, %d, 0x%x, ext %s)"
-                         char char char
-                         encoding-string-hex)
-               (format "(0%o, %d, 0x%x)"
-                       char char char))))
+      (let ((charset (char-charset char))
+           (coding-system buffer-file-coding-system)
+           slot external encoding-msg)
+       ;; To decided an external character code, we use
+       ;; charset-origin-alist property of buffer-file-coding-system.
+       ;; But, if buffer-file-coding-system is nil of undecided, use
+       ;; that property of default-buffer-file-coding-system.  If
+       ;; that property value is nil, we don't show external
+       ;; character code.
+       (if (or (not coding-system)
+               (eq (coding-system-type coding-system) t))
+           (setq coding-system default-buffer-file-coding-system))
+       (if (and coding-system
+                (setq slot
+                      (coding-system-get coding-system 'charset-origin-alist))
+                (setq slot (assq charset slot)))
+           (setq external (list (nth 1 slot) (funcall (nth 2 slot) char))))
+       (setq encoding-msg
+             (if external
+                 (format "(0%o, %d, 0x%x, ext 0x%x)"
+                         char char char (nth 1 external))
+               (format "(0%o, %d, 0x%x)" char char char)))
        (if detail
-           (let* ((internal (split-char char))
-                  (charset (char-charset char))
-                  (slot (assq charset charset-origin-alist))
-                  external)
-             (if slot
-                 (setq external (list (nth 1 slot) (funcall (nth 2 slot) char)))
-               (if (eq charset 'composition)
-                   (setq internal '("composite-character"))
+           ;; We show the detailed information of CHAR.
+           (let (internal)
+             (if (eq charset 'composition)
+                 ;; For a composite character, we show the components
+                 ;; only.
+                 (setq internal (concat "(composition of \""
+                                        (decompose-composite-char char)
+                                        "\")")
+                       external nil)
+               (setq internal (split-char char))
+               (unless external
                  (setq external (cons (charset-short-name charset)
                                       (copy-sequence (cdr internal))))
                  (if (= (charset-iso-graphic-plane charset) 1)
@@ -552,7 +563,7 @@ Each language environment may show different external character components."
                       (if (< char 256)
                           (single-key-description char)
                         (char-to-string char))
-                      encoding-msg (or internal "") (or external "")))
+                      encoding-msg internal (or external "")))
          (if (or (/= beg 1) (/= end (1+ total)))
              (message "Char: %s %s point=%d of %d(%d%%) <%d - %d>  column %d %s"
                       (if (< char 256)
@@ -1173,12 +1184,19 @@ In either case, the output is inserted after point (leaving mark after it)."
               (car (cdr (cdr (process-command process))))
               (substring signal 0 -1))))
 
+(defvar shell-command-on-region-default-error-buffer nil
+  "*Name of buffer that `shell-command-on-region' uses for stderr.
+This buffer is used when `shell-command-on-region' is run interactively.
+A nil value for this variable means that output to stderr and stdout
+will be intermixed in the output stream.")
+
 (defun shell-command-on-region (start end command
                                      &optional output-buffer replace
                                      error-buffer)
   "Execute string COMMAND in inferior shell with region as input.
 Normally display output (if any) in temp buffer `*Shell Command Output*';
-Prefix arg means replace the region with it.
+Prefix arg means replace the region with it.  Return the exit code of
+COMMAND.
 
 To specify a coding system for converting non-ASCII characters
 in the input and output to the shell command, use \\[universal-coding-system-argument]
@@ -1211,7 +1229,10 @@ around it.
 
 If optional sixth argument ERROR-BUFFER is non-nil, it is a buffer
 or buffer name to which to direct the command's standard error output.
-If it is nil, error output is mingled with regular output."
+If it is nil, error output is mingled with regular output.
+In an interactive call, the variable
+`shell-command-on-region-default-error-buffer' specifies the value
+of ERROR-BUFFER."
   (interactive (let ((string
                      ;; Do this before calling region-beginning
                      ;; and region-end, in case subprocess output
@@ -1224,96 +1245,100 @@ If it is nil, error output is mingled with regular output."
                 (list (region-beginning) (region-end)
                       string
                       current-prefix-arg
-                      current-prefix-arg)))
+                      current-prefix-arg
+                      shell-command-on-region-default-error-buffer)))
   (let ((error-file
         (if error-buffer 
             (concat (file-name-directory temp-file-name-pattern)
                     (make-temp-name "scor"))
-          nil)))
-  (if (or replace
-         (and output-buffer
-              (not (or (bufferp output-buffer) (stringp output-buffer))))
-         (equal (buffer-name (current-buffer)) "*Shell Command Output*"))
-      ;; Replace specified region with output from command.
-      (let ((swap (and replace (< start end))))
-       ;; Don't muck with mark unless REPLACE says we should.
-       (goto-char start)
-       (and replace (push-mark))
-       (call-process-region start end shell-file-name t
-                            (if error-file
-                                (list t error-file)
-                              t)
-                            nil shell-command-switch command)
-       (let ((shell-buffer (get-buffer "*Shell Command Output*")))
-         (and shell-buffer (not (eq shell-buffer (current-buffer)))
-              (kill-buffer shell-buffer)))
-       ;; Don't muck with mark unless REPLACE says we should.
-       (and replace swap (exchange-point-and-mark)))
-    ;; No prefix argument: put the output in a temp buffer,
-    ;; replacing its entire contents.
-    (let ((buffer (get-buffer-create
-                  (or output-buffer "*Shell Command Output*")))
-         (success nil)
-          (exit-status nil))
-      (unwind-protect
-         (if (eq buffer (current-buffer))
-             ;; If the input is the same buffer as the output,
-             ;; delete everything but the specified region,
-             ;; then replace that region with the output.
-             (progn (setq buffer-read-only nil)
-                    (delete-region (max start end) (point-max))
-                    (delete-region (point-min) (min start end))
-                    (setq exit-status
-                           (call-process-region (point-min) (point-max)
-                                                shell-file-name t 
-                                                (if error-file
-                                                    (list t error-file)
-                                                  t)
-                                                nil shell-command-switch command))
-                    (setq success t))
-           ;; Clear the output buffer, then run the command with output there.
-           (save-excursion
-             (set-buffer buffer)
-             (setq buffer-read-only nil)
-             (erase-buffer))
-           (setq exit-status
-                  (call-process-region start end shell-file-name nil
-                                       (if error-file
-                                           (list buffer error-file)
-                                         buffer)
-                                       nil shell-command-switch command))
-           (setq success t))
-       ;; Report the amount of output.
-       (let ((lines (save-excursion
-                      (set-buffer buffer)
-                      (if (= (buffer-size) 0)
-                          0
-                        (count-lines (point-min) (point-max))))))
-         (cond ((= lines 0)
-                (if success
-                    (message "(Shell command %sed with no output)"
-                              (if (equal 0 exit-status)
-                                  "succeed"
-                                "fail")))
-                (kill-buffer buffer))
-               ((and success (= lines 1))
-                (message "%s"
-                         (save-excursion
-                           (set-buffer buffer)
-                           (goto-char (point-min))
-                           (buffer-substring (point)
-                                             (progn (end-of-line) (point))))))
-               (t 
-                (save-excursion
-                  (set-buffer buffer)
-                  (goto-char (point-min)))
-                (display-buffer buffer)))))))
-  (if (and error-file (file-exists-p error-file))
-      (save-excursion
-       (set-buffer (get-buffer-create error-buffer))
-       ;; Do no formatting while reading error file, for fear of looping.
-       (format-insert-file error-file nil)
-       (delete-file error-file)))))
+          nil))
+       exit-status)
+    (if (or replace
+           (and output-buffer
+                (not (or (bufferp output-buffer) (stringp output-buffer))))
+           (equal (buffer-name (current-buffer)) "*Shell Command Output*"))
+       ;; Replace specified region with output from command.
+       (let ((swap (and replace (< start end))))
+         ;; Don't muck with mark unless REPLACE says we should.
+         (goto-char start)
+         (and replace (push-mark))
+         (setq exit-status
+               (call-process-region start end shell-file-name t
+                                    (if error-file
+                                        (list t error-file)
+                                      t)
+                                    nil shell-command-switch command))
+         (let ((shell-buffer (get-buffer "*Shell Command Output*")))
+           (and shell-buffer (not (eq shell-buffer (current-buffer)))
+                (kill-buffer shell-buffer)))
+         ;; Don't muck with mark unless REPLACE says we should.
+         (and replace swap (exchange-point-and-mark)))
+      ;; No prefix argument: put the output in a temp buffer,
+      ;; replacing its entire contents.
+      (let ((buffer (get-buffer-create
+                    (or output-buffer "*Shell Command Output*")))
+           (success nil))
+       (unwind-protect
+           (if (eq buffer (current-buffer))
+               ;; If the input is the same buffer as the output,
+               ;; delete everything but the specified region,
+               ;; then replace that region with the output.
+               (progn (setq buffer-read-only nil)
+                      (delete-region (max start end) (point-max))
+                      (delete-region (point-min) (min start end))
+                      (setq exit-status
+                            (call-process-region (point-min) (point-max)
+                                                 shell-file-name t 
+                                                 (if error-file
+                                                     (list t error-file)
+                                                   t)
+                                                 nil shell-command-switch
+                                                 command)))
+             ;; Clear the output buffer, then run the command with
+             ;; output there.
+             (save-excursion
+               (set-buffer buffer)
+               (setq buffer-read-only nil)
+               (erase-buffer))
+             (setq exit-status
+                   (call-process-region start end shell-file-name nil
+                                        (if error-file
+                                            (list buffer error-file)
+                                          buffer)
+                                        nil shell-command-switch command)))
+         (setq success (zerop exit-status))
+         ;; Report the amount of output.
+         (let ((lines (save-excursion
+                        (set-buffer buffer)
+                        (if (= (buffer-size) 0)
+                            0
+                          (count-lines (point-min) (point-max))))))
+           (cond ((= lines 0)
+                  (if success
+                      (message "(Shell command %sed with no output)"
+                               (if (equal 0 exit-status)
+                                   "succeed"
+                                 "fail")))
+                  (kill-buffer buffer))
+                 ((and success (= lines 1))
+                  (message "%s"
+                           (save-excursion
+                             (set-buffer buffer)
+                             (goto-char (point-min))
+                             (buffer-substring (point)
+                                               (progn (end-of-line) (point))))))
+                 (t 
+                  (save-excursion
+                    (set-buffer buffer)
+                    (goto-char (point-min)))
+                  (display-buffer buffer)))))))
+    (if (and error-file (file-exists-p error-file))
+       (save-excursion
+         (set-buffer (get-buffer-create error-buffer))
+         ;; Do no formatting while reading error file, for fear of looping.
+         (format-insert-file error-file nil)
+         (delete-file error-file)))
+    exit-status))
        
 (defun shell-command-to-string (command)
   "Execute shell command COMMAND and return its output as a string."
@@ -3113,6 +3138,7 @@ for `auto-fill-function' when turning Auto Fill mode on."
 (defun turn-on-auto-fill ()
   "Unconditionally turn on Auto Fill mode."
   (auto-fill-mode 1))
+(custom-add-option 'text-mode-hook 'turn-on-auto-fill)
 
 (defun set-fill-column (arg)
   "Set `fill-column' to specified argument.