diff options
| author | Stefan Monnier | 2020-01-19 17:10:57 -0500 |
|---|---|---|
| committer | Stefan Monnier | 2020-01-19 17:10:57 -0500 |
| commit | 46fefb09745abbcdb4b56d80cd2bbd545afc39e1 (patch) | |
| tree | 6f32e74396591b99e2f623bf9e125bcea9ece24f | |
| parent | e5e31aab9b13701c0aefd93ad786d4b8feff2789 (diff) | |
| download | emacs-46fefb09745abbcdb4b56d80cd2bbd545afc39e1.tar.gz emacs-46fefb09745abbcdb4b56d80cd2bbd545afc39e1.zip | |
* lisp/international/mule-cmds.el (universal-coding-system-argument): Rewrite
Use the new `prefix-command-*` hooks and functions so it interacts
better with other prefix commands (and with itself), and so the
pre/post-command-hook and other command-loop operations are performed
"normally".
(mule-cmds--prefixed-command-next-coding-system)
(mule-cmds--prefixed-command-last-coding-system): New vars.
(mule-cmds--prefixed-command-pch, mule-cmds--prefixed-command-echo)
(mule-cmds--prefixed-command-preserve): New functions.
| -rw-r--r-- | lisp/international/mule-cmds.el | 96 |
1 files changed, 51 insertions, 45 deletions
diff --git a/lisp/international/mule-cmds.el b/lisp/international/mule-cmds.el index c86b1da0ae7..91253745730 100644 --- a/lisp/international/mule-cmds.el +++ b/lisp/international/mule-cmds.el | |||
| @@ -283,8 +283,42 @@ wrong, use this command again to toggle back to the right mode." | |||
| 283 | (interactive) | 283 | (interactive) |
| 284 | (view-file (expand-file-name "HELLO" data-directory))) | 284 | (view-file (expand-file-name "HELLO" data-directory))) |
| 285 | 285 | ||
| 286 | (defvar mule-cmds--prefixed-command-next-coding-system nil) | ||
| 287 | (defvar mule-cmds--prefixed-command-last-coding-system nil) | ||
| 288 | |||
| 289 | (defun mule-cmds--prefixed-command-pch () | ||
| 290 | (if (not mule-cmds--prefixed-command-next-coding-system) | ||
| 291 | (progn | ||
| 292 | (remove-hook 'pre-command-hook #'mule-cmds--prefixed-command) | ||
| 293 | (remove-hook 'prefix-command-echo-keystrokes-functions | ||
| 294 | #'mule-cmds--prefixed-command-echo) | ||
| 295 | (remove-hook 'prefix-command-preserve-state-hook | ||
| 296 | #'mule-cmds--prefixed-command-preserve)) | ||
| 297 | (setq this-command | ||
| 298 | (let ((cmd this-command) | ||
| 299 | (coding-system mule-cmds--prefixed-command-next-coding-system)) | ||
| 300 | (lambda () | ||
| 301 | (interactive) | ||
| 302 | (setq this-command cmd) | ||
| 303 | (let ((coding-system-for-read coding-system) | ||
| 304 | (coding-system-for-write coding-system) | ||
| 305 | (coding-system-require-warning t)) | ||
| 306 | (call-interactively cmd))))) | ||
| 307 | (setq mule-cmds--prefixed-command-last-coding-system | ||
| 308 | mule-cmds--prefixed-command-next-coding-system) | ||
| 309 | (setq mule-cmds--prefixed-command-next-coding-system nil))) | ||
| 310 | |||
| 311 | (defun mule-cmds--prefixed-command-echo () | ||
| 312 | (when mule-cmds--prefixed-command-next-coding-system | ||
| 313 | (format "With coding-system %S" | ||
| 314 | mule-cmds--prefixed-command-next-coding-system))) | ||
| 315 | |||
| 316 | (defun mule-cmds--prefixed-command-preserve () | ||
| 317 | (setq mule-cmds--prefixed-command-next-coding-system | ||
| 318 | mule-cmds--prefixed-command-last-coding-system)) | ||
| 319 | |||
| 286 | (defun universal-coding-system-argument (coding-system) | 320 | (defun universal-coding-system-argument (coding-system) |
| 287 | "Execute an I/O command using the specified coding system." | 321 | "Execute an I/O command using the specified CODING-SYSTEM." |
| 288 | (interactive | 322 | (interactive |
| 289 | (let ((default (and buffer-file-coding-system | 323 | (let ((default (and buffer-file-coding-system |
| 290 | (not (eq (coding-system-type buffer-file-coding-system) | 324 | (not (eq (coding-system-type buffer-file-coding-system) |
| @@ -295,41 +329,13 @@ wrong, use this command again to toggle back to the right mode." | |||
| 295 | (format "Coding system for following command (default %s): " default) | 329 | (format "Coding system for following command (default %s): " default) |
| 296 | "Coding system for following command: ") | 330 | "Coding system for following command: ") |
| 297 | default)))) | 331 | default)))) |
| 298 | ;; FIXME: This "read-key-sequence + call-interactively" loop is trying to | 332 | (prefix-command-preserve-state) |
| 299 | ;; reproduce the normal command loop, but this "can't" be done faithfully so | 333 | (setq mule-cmds--prefixed-command-next-coding-system coding-system) |
| 300 | ;; it necessarily suffers from breakage in corner cases (e.g. it fails to run | 334 | (add-hook 'pre-command-hook #'mule-cmds--prefixed-command-pch) |
| 301 | ;; pre/post-command-hook, doesn't properly set this-command/last-command, it | 335 | (add-hook 'prefix-command-echo-keystrokes-functions |
| 302 | ;; doesn't handle keyboard macros, ...). | 336 | #'mule-cmds--prefixed-command-echo) |
| 303 | (let* ((keyseq (read-key-sequence | 337 | (add-hook 'prefix-command-preserve-state-hook |
| 304 | (format "Command to execute with %s:" coding-system))) | 338 | #'mule-cmds--prefixed-command-preserve)) |
| 305 | (cmd (key-binding keyseq))) | ||
| 306 | ;; read-key-sequence ignores quit, so make an explicit check. | ||
| 307 | (if (equal last-input-event (nth 3 (current-input-mode))) | ||
| 308 | (keyboard-quit)) | ||
| 309 | (when (memq cmd '(universal-argument digit-argument)) | ||
| 310 | (call-interactively cmd) | ||
| 311 | |||
| 312 | ;; Process keys bound in `universal-argument-map'. | ||
| 313 | (while (progn | ||
| 314 | (setq keyseq (read-key-sequence nil t) | ||
| 315 | cmd (key-binding keyseq t)) | ||
| 316 | (memq cmd '(negative-argument digit-argument | ||
| 317 | universal-argument-more))) | ||
| 318 | (setq current-prefix-arg prefix-arg prefix-arg nil) | ||
| 319 | ;; Have to bind `last-command-event' here so that | ||
| 320 | ;; `digit-argument', for instance, can compute the | ||
| 321 | ;; `prefix-arg'. | ||
| 322 | (setq last-command-event (aref keyseq 0)) | ||
| 323 | (call-interactively cmd))) | ||
| 324 | |||
| 325 | (let ((coding-system-for-read coding-system) | ||
| 326 | (coding-system-for-write coding-system) | ||
| 327 | (coding-system-require-warning t)) | ||
| 328 | (setq current-prefix-arg prefix-arg prefix-arg nil) | ||
| 329 | ;; Have to bind `last-command-event' e.g. for `self-insert-command'. | ||
| 330 | (setq last-command-event (aref keyseq 0)) | ||
| 331 | (message "") | ||
| 332 | (call-interactively cmd)))) | ||
| 333 | 339 | ||
| 334 | (defun set-default-coding-systems (coding-system) | 340 | (defun set-default-coding-systems (coding-system) |
| 335 | "Set default value of various coding systems to CODING-SYSTEM. | 341 | "Set default value of various coding systems to CODING-SYSTEM. |
| @@ -700,8 +706,8 @@ DEFAULT is the coding system to use by default in the query." | |||
| 700 | ;; buffer is displayed. | 706 | ;; buffer is displayed. |
| 701 | (when (and unsafe (not (stringp from))) | 707 | (when (and unsafe (not (stringp from))) |
| 702 | (pop-to-buffer bufname) | 708 | (pop-to-buffer bufname) |
| 703 | (goto-char (apply 'min (mapcar #'(lambda (x) (car (cadr x))) | 709 | (goto-char (apply #'min (mapcar (lambda (x) (or (car (cadr x)) (point-max))) |
| 704 | unsafe)))) | 710 | unsafe)))) |
| 705 | ;; Then ask users to select one from CODINGS while showing | 711 | ;; Then ask users to select one from CODINGS while showing |
| 706 | ;; the reason why none of the defaults are not used. | 712 | ;; the reason why none of the defaults are not used. |
| 707 | (with-output-to-temp-buffer "*Warning*" | 713 | (with-output-to-temp-buffer "*Warning*" |
| @@ -1402,13 +1408,13 @@ The commands `describe-input-method' and `list-input-methods' need | |||
| 1402 | these duplicated values to show some information about input methods | 1408 | these duplicated values to show some information about input methods |
| 1403 | without loading the relevant Quail packages. | 1409 | without loading the relevant Quail packages. |
| 1404 | \n(fn INPUT-METHOD LANG-ENV ACTIVATE-FUNC TITLE DESCRIPTION &rest ARGS)" | 1410 | \n(fn INPUT-METHOD LANG-ENV ACTIVATE-FUNC TITLE DESCRIPTION &rest ARGS)" |
| 1405 | (if (symbolp lang-env) | 1411 | (setq lang-env (if (symbolp lang-env) |
| 1406 | (setq lang-env (symbol-name lang-env)) | 1412 | (symbol-name lang-env) |
| 1407 | (setq lang-env (purecopy lang-env))) | 1413 | (purecopy lang-env))) |
| 1408 | (if (symbolp input-method) | 1414 | (setq input-method (if (symbolp input-method) |
| 1409 | (setq input-method (symbol-name input-method)) | 1415 | (symbol-name input-method) |
| 1410 | (setq input-method (purecopy input-method))) | 1416 | (purecopy input-method))) |
| 1411 | (setq args (mapcar 'purecopy args)) | 1417 | (setq args (mapcar #'purecopy args)) |
| 1412 | (let ((info (cons lang-env args)) | 1418 | (let ((info (cons lang-env args)) |
| 1413 | (slot (assoc input-method input-method-alist))) | 1419 | (slot (assoc input-method input-method-alist))) |
| 1414 | (if slot | 1420 | (if slot |