aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/arc-mode.el
diff options
context:
space:
mode:
authorMiles Bader2007-10-11 16:14:00 +0000
committerMiles Bader2007-10-11 16:14:00 +0000
commitecb21060d5c1752d41d7a742be565c59b5fcb855 (patch)
treefadebcd18a69457a1d564f738c3f9bdcf512ab4b /lisp/arc-mode.el
parent42af7493ae7e7a14ee508800c7fa75b65a94c143 (diff)
parent58ade22bf16a9ec2ff0aee6c59d8db4d1703e94f (diff)
downloademacs-ecb21060d5c1752d41d7a742be565c59b5fcb855.tar.gz
emacs-ecb21060d5c1752d41d7a742be565c59b5fcb855.zip
Merge from emacs--devo--0
Patches applied: * emacs--devo--0 (patch 866-879) - Merge multi-tty branch - Update from CVS - Merge from emacs--rel--22 Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-257
Diffstat (limited to 'lisp/arc-mode.el')
-rw-r--r--lisp/arc-mode.el151
1 files changed, 120 insertions, 31 deletions
diff --git a/lisp/arc-mode.el b/lisp/arc-mode.el
index 20757586aea..421283da9e0 100644
--- a/lisp/arc-mode.el
+++ b/lisp/arc-mode.el
@@ -54,17 +54,17 @@
54;; ARCHIVE TYPES: Currently only the archives below are handled, but the 54;; ARCHIVE TYPES: Currently only the archives below are handled, but the
55;; structure for handling just about anything is in place. 55;; structure for handling just about anything is in place.
56;; 56;;
57;; Arc Lzh Zip Zoo 57;; Arc Lzh Zip Zoo Rar
58;; -------------------------------- 58;; ----------------------------------------
59;; View listing Intern Intern Intern Intern 59;; View listing Intern Intern Intern Intern Y
60;; Extract member Y Y Y Y 60;; Extract member Y Y Y Y Y
61;; Save changed member Y Y Y Y 61;; Save changed member Y Y Y Y N
62;; Add new member N N N N 62;; Add new member N N N N N
63;; Delete member Y Y Y Y 63;; Delete member Y Y Y Y N
64;; Rename member Y Y N N 64;; Rename member Y Y N N N
65;; Chmod - Y Y - 65;; Chmod - Y Y - N
66;; Chown - Y - - 66;; Chown - Y - - N
67;; Chgrp - Y - - 67;; Chgrp - Y - - N
68;; 68;;
69;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips 69;; Special thanks to Bill Brodie <wbrodie@panix.com> for very useful tips
70;; on the first released version of this package. 70;; on the first released version of this package.
@@ -104,7 +104,7 @@
104;;; Code: 104;;; Code:
105 105
106;; ------------------------------------------------------------------------- 106;; -------------------------------------------------------------------------
107;; Section: Configuration. 107;;; Section: Configuration.
108 108
109(defgroup archive nil 109(defgroup archive nil
110 "Simple editing of archives." 110 "Simple editing of archives."
@@ -318,7 +318,7 @@ Archive and member name will be added."
318 (string :format "%v"))) 318 (string :format "%v")))
319 :group 'archive-zoo) 319 :group 'archive-zoo)
320;; ------------------------------------------------------------------------- 320;; -------------------------------------------------------------------------
321;; Section: Variables 321;;; Section: Variables
322 322
323(defvar archive-subtype nil "Symbol describing archive type.") 323(defvar archive-subtype nil "Symbol describing archive type.")
324(defvar archive-file-list-start nil "Position of first contents line.") 324(defvar archive-file-list-start nil "Position of first contents line.")
@@ -463,7 +463,7 @@ Each descriptor is a vector of the form
463(make-variable-buffer-local 'archive-files) 463(make-variable-buffer-local 'archive-files)
464 464
465;; ------------------------------------------------------------------------- 465;; -------------------------------------------------------------------------
466;; Section: Support functions. 466;;; Section: Support functions.
467 467
468(eval-when-compile 468(eval-when-compile
469 (defsubst byte-after (pos) 469 (defsubst byte-after (pos)
@@ -619,7 +619,7 @@ Does not signal an error if optional argument NOERROR is non-nil."
619 (if (not noerror) 619 (if (not noerror)
620 (error "Line does not describe a member of the archive"))))) 620 (error "Line does not describe a member of the archive")))))
621;; ------------------------------------------------------------------------- 621;; -------------------------------------------------------------------------
622;; Section: the mode definition 622;;; Section: the mode definition
623 623
624;;;###autoload 624;;;###autoload
625(defun archive-mode (&optional force) 625(defun archive-mode (&optional force)
@@ -727,8 +727,18 @@ archive.
727 ;; Have seen capital "LHA's", and file has lower case "LHa's" too. 727 ;; Have seen capital "LHA's", and file has lower case "LHa's" too.
728 ;; Note this regexp is also in archive-exe-p. 728 ;; Note this regexp is also in archive-exe-p.
729 ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe) 729 ((looking-at "MZ\\(.\\|\n\\)\\{34\\}LH[aA]'s SFX ") 'lzh-exe)
730 ((looking-at "Rar!") 'rar)
730 (t (error "Buffer format not recognized"))))) 731 (t (error "Buffer format not recognized")))))
731;; ------------------------------------------------------------------------- 732;; -------------------------------------------------------------------------
733
734(defun archive-desummarize ()
735 (let ((inhibit-read-only t)
736 (modified (buffer-modified-p)))
737 (widen)
738 (delete-region (point-min) archive-proper-file-start)
739 (restore-buffer-modified-p modified)))
740
741
732(defun archive-summarize (&optional shut-up) 742(defun archive-summarize (&optional shut-up)
733 "Parse the contents of the archive file in the current buffer. 743 "Parse the contents of the archive file in the current buffer.
734Place a dired-like listing on the front; 744Place a dired-like listing on the front;
@@ -738,6 +748,8 @@ Optional argument SHUT-UP, if non-nil, means don't print messages
738when parsing the archive." 748when parsing the archive."
739 (widen) 749 (widen)
740 (let ((inhibit-read-only t)) 750 (let ((inhibit-read-only t))
751 (setq archive-proper-file-start (copy-marker (point-min) t))
752 (set (make-local-variable 'change-major-mode-hook) 'archive-desummarize)
741 (or shut-up 753 (or shut-up
742 (message "Parsing archive file...")) 754 (message "Parsing archive file..."))
743 (buffer-disable-undo (current-buffer)) 755 (buffer-disable-undo (current-buffer))
@@ -753,13 +765,9 @@ when parsing the archive."
753 765
754(defun archive-resummarize () 766(defun archive-resummarize ()
755 "Recreate the contents listing of an archive." 767 "Recreate the contents listing of an archive."
756 (let ((modified (buffer-modified-p)) 768 (let ((no (archive-get-lineno)))
757 (no (archive-get-lineno)) 769 (archive-desummarize)
758 (inhibit-read-only t))
759 (widen)
760 (delete-region (point-min) archive-proper-file-start)
761 (archive-summarize t) 770 (archive-summarize t)
762 (restore-buffer-modified-p modified)
763 (goto-char archive-file-list-start) 771 (goto-char archive-file-list-start)
764 (archive-next-line no))) 772 (archive-next-line no)))
765 773
@@ -796,7 +804,7 @@ This function changes the set of information shown for each files."
796 (setq archive-alternate-display (not archive-alternate-display)) 804 (setq archive-alternate-display (not archive-alternate-display))
797 (archive-resummarize)) 805 (archive-resummarize))
798;; ------------------------------------------------------------------------- 806;; -------------------------------------------------------------------------
799;; Section: Local archive copy handling 807;;; Section: Local archive copy handling
800 808
801(defun archive-unique-fname (fname dir) 809(defun archive-unique-fname (fname dir)
802 "Make sure a file FNAME can be created uniquely in directory DIR. 810 "Make sure a file FNAME can be created uniquely in directory DIR.
@@ -878,7 +886,7 @@ using `make-temp-file', and the generated name is returned."
878 (error nil)) 886 (error nil))
879 (if (string= name top) (setq again nil))))) 887 (if (string= name top) (setq again nil)))))
880;; ------------------------------------------------------------------------- 888;; -------------------------------------------------------------------------
881;; Section: Member extraction 889;;; Section: Member extraction
882 890
883(defun archive-file-name-handler (op &rest args) 891(defun archive-file-name-handler (op &rest args)
884 (or (eq op 'file-exists-p) 892 (or (eq op 'file-exists-p)
@@ -1100,7 +1108,7 @@ using `make-temp-file', and the generated name is returned."
1100 (funcall func buffer-file-name membuf name)) 1108 (funcall func buffer-file-name membuf name))
1101 (error "Adding a new member is not supported for this archive type")))) 1109 (error "Adding a new member is not supported for this archive type"))))
1102;; ------------------------------------------------------------------------- 1110;; -------------------------------------------------------------------------
1103;; Section: IO stuff 1111;;; Section: IO stuff
1104 1112
1105(defun archive-write-file-member () 1113(defun archive-write-file-member ()
1106 (save-excursion 1114 (save-excursion
@@ -1170,7 +1178,7 @@ using `make-temp-file', and the generated name is returned."
1170 (set-buffer-modified-p nil)) 1178 (set-buffer-modified-p nil))
1171 t)) 1179 t))
1172;; ------------------------------------------------------------------------- 1180;; -------------------------------------------------------------------------
1173;; Section: Marking and unmarking. 1181;;; Section: Marking and unmarking.
1174 1182
1175(defun archive-flag-deleted (p &optional type) 1183(defun archive-flag-deleted (p &optional type)
1176 "In archive mode, mark this member to be deleted from the archive. 1184 "In archive mode, mark this member to be deleted from the archive.
@@ -1235,7 +1243,7 @@ Use \\[archive-unmark-all-files] to remove all marks."
1235 (and default 1243 (and default
1236 (list (archive-get-descr)))))) 1244 (list (archive-get-descr))))))
1237;; ------------------------------------------------------------------------- 1245;; -------------------------------------------------------------------------
1238;; Section: Operate 1246;;; Section: Operate
1239 1247
1240(defun archive-next-line (p) 1248(defun archive-next-line (p)
1241 (interactive "p") 1249 (interactive "p")
@@ -1353,7 +1361,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
1353 (let ((inhibit-read-only t)) 1361 (let ((inhibit-read-only t))
1354 (undo))) 1362 (undo)))
1355;; ------------------------------------------------------------------------- 1363;; -------------------------------------------------------------------------
1356;; Section: Arc Archives 1364;;; Section: Arc Archives
1357 1365
1358(defun archive-arc-summarize () 1366(defun archive-arc-summarize ()
1359 (let ((p 1) 1367 (let ((p 1)
@@ -1423,7 +1431,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
1423 (delete-char 13) 1431 (delete-char 13)
1424 (insert-unibyte name))))) 1432 (insert-unibyte name)))))
1425;; ------------------------------------------------------------------------- 1433;; -------------------------------------------------------------------------
1426;; Section: Lzh Archives 1434;;; Section: Lzh Archives
1427 1435
1428(defun archive-lzh-summarize (&optional start) 1436(defun archive-lzh-summarize (&optional start)
1429 (let ((p (or start 1)) ;; 1 for .lzh, something further on for .exe 1437 (let ((p (or start 1)) ;; 1 for .lzh, something further on for .exe
@@ -1646,7 +1654,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
1646 files "a unix-style mode" 8)) 1654 files "a unix-style mode" 8))
1647 1655
1648;; ------------------------------------------------------------------------- 1656;; -------------------------------------------------------------------------
1649;; Section: Lzh Self-Extracting .exe Archives 1657;;; Section: Lzh Self-Extracting .exe Archives
1650;; 1658;;
1651;; No support for modifying these files. It looks like the lha for unix 1659;; No support for modifying these files. It looks like the lha for unix
1652;; program (as of version 1.14i) can't create or retain the DOS exe part. 1660;; program (as of version 1.14i) can't create or retain the DOS exe part.
@@ -1673,7 +1681,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
1673 "Extract a member from an LZH self-extracting exe, for `archive-mode'.") 1681 "Extract a member from an LZH self-extracting exe, for `archive-mode'.")
1674 1682
1675;; ------------------------------------------------------------------------- 1683;; -------------------------------------------------------------------------
1676;; Section: Zip Archives 1684;;; Section: Zip Archives
1677 1685
1678(defun archive-zip-summarize () 1686(defun archive-zip-summarize ()
1679 (goto-char (- (point-max) (- 22 18))) 1687 (goto-char (- (point-max) (- 22 18)))
@@ -1780,7 +1788,7 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
1780 (t (message "Don't know how to change mode for this member")))) 1788 (t (message "Don't know how to change mode for this member"))))
1781 )))) 1789 ))))
1782;; ------------------------------------------------------------------------- 1790;; -------------------------------------------------------------------------
1783;; Section: Zoo Archives 1791;;; Section: Zoo Archives
1784 1792
1785(defun archive-zoo-summarize () 1793(defun archive-zoo-summarize ()
1786 (let ((p (1+ (archive-l-e 25 4))) 1794 (let ((p (1+ (archive-l-e 25 4)))
@@ -1848,6 +1856,87 @@ This doesn't recover lost files, it just undoes changes in the buffer itself."
1848 1856
1849(defun archive-zoo-extract (archive name) 1857(defun archive-zoo-extract (archive name)
1850 (archive-extract-by-stdout archive name archive-zoo-extract)) 1858 (archive-extract-by-stdout archive name archive-zoo-extract))
1859
1860;; -------------------------------------------------------------------------
1861;;; Section: Rar Archives
1862
1863(defun archive-rar-summarize ()
1864 (let* ((file buffer-file-name)
1865 (copy (file-local-copy file))
1866 header footer
1867 (maxname 10)
1868 (maxsize 5)
1869 (files ()))
1870 (with-temp-buffer
1871 (call-process "unrar-free" nil t nil "--list" (or file copy))
1872 (if copy (delete-file copy))
1873 (goto-char (point-min))
1874 (re-search-forward "^-+\n")
1875 (setq header
1876 (buffer-substring (save-excursion (re-search-backward "^[^ ]"))
1877 (point)))
1878 (while (looking-at (concat " \\(.*\\)\n" ;Name.
1879 ;; Size ; Packed.
1880 " +\\([0-9]+\\) +[0-9]+"
1881 ;; Ratio ; Date'
1882 " +\\([0-9%]+\\) +\\([-0-9]+\\)"
1883 ;; Time ; Attr.
1884 " +\\([0-9:]+\\) +......"
1885 ;; CRC; Meth ; Var.
1886 " +[0-9A-F]+ +[^ \n]+ +[0-9.]+\n"))
1887 (goto-char (match-end 0))
1888 (let ((name (match-string 1))
1889 (size (match-string 2)))
1890 (if (> (length name) maxname) (setq maxname (length name)))
1891 (if (> (length size) maxsize) (setq maxsize (length size)))
1892 (push (vector name name nil nil
1893 ;; Size, Ratio.
1894 size (match-string 3)
1895 ;; Date, Time.
1896 (match-string 4) (match-string 5))
1897 files)))
1898 (setq footer (buffer-substring (point) (point-max))))
1899 (setq files (nreverse files))
1900 (goto-char (point-min))
1901 (let* ((format (format " %%s %%s %%%ds %%5s %%s" maxsize))
1902 (sep (format format "--------" "-----" (make-string maxsize ?-)
1903 "-----" ""))
1904 (column (length sep)))
1905 (insert (format format " Date " "Time " "Size " "Ratio" " Filename") "\n")
1906 (insert sep (make-string maxname ?-) "\n")
1907 (archive-summarize-files (mapcar (lambda (desc)
1908 (let ((text
1909 (format format
1910 (aref desc 6)
1911 (aref desc 7)
1912 (aref desc 4)
1913 (aref desc 5)
1914 (aref desc 1))))
1915 (vector text
1916 column
1917 (length text))))
1918 files))
1919 (insert sep (make-string maxname ?-) "\n")
1920 (apply 'vector files))))
1921
1922(defun archive-rar-extract (archive name)
1923 ;; unrar-free seems to have no way to extract to stdout or even to a file.
1924 (if (file-name-absolute-p name)
1925 ;; The code below assumes the name is relative and may do undesirable
1926 ;; things otherwise.
1927 (error "Can't extract files with non-relative names")
1928 (let ((dest (make-temp-file "arc-rar" 'dir)))
1929 (unwind-protect
1930 (progn
1931 (call-process "unrar-free" nil nil nil
1932 "--extract" archive name dest)
1933 (insert-file-contents-literally (expand-file-name name dest)))
1934 (delete-file (expand-file-name name dest))
1935 (while (file-name-directory name)
1936 (setq name (directory-file-name (file-name-directory name)))
1937 (delete-directory (expand-file-name name dest)))
1938 (delete-directory dest)))))
1939
1851;; ------------------------------------------------------------------------- 1940;; -------------------------------------------------------------------------
1852;; This line was a mistake; it is kept now for compatibility. 1941;; This line was a mistake; it is kept now for compatibility.
1853;; rms 15 Oct 98 1942;; rms 15 Oct 98