diff options
| author | Stefan Monnier | 2020-04-03 13:28:31 -0400 |
|---|---|---|
| committer | Stefan Monnier | 2020-04-03 13:58:28 -0400 |
| commit | 9b6d252a1806c4b73e43eaaecde3d7cdc38c4b1d (patch) | |
| tree | 465b375ea00f9661ce7ccbc66bc9bbaf26a1bb37 | |
| parent | 00f7744c1b0f3e6aa59634a28ab671b2203e3900 (diff) | |
| download | emacs-9b6d252a1806c4b73e43eaaecde3d7cdc38c4b1d.tar.gz emacs-9b6d252a1806c4b73e43eaaecde3d7cdc38c4b1d.zip | |
* lisp/arc-mode.el: Use lexical-binding
(arc-insert-unibyte): Simplify.
(archive--mode-revert): Rename from `archive-mode-revert` and adjust
for use as an :around advice.
(archive-mode): Use setq-local. Use `add-function` to hook into
`revert-buffer-function`.
(archive-summarize): Don't use `set` on a hook.
| -rw-r--r-- | lisp/arc-mode.el | 79 |
1 files changed, 37 insertions, 42 deletions
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el index 677483e49f2..f2dcb72eec1 100644 --- a/lisp/arc-mode.el +++ b/lisp/arc-mode.el | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | ;;; arc-mode.el --- simple editing of archives | 1 | ;;; arc-mode.el --- simple editing of archives -*- lexical-binding: t; -*- |
| 2 | 2 | ||
| 3 | ;; Copyright (C) 1995, 1997-1998, 2001-2020 Free Software Foundation, | 3 | ;; Copyright (C) 1995, 1997-1998, 2001-2020 Free Software Foundation, |
| 4 | ;; Inc. | 4 | ;; Inc. |
| @@ -52,17 +52,17 @@ | |||
| 52 | ;; ARCHIVE TYPES: Currently only the archives below are handled, but the | 52 | ;; ARCHIVE TYPES: Currently only the archives below are handled, but the |
| 53 | ;; structure for handling just about anything is in place. | 53 | ;; structure for handling just about anything is in place. |
| 54 | ;; | 54 | ;; |
| 55 | ;; Arc Lzh Zip Zoo Rar 7z | 55 | ;; Arc Lzh Zip Zoo Rar 7z Ar |
| 56 | ;; -------------------------------------------- | 56 | ;; -------------------------------------------------- |
| 57 | ;; View listing Intern Intern Intern Intern Y Y | 57 | ;; View listing Intern Intern Intern Intern Y Y Y |
| 58 | ;; Extract member Y Y Y Y Y Y | 58 | ;; Extract member Y Y Y Y Y Y Y |
| 59 | ;; Save changed member Y Y Y Y N Y | 59 | ;; Save changed member Y Y Y Y N Y N |
| 60 | ;; Add new member N N N N N N | 60 | ;; Add new member N N N N N N N |
| 61 | ;; Delete member Y Y Y Y N Y | 61 | ;; Delete member Y Y Y Y N Y N |
| 62 | ;; Rename member Y Y N N N N | 62 | ;; Rename member Y Y N N N N N |
| 63 | ;; Chmod - Y Y - N N | 63 | ;; Chmod - Y Y - N N N |
| 64 | ;; Chown - Y - - N N | 64 | ;; Chown - Y - - N N N |
| 65 | ;; Chgrp - Y - - N N | 65 | ;; Chgrp - Y - - N N N |
| 66 | ;; | 66 | ;; |
| 67 | ;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips | 67 | ;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips |
| 68 | ;; on the first released version of this package. | 68 | ;; on the first released version of this package. |
| @@ -520,9 +520,9 @@ Each descriptor is a vector of the form | |||
| 520 | (defun arc-insert-unibyte (&rest args) | 520 | (defun arc-insert-unibyte (&rest args) |
| 521 | "Like insert but don't make unibyte string and eight-bit char multibyte." | 521 | "Like insert but don't make unibyte string and eight-bit char multibyte." |
| 522 | (dolist (elt args) | 522 | (dolist (elt args) |
| 523 | (if (integerp elt) | 523 | (insert (if (and (integerp elt) (>= elt 128)) |
| 524 | (insert (if (< elt 128) elt (decode-char 'eight-bit elt))) | 524 | (decode-char 'eight-bit elt) |
| 525 | (insert elt)))) | 525 | elt)))) |
| 526 | 526 | ||
| 527 | (defsubst archive-name (suffix) | 527 | (defsubst archive-name (suffix) |
| 528 | (intern (concat "archive-" (symbol-name archive-subtype) "-" suffix))) | 528 | (intern (concat "archive-" (symbol-name archive-subtype) "-" suffix))) |
| @@ -622,7 +622,8 @@ the mode is invalid. If ERROR is nil then nil will be returned." | |||
| 622 | (format "%2d-%s-%d" | 622 | (format "%2d-%s-%d" |
| 623 | day | 623 | day |
| 624 | (aref ["Jan" "Feb" "Mar" "Apr" "May" "Jun" | 624 | (aref ["Jan" "Feb" "Mar" "Apr" "May" "Jun" |
| 625 | "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"] (1- month)) | 625 | "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"] |
| 626 | (1- month)) | ||
| 626 | year)))) | 627 | year)))) |
| 627 | 628 | ||
| 628 | (defun archive-dostime (time) | 629 | (defun archive-dostime (time) |
| @@ -684,38 +685,33 @@ archive. | |||
| 684 | ;; mode on and off. You can corrupt things that way. | 685 | ;; mode on and off. You can corrupt things that way. |
| 685 | (if (zerop (buffer-size)) | 686 | (if (zerop (buffer-size)) |
| 686 | ;; At present we cannot create archives from scratch | 687 | ;; At present we cannot create archives from scratch |
| 687 | (funcall (or (default-value 'major-mode) 'fundamental-mode)) | 688 | (funcall (or (default-value 'major-mode) #'fundamental-mode)) |
| 688 | (if (and (not force) archive-files) nil | 689 | (if (and (not force) archive-files) nil |
| 689 | (kill-all-local-variables) | 690 | (kill-all-local-variables) |
| 690 | (let* ((type (archive-find-type)) | 691 | (let* ((type (archive-find-type)) |
| 691 | (typename (capitalize (symbol-name type)))) | 692 | (typename (capitalize (symbol-name type)))) |
| 692 | (make-local-variable 'archive-subtype) | 693 | (setq-local archive-subtype type) |
| 693 | (setq archive-subtype type) | ||
| 694 | 694 | ||
| 695 | ;; Buffer contains treated image of file before the file contents | 695 | ;; Buffer contains treated image of file before the file contents |
| 696 | (make-local-variable 'revert-buffer-function) | 696 | (add-function :around (local 'revert-buffer-function) |
| 697 | (setq revert-buffer-function 'archive-mode-revert) | 697 | #'archive--mode-revert) |
| 698 | (auto-save-mode 0) | ||
| 699 | 698 | ||
| 700 | (add-hook 'write-contents-functions 'archive-write-file nil t) | 699 | (add-hook 'write-contents-functions #'archive-write-file nil t) |
| 701 | 700 | ||
| 702 | (make-local-variable 'require-final-newline) | 701 | (setq-local truncate-lines t) |
| 703 | (setq require-final-newline nil) | 702 | (setq-local require-final-newline nil) |
| 704 | (make-local-variable 'local-enable-local-variables) | 703 | (setq-local local-enable-local-variables nil) |
| 705 | (setq local-enable-local-variables nil) | ||
| 706 | 704 | ||
| 707 | ;; Prevent loss of data when saving the file. | 705 | ;; Prevent loss of data when saving the file. |
| 708 | (make-local-variable 'file-precious-flag) | 706 | (setq-local file-precious-flag t) |
| 709 | (setq file-precious-flag t) | ||
| 710 | 707 | ||
| 711 | (make-local-variable 'archive-read-only) | ||
| 712 | ;; Archives which are inside other archives and whose | 708 | ;; Archives which are inside other archives and whose |
| 713 | ;; names are invalid for this OS, can't be written. | 709 | ;; names are invalid for this OS, can't be written. |
| 714 | (setq archive-read-only | 710 | (setq-local archive-read-only |
| 715 | (or (not (file-writable-p (buffer-file-name))) | 711 | (or (not (file-writable-p (buffer-file-name))) |
| 716 | (and archive-subfile-mode | 712 | (and archive-subfile-mode |
| 717 | (string-match file-name-invalid-regexp | 713 | (string-match file-name-invalid-regexp |
| 718 | (aref archive-subfile-mode 0))))) | 714 | (aref archive-subfile-mode 0))))) |
| 719 | 715 | ||
| 720 | ;; Should we use a local copy when accessing from outside Emacs? | 716 | ;; Should we use a local copy when accessing from outside Emacs? |
| 721 | (make-local-variable 'archive-local-name) | 717 | (make-local-variable 'archive-local-name) |
| @@ -728,7 +724,7 @@ archive. | |||
| 728 | (string-match file-name-invalid-regexp | 724 | (string-match file-name-invalid-regexp |
| 729 | (buffer-file-name))))) | 725 | (buffer-file-name))))) |
| 730 | 726 | ||
| 731 | (setq major-mode 'archive-mode) | 727 | (setq major-mode #'archive-mode) |
| 732 | (setq mode-name (concat typename "-Archive")) | 728 | (setq mode-name (concat typename "-Archive")) |
| 733 | ;; Run archive-foo-mode-hook and archive-mode-hook | 729 | ;; Run archive-foo-mode-hook and archive-mode-hook |
| 734 | (run-mode-hooks (archive-name "mode-hook") 'archive-mode-hook) | 730 | (run-mode-hooks (archive-name "mode-hook") 'archive-mode-hook) |
| @@ -803,7 +799,7 @@ when parsing the archive." | |||
| 803 | (let ((create-lockfiles nil) ; avoid changing dir mtime by lock_file | 799 | (let ((create-lockfiles nil) ; avoid changing dir mtime by lock_file |
| 804 | (inhibit-read-only t)) | 800 | (inhibit-read-only t)) |
| 805 | (setq archive-proper-file-start (copy-marker (point-min) t)) | 801 | (setq archive-proper-file-start (copy-marker (point-min) t)) |
| 806 | (set (make-local-variable 'change-major-mode-hook) 'archive-desummarize) | 802 | (add-hook 'change-major-mode-hook #'archive-desummarize nil t) |
| 807 | (or shut-up | 803 | (or shut-up |
| 808 | (message "Parsing archive file...")) | 804 | (message "Parsing archive file...")) |
| 809 | (buffer-disable-undo (current-buffer)) | 805 | (buffer-disable-undo (current-buffer)) |
| @@ -968,7 +964,7 @@ using `make-temp-file', and the generated name is returned." | |||
| 968 | (delete-file tmpfile))))) | 964 | (delete-file tmpfile))))) |
| 969 | 965 | ||
| 970 | (defun archive-file-name-handler (op &rest args) | 966 | (defun archive-file-name-handler (op &rest args) |
| 971 | (or (eq op 'file-exists-p) | 967 | (or (eq op #'file-exists-p) |
| 972 | (let ((file-name-handler-alist nil)) | 968 | (let ((file-name-handler-alist nil)) |
| 973 | (apply op args)))) | 969 | (apply op args)))) |
| 974 | 970 | ||
| @@ -1461,12 +1457,11 @@ as a relative change like \"g+rw\" as for chmod(2)." | |||
| 1461 | (error "Renaming is not supported for this archive type")))) | 1457 | (error "Renaming is not supported for this archive type")))) |
| 1462 | 1458 | ||
| 1463 | ;; Revert the buffer and recompute the dired-like listing. | 1459 | ;; Revert the buffer and recompute the dired-like listing. |
| 1464 | (defun archive-mode-revert (&optional _no-auto-save _no-confirm) | 1460 | (defun archive--mode-revert (orig-fun &rest args) |
| 1465 | (let ((no (archive-get-lineno))) | 1461 | (let ((no (archive-get-lineno))) |
| 1466 | (setq archive-files nil) | 1462 | (setq archive-files nil) |
| 1467 | (let ((revert-buffer-function nil) | 1463 | (let ((coding-system-for-read 'no-conversion)) |
| 1468 | (coding-system-for-read 'no-conversion)) | 1464 | (apply orig-fun t t (cddr args))) |
| 1469 | (revert-buffer t t)) | ||
| 1470 | (archive-mode) | 1465 | (archive-mode) |
| 1471 | (goto-char archive-file-list-start) | 1466 | (goto-char archive-file-list-start) |
| 1472 | (archive-next-line no))) | 1467 | (archive-next-line no))) |