Commit af103ef3 authored by Glenn Morris's avatar Glenn Morris

Merge from origin/emacs-26

615cff42 (origin/emacs-26) Fix process filter documentation (Bug#13400)
beb1d222 Fix query-replace-regexp undo feature

# Conflicts:
#	test/lisp/replace-tests.el
parents 989c85e7 615cff42
Pipeline #2901 failed with stage
in 61 minutes and 8 seconds
...@@ -596,9 +596,8 @@ process}. After an asynchronous process is created, it runs in ...@@ -596,9 +596,8 @@ process}. After an asynchronous process is created, it runs in
parallel with Emacs, and Emacs can communicate with it using the parallel with Emacs, and Emacs can communicate with it using the
functions described in the following sections (@pxref{Input to functions described in the following sections (@pxref{Input to
Processes}, and @pxref{Output from Processes}). Note that process Processes}, and @pxref{Output from Processes}). Note that process
communication is only partially asynchronous: Emacs sends data to the communication is only partially asynchronous: Emacs sends and receives
process only when certain functions are called, and Emacs accepts data data to and from a process only when those functions are called.
from the process only while waiting for input or for a time delay.
@cindex pty, when to use for subprocess communications @cindex pty, when to use for subprocess communications
@cindex pipe, when to use for subprocess communications @cindex pipe, when to use for subprocess communications
...@@ -1245,8 +1244,9 @@ the defaulting mechanism (@pxref{Default Coding Systems}). ...@@ -1245,8 +1244,9 @@ the defaulting mechanism (@pxref{Default Coding Systems}).
because the input buffer is full. When this happens, the send functions because the input buffer is full. When this happens, the send functions
wait a short while, accepting output from subprocesses, and then try wait a short while, accepting output from subprocesses, and then try
again. This gives the subprocess a chance to read more of its pending again. This gives the subprocess a chance to read more of its pending
input and make space in the buffer. It also allows filters, sentinels input and make space in the buffer. It also allows filters (including
and timers to run---so take account of that in writing your code. the one currently running), sentinels and timers to run---so take
account of that in writing your code.
In these functions, the @var{process} argument can be a process or In these functions, the @var{process} argument can be a process or
the name of a process, or a buffer or buffer name (which stands the name of a process, or a buffer or buffer name (which stands
...@@ -1461,9 +1461,10 @@ output, Emacs won't receive that output. ...@@ -1461,9 +1461,10 @@ output, Emacs won't receive that output.
Output from a subprocess can arrive only while Emacs is waiting: when Output from a subprocess can arrive only while Emacs is waiting: when
reading terminal input (see the function @code{waiting-for-user-input-p}), reading terminal input (see the function @code{waiting-for-user-input-p}),
in @code{sit-for} and @code{sleep-for} (@pxref{Waiting}), and in in @code{sit-for} and @code{sleep-for} (@pxref{Waiting}), in
@code{accept-process-output} (@pxref{Accepting Output}). This @code{accept-process-output} (@pxref{Accepting Output}), and in
minimizes the problem of timing errors that usually plague parallel functions which send data to processes (@pxref{Input to Processes}).
This minimizes the problem of timing errors that usually plague parallel
programming. For example, you can safely create a process and only programming. For example, you can safely create a process and only
then specify its buffer or filter function; no output can arrive then specify its buffer or filter function; no output can arrive
before you finish, if the code in between does not call any primitive before you finish, if the code in between does not call any primitive
...@@ -1639,14 +1640,10 @@ outputs directly to the process buffer. ...@@ -1639,14 +1640,10 @@ outputs directly to the process buffer.
By default, the error output from the process, if any, is also By default, the error output from the process, if any, is also
passed to the filter function, unless the destination for the standard passed to the filter function, unless the destination for the standard
error stream of the process was separated from the standard output error stream of the process was separated from the standard output
when the process was created (@pxref{Output from Processes}). when the process was created. Emacs will only call the filter
function during certain function calls. @xref{Output from Processes}.
The filter function can only be called when Emacs is waiting for Note that if any of those functions are called by the filter, the
something, because process output arrives only at such times. Emacs filter may be called recursively.
waits when reading terminal input (see the function
@code{waiting-for-user-input-p}), in @code{sit-for} and
@code{sleep-for} (@pxref{Waiting}), and in
@code{accept-process-output} (@pxref{Accepting Output}).
A filter function must accept two arguments: the associated process A filter function must accept two arguments: the associated process
and a string, which is output just received from it. The function is and a string, which is output just received from it. The function is
......
...@@ -2728,7 +2728,8 @@ characters." ...@@ -2728,7 +2728,8 @@ characters."
(setq real-match-data (setq real-match-data
(save-excursion (save-excursion
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(looking-at search-string) ;; We must quote the string (Bug#37073)
(looking-at (regexp-quote search-string))
(match-data t (nth 2 elt))) (match-data t (nth 2 elt)))
noedit noedit
(replace-match-maybe-edit (replace-match-maybe-edit
...@@ -2738,7 +2739,9 @@ characters." ...@@ -2738,7 +2739,9 @@ characters."
real-match-data real-match-data
(save-excursion (save-excursion
(goto-char (match-beginning 0)) (goto-char (match-beginning 0))
(looking-at next-replacement) (if regexp-flag
(looking-at next-replacement)
(looking-at (regexp-quote next-replacement)))
(match-data t (nth 2 elt)))) (match-data t (nth 2 elt))))
;; Set replaced nil to keep in loop ;; Set replaced nil to keep in loop
(when (eq def 'undo-all) (when (eq def 'undo-all)
......
...@@ -411,6 +411,9 @@ Each element has the format: ...@@ -411,6 +411,9 @@ Each element has the format:
(defvar replace-tests-bind-read-string nil (defvar replace-tests-bind-read-string nil
"A string to bind `read-string' and avoid the prompt.") "A string to bind `read-string' and avoid the prompt.")
(defvar replace-tests-perform-replace-regexp-flag t
"Value for regexp-flag argument passed to `perform-replace' in undo tests.")
(defmacro replace-tests-with-undo (input from to char-nums def-chr &rest body) (defmacro replace-tests-with-undo (input from to char-nums def-chr &rest body)
"Helper to test `query-replace' undo feature. "Helper to test `query-replace' undo feature.
INPUT is a string to insert in a temporary buffer. INPUT is a string to insert in a temporary buffer.
...@@ -463,7 +466,7 @@ Return the last evalled form in BODY." ...@@ -463,7 +466,7 @@ Return the last evalled form in BODY."
((symbol-function 'replace-highlight) ((symbol-function 'replace-highlight)
(lambda (&rest _args) (lambda (&rest _args)
(string-match "[A-Z ]" "ForestGreen")))) (string-match "[A-Z ]" "ForestGreen"))))
(perform-replace ,from ,to t t nil)) (perform-replace ,from ,to t replace-tests-perform-replace-regexp-flag nil))
,@body)))) ,@body))))
(defun replace-tests--query-replace-undo (&optional comma) (defun replace-tests--query-replace-undo (&optional comma)
...@@ -505,4 +508,26 @@ Return the last evalled form in BODY." ...@@ -505,4 +508,26 @@ Return the last evalled form in BODY."
input "a" "B" ((?\s . (1 2 3)) (?E . (4)) (?U . (5))) ?q input "a" "B" ((?\s . (1 2 3)) (?E . (4)) (?U . (5))) ?q
(string= input (buffer-string)))))) (string= input (buffer-string))))))
(ert-deftest query-replace-undo-bug37073 ()
"Test for https://debbugs.gnu.org/37073 ."
(let ((input "theorem 1\ntheorem 2\ntheorem 3"))
(should
(replace-tests-with-undo
input "theorem \\([0-9]+\\)"
"theorem \\\\ref{theo_\\1}"
((?\s . (1 2)) (?U . (3)))
?q
(string= input (buffer-string)))))
;; Now run a test with regexp-flag arg in `perform-replace' set to nil
(let ((input " ^theorem$ 1\n ^theorem$ 2\n ^theorem$ 3")
(replace-tests-perform-replace-regexp-flag nil)
(expected " theo 1\n ^theorem$ 2\n ^theorem$ 3"))
(should
(replace-tests-with-undo
input "^theorem$"
"theo"
((?\s . (1 2 4)) (?U . (3)))
?q
(string= expected (buffer-string))))))
;;; replace-tests.el ends here ;;; replace-tests.el ends here
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment