;; We define this, rather than making `eval' interactive,
;; for the sake of completion of names like eval-region, eval-current-buffer.
-(defun eval-expression (eval-expression-arg)
+(defun eval-expression (eval-expression-arg
+ &optional eval-expression-insert-value)
"Evaluate EXPRESSION and print value in minibuffer.
Value is also consed on to front of the variable `values'."
(interactive
(list (read-from-minibuffer "Eval: "
nil read-expression-map t
- 'read-expression-history)))
+ 'read-expression-history)
+ current-prefix-arg))
(setq values (cons (eval eval-expression-arg) values))
- (prin1 (car values) t))
+ (prin1 (car values)
+ (if eval-expression-insert-value (current-buffer) t)))
(defun edit-and-eval-command (prompt command)
"Prompting with PROMPT, let user edit COMMAND and eval result.
(setq newcmd
(let ((print-level nil)
(minibuffer-history-position arg)
- (minibuffer-history-sexp-flag t))
+ (minibuffer-history-sexp-flag (1+ (minibuffer-depth))))
(read-from-minibuffer
"Redo: " (prin1-to-string elt) read-expression-map t
(cons 'command-history arg))))
(defvar minibuffer-history-sexp-flag nil
"Non-nil when doing history operations on `command-history'.
More generally, indicates that the history list being acted on
-contains expressions rather than strings.")
+contains expressions rather than strings.
+It is only valid if its value equals the current minibuffer depth,
+to handle recursive uses of the minibuffer.")
(setq minibuffer-history-variable 'minibuffer-history)
(setq minibuffer-history-position nil)
(defvar minibuffer-history-search-history nil)
If N is negative, find the next or Nth next match."
(interactive
(let* ((enable-recursive-minibuffers t)
- (minibuffer-history-sexp-flag nil)
(regexp (read-from-minibuffer "Previous element matching (regexp): "
nil
minibuffer-local-map
"No later matching history item"
"No earlier matching history item")))
(if (string-match regexp
- (if minibuffer-history-sexp-flag
+ (if (eq minibuffer-history-sexp-flag
+ (minibuffer-depth))
(let ((print-level nil))
(prin1-to-string (nth (1- pos) history)))
(nth (1- pos) history)))
(setq minibuffer-history-position pos)
(erase-buffer)
(let ((elt (nth (1- pos) history)))
- (insert (if minibuffer-history-sexp-flag
+ (insert (if (eq minibuffer-history-sexp-flag (minibuffer-depth))
(let ((print-level nil))
(prin1-to-string elt))
elt)))
If N is negative, find the previous or Nth previous match."
(interactive
(let* ((enable-recursive-minibuffers t)
- (minibuffer-history-sexp-flag nil)
(regexp (read-from-minibuffer "Next element matching (regexp): "
nil
minibuffer-local-map
(cond ((= narg -1)
(setq elt minibuffer-default))
((= narg 0)
- (setq elt minibuffer-text-before-history)
+ (setq elt (or minibuffer-text-before-history ""))
(setq minibuffer-text-before-history nil))
(t (setq elt (nth (1- minibuffer-history-position)
(symbol-value minibuffer-history-variable)))))
(insert
- (if minibuffer-history-sexp-flag
+ (if (eq minibuffer-history-sexp-flag (minibuffer-depth))
(let ((print-level nil))
(prin1-to-string elt))
elt))
(substring signal 0 -1))))
(defun shell-command-on-region (start end command
- &optional output-buffer replace)
+ &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.
`buffer-file-coding-system'. If the output is going to replace the region,
then it is decoded from that same coding system.
-The noninteractive arguments are START, END, COMMAND, OUTPUT-BUFFER, REPLACE.
-If REPLACE is non-nil, that means insert the output
+The noninteractive arguments are START, END, COMMAND, OUTPUT-BUFFER, REPLACE,
+ERROR-BUFFER. If REPLACE is non-nil, that means insert the output
in place of text from START to END, putting point and mark around it.
Noninteractive callers can specify coding systems by binding
`coding-system-for-read' and `coding-system-for-write'.
If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
If OUTPUT-BUFFER is not a buffer and not nil,
insert output in the current buffer.
-In either case, the output is inserted after point (leaving mark after it)."
+In either case, the output is inserted after point (leaving mark after it).
+
+If optional fifth 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."
(interactive (let ((string
;; Do this before calling region-beginning
;; and region-end, in case subprocess output
string
current-prefix-arg
current-prefix-arg)))
+ (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))))
;; 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 t nil
- shell-command-switch command)
+ (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)))
(delete-region (max start end) (point-max))
(delete-region (point-min) (min start end))
(call-process-region (point-min) (point-max)
- shell-file-name t t nil
- shell-command-switch command)
+ 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))
- (call-process-region start end shell-file-name
- nil buffer nil
- shell-command-switch command)
+ (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
(save-excursion
(set-buffer buffer)
(goto-char (point-min)))
- (display-buffer buffer))))))))
+ (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)))))
(defun shell-command-to-string (command)
"Execute shell command COMMAND and return its output as a string."
prop
(or (memq prop buffer-invisibility-spec)
(assq prop buffer-invisibility-spec)))))
- (if (get-text-property (point) 'invisible)
- (goto-char (next-single-property-change (point) 'invisible))
- (goto-char (next-overlay-change (point))))
+ (goto-char
+ (if (get-text-property (point) 'invisible)
+ (or (next-single-property-change (point) 'invisible)
+ (point-max))
+ (next-overlay-change (point))))
(or (zerop (forward-line 1))
(signal 'end-of-buffer nil)))
(setq arg (1- arg)))
prop
(or (memq prop buffer-invisibility-spec)
(assq prop buffer-invisibility-spec)))))
- (if (get-text-property (1- (point)) 'invisible)
- (goto-char (previous-single-property-change (point) 'invisible))
- (goto-char (previous-overlay-change (point))))
+ (goto-char
+ (if (get-text-property (1- (point)) 'invisible)
+ (or (previous-single-property-change (point) 'invisible)
+ (point-min))
+ (previous-overlay-change (point))))
(or (zerop (forward-line -1))
(signal 'beginning-of-buffer nil)))
(setq first nil)
(if (get-text-property (point) 'invisible)
(goto-char (next-single-property-change (point) 'invisible))
(goto-char (next-overlay-change (point))))
- (forward-char 1)
(end-of-line)))
\f
;;;; Window system cut and paste hooks.
regexp)
:group 'fill)
+(defvar comment-line-break-function 'indent-new-comment-line
+ "*Mode-specific function which line breaks and continues a comment.
+
+This function is only called during auto-filling of a comment section.
+The function should take a single optional argument, which is a flag
+indicating whether it should use soft newlines.
+
+Setting this variable automatically makes it local to the current buffer.")
+
;; This function is the auto-fill-function of a buffer
;; when Auto-Fill mode is enabled.
;; It returns t if it really did any work.
(while (and (not give-up) (> (current-column) fc))
;; Determine where to split the line.
- (let ((fill-point
- (let ((opoint (point))
- bounce
- (first t)
- after-prefix)
- (save-excursion
- (beginning-of-line)
- (setq after-prefix (point))
- (and fill-prefix
- (looking-at (regexp-quote fill-prefix))
- (setq after-prefix (match-end 0)))
- (move-to-column (1+ fc))
- ;; Move back to the point where we can break the
- ;; line at. We break the line between word or
- ;; after/before the character which has character
- ;; category `|'. We search space, \c| followed by
- ;; a character, or \c| follwoing a character. If
- ;; not found, place the point at beginning of line.
- (while (or first
- ;; If this is after period and a single space,
- ;; move back once more--we don't want to break
- ;; the line there and make it look like a
- ;; sentence end.
- (and (not (bobp))
- (not bounce)
- sentence-end-double-space
- (save-excursion (forward-char -1)
- (and (looking-at "\\. ")
- (not (looking-at "\\. "))))))
- (setq first nil)
- (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^")
- ;; If we find nowhere on the line to break it,
- ;; break after one word. Set bounce to t
- ;; so we will not keep going in this while loop.
- (if (<= (point) after-prefix)
- (progn
- (re-search-forward "[ \t]" opoint t)
- (setq bounce t))
- (if (looking-at "[ \t]")
- ;; Break the line at word boundary.
- (skip-chars-backward " \t")
- ;; Break the line after/before \c|.
- (forward-char 1))))
- (if (and enable-kinsoku enable-multibyte-characters)
- (kinsoku (save-excursion
- (forward-line 0) (point))))
- ;; Let fill-point be set to the place where we end up.
- (point)))))
-
- ;; If that place is not the beginning of the line,
- ;; break the line there.
+ (let* (after-prefix
+ (fill-point
+ (let ((opoint (point))
+ bounce
+ (first t))
+ (save-excursion
+ (beginning-of-line)
+ (setq after-prefix (point))
+ (and fill-prefix
+ (looking-at (regexp-quote fill-prefix))
+ (setq after-prefix (match-end 0)))
+ (move-to-column (1+ fc))
+ ;; Move back to the point where we can break the
+ ;; line at. We break the line between word or
+ ;; after/before the character which has character
+ ;; category `|'. We search space, \c| followed by
+ ;; a character, or \c| follwoing a character. If
+ ;; not found, place the point at beginning of line.
+ (while (or first
+ ;; If this is after period and a single space,
+ ;; move back once more--we don't want to break
+ ;; the line there and make it look like a
+ ;; sentence end.
+ (and (not (bobp))
+ (not bounce)
+ sentence-end-double-space
+ (save-excursion (forward-char -1)
+ (and (looking-at "\\. ")
+ (not (looking-at "\\. "))))))
+ (setq first nil)
+ (re-search-backward "[ \t]\\|\\c|.\\|.\\c|\\|^")
+ ;; If we find nowhere on the line to break it,
+ ;; break after one word. Set bounce to t
+ ;; so we will not keep going in this while loop.
+ (if (<= (point) after-prefix)
+ (progn
+ (goto-char after-prefix)
+ (re-search-forward "[ \t]" opoint t)
+ (setq bounce t))
+ (if (looking-at "[ \t]")
+ ;; Break the line at word boundary.
+ (skip-chars-backward " \t")
+ ;; Break the line after/before \c|.
+ (forward-char 1))))
+ (if (and enable-kinsoku enable-multibyte-characters)
+ (kinsoku (save-excursion
+ (forward-line 0) (point))))
+ ;; Let fill-point be set to the place where we end up.
+ (point)))))
+
+ ;; See whether the place we found is any good.
(if (save-excursion
(goto-char fill-point)
(and (not (bolp))
+ ;; There is no use breaking at end of line.
+ (not (save-excursion (skip-chars-forward " ") (eolp)))
+ ;; It is futile to split at the end of the prefix
+ ;; since we would just insert the prefix again.
+ (not (and after-prefix (<= (point) after-prefix)))
;; Don't split right after a comment starter
;; since we would just make another comment starter.
(not (and comment-start-skip
(and (re-search-forward comment-start-skip
limit t)
(eq (point) limit)))))))
+ ;; Ok, we have a useful place to break the line. Do it.
(let ((prev-column (current-column)))
;; If point is at the fill-point, do not `save-excursion'.
;; Otherwise, if a comment prefix or fill-prefix is inserted,
(if (save-excursion
(skip-chars-backward " \t")
(= (point) fill-point))
- (indent-new-comment-line t)
+ (funcall comment-line-break-function t)
(save-excursion
(goto-char fill-point)
- (indent-new-comment-line t)))
+ (funcall comment-line-break-function t)))
;; Now do justification, if required
(if (not (eq justify 'left))
(save-excursion
;; trying again will not help.
(if (>= (current-column) prev-column)
(setq give-up t)))
- ;; No place to break => stop trying.
+ ;; No good place to break => stop trying.
(setq give-up t))))
;; Justify last line.
(justify-current-line justify t t)
(goto-char (point-max))
(skip-chars-backward (format "^%c" directory-sep-char))
(- (point) (point-min))))
- ;; Otherwise, the whole input is the text being completed.
- (setq completion-base-size 0))
+ ;; Otherwise, in minibuffer, the whole input is being completed.
+ (save-match-data
+ (if (string-match "\\` \\*Minibuf-[0-9]+\\*\\'"
+ (buffer-name mainbuf))
+ (setq completion-base-size 0))))
(goto-char (point-min))
(if window-system
(insert (substitute-command-keys