If @var{async} is non-@code{nil}, the file will be loaded into the
buffer asynchronously. Interactively, this is indicated by either
setting user option @code{execute-file-commands-asynchronously} to
-non-@code{nil}, or by the key sequence @kbd{C-x &} prior the command.
+non-@code{nil}, or by the key sequence @kbd{C-x &}
+(@code{universal-async-argument}) prior the command.
When @code{find-file} is called interactively, it prompts for
@var{filename} in the minibuffer.
and never treat wildcard characters specially.
@end defopt
+@kindex C-x &
+@findex universal-async-argument
@defopt execute-file-commands-asynchronously
If this variable is non-@code{nil}, a file will be visited
asynchronously when called interactively. If it is a regular
expression, it must match the file name to be visited. This behavior
-is toggled by the key sequence @kbd{C-x &} prior to the interactive
-call of the file visiting command.
+is toggled by the key sequence @kbd{C-x &}
+(@code{universal-async-argument}) prior to the interactive call of the
+file visiting command.
@end defopt
@defopt find-file-hook
uses of this function all but disappeared by now, so we are
un-obsoleting it.
+--- (Needs better documentation)
+** There is a new command 'universal-async-argument', bound to 'C-x &'.
+If this command precedes another command, the value of variable
+'universal-async-argument' will be toggled. This indicates, that the
+following command shall be executed asynchronously. For example,
+file visiting commands would load files into buffers asynchronously.
+
\f
* Changes in Emacs 27.1 on Non-Free Operating Systems
,@body)
(remove-hook 'minibuffer-setup-hook ,hook)))))
-(defun universal-async-argument (async)
- "Execute an interactive command using the ASYNC argument.
-For file visiting and saving commands, this toggles the meaning
-of `execute-file-commands-asynchronously'."
- (interactive
- (list (and (featurep 'threads) (not execute-file-commands-asynchronously))))
- (let* ((execute-file-commands-asynchronously async)
- (keyseq (read-key-sequence nil))
- (cmd (key-binding keyseq))
- prefix)
- ;; `read-key-sequence' ignores quit, so make an explicit check.
- (if (equal last-input-event (nth 3 (current-input-mode)))
- (keyboard-quit))
- (when (memq cmd '(universal-argument digit-argument))
- (call-interactively cmd)
-
- ;; Process keys bound in `universal-argument-map'.
- (while (progn
- (setq keyseq (read-key-sequence nil t)
- cmd (key-binding keyseq t))
- (not (eq cmd 'universal-argument-other-key)))
- (let ((current-prefix-arg prefix-arg)
- ;; Have to bind `last-command-event' here so that
- ;; `digit-argument', for instance, can compute the
- ;; `prefix-arg'.
- (last-command-event (aref keyseq 0)))
- (call-interactively cmd)))
-
- ;; This is the final call to `universal-argument-other-key', which
- ;; sets the final `prefix-arg'.
- (let ((current-prefix-arg prefix-arg))
- (call-interactively cmd))
-
- ;; Read the command to execute with the given `prefix-arg'.
- (setq prefix prefix-arg
- keyseq (read-key-sequence nil t)
- cmd (key-binding keyseq)))
-
- (let ((current-prefix-arg prefix))
- (message "")
- (call-interactively cmd))))
-
-(define-key ctl-x-map "&" 'universal-async-argument)
-
(defun find-file-read-args (prompt mustmatch &optional wildcards)
"Return the interactive spec (<filename> <async>).
If WILDCARDS is non-nil, return the spec (<filename> t <async>)."
(let ((filename (read-file-name prompt nil default-directory mustmatch))
- (async (and (featurep 'threads) execute-file-commands-asynchronously)))
+ (async (and (featurep 'threads)
+ (xor universal-async-argument
+ execute-file-commands-asynchronously))))
(when (stringp async) (setq async (string-match-p async filename)))
(if wildcards `(,filename t ,async) `(,filename ,async))))
(list (read-file-name
"Find alternate file: " file-dir nil
(confirm-nonexistent-file-or-buffer) file-name)
- t
- (and (featurep 'threads) execute-file-commands-asynchronously)))))
+ t (and (featurep 'threads)
+ (xor universal-async-argument
+ execute-file-commands-asynchronously))))))
(when (stringp async) (setq async (string-match-p async filename)))
(if (one-window-p)
(find-file-other-window filename wildcards async)
(list (read-file-name
"Find alternate file: " file-dir nil
(confirm-nonexistent-file-or-buffer) file-name)
- t (and (featurep 'threads) execute-file-commands-asynchronously))))
+ t (and (featurep 'threads)
+ (xor universal-async-argument
+ execute-file-commands-asynchronously)))))
(when (stringp async) (setq async (string-match-p async filename)))
(unless (run-hook-with-args-until-failure 'kill-buffer-query-functions)
(user-error "Aborted"))
(t
digit))))
(universal-argument--mode))
+
+(defvar universal-async-argument nil
+ "Non-nil indicates a command to run asynchronously when called interactively.
+The semantics depend on the command. This variable should not be
+set globally, it should be used in let-bindings only.")
+
+(defun universal-async-argument ()
+ "Execute an interactive command asynchronously."
+ (interactive)
+ (let* ((universal-async-argument (not universal-async-argument))
+ (keyseq (read-key-sequence nil t))
+ (cmd (key-binding keyseq))
+ prefix)
+ ;; `read-key-sequence' ignores quit, so make an explicit check.
+ (if (equal last-input-event (nth 3 (current-input-mode)))
+ (keyboard-quit))
+ (when (memq cmd '(universal-argument digit-argument))
+ (call-interactively cmd)
+
+ ;; Process keys bound in `universal-argument-map'.
+ (while (progn
+ (setq keyseq (read-key-sequence nil t)
+ cmd (key-binding keyseq t))
+ (not (eq cmd 'universal-argument-other-key)))
+ (let ((current-prefix-arg prefix-arg)
+ ;; Have to bind `last-command-event' here so that
+ ;; `digit-argument', for instance, can compute the
+ ;; `prefix-arg'.
+ (last-command-event (aref keyseq 0)))
+ (call-interactively cmd)))
+
+ ;; This is the final call to `universal-argument-other-key', which
+ ;; sets the final `prefix-arg'.
+ (let ((current-prefix-arg prefix-arg))
+ (call-interactively cmd))
+
+ ;; Read the command to execute with the given `prefix-arg'.
+ (setq prefix prefix-arg
+ keyseq (read-key-sequence nil t)
+ cmd (key-binding keyseq)))
+
+ (let ((current-prefix-arg prefix))
+ (message "")
+ (call-interactively cmd))))
+
+(define-key ctl-x-map "&" 'universal-async-argument)
\f
(defvar filter-buffer-substring-functions nil