aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2010-12-07 21:18:02 -0500
committerStefan Monnier2010-12-07 21:18:02 -0500
commit33cf0fb2261201d66a7bf122d30718bdfbd7d38e (patch)
treed978f2a73b5765cbffc4bfa81f8a781b752d8ce5
parent60568d7458c91e54947bbe8c15af3cca79488b9b (diff)
downloademacs-33cf0fb2261201d66a7bf122d30718bdfbd7d38e.tar.gz
emacs-33cf0fb2261201d66a7bf122d30718bdfbd7d38e.zip
* lisp/files.el (dir-locals-collect-variables): Don't let errors stop us.
Use string-prefix-p. (file-name-version-regexp): New var. (file-name-sans-versions): * lisp/jka-cmpr-hook.el (jka-compr-build-file-regexp): Use it, (jka-compr-get-compression-info): Use dolist. (jka-compr-compression-info-list): Don't bother specifying version/backup regexps.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/files.el57
-rw-r--r--lisp/jka-cmpr-hook.el34
3 files changed, 66 insertions, 36 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 6eb650ae7bb..c6e035ebe97 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,14 @@
12010-12-08 Stefan Monnier <monnier@iro.umontreal.ca>
2
3 * files.el (dir-locals-collect-variables): Don't let errors stop us.
4 Use string-prefix-p.
5 (file-name-version-regexp): New var.
6 (file-name-sans-versions):
7 * jka-cmpr-hook.el (jka-compr-build-file-regexp): Use it,
8 (jka-compr-get-compression-info): Use dolist.
9 (jka-compr-compression-info-list): Don't bother specifying
10 version/backup regexps.
11
12010-12-07 Tassilo Horn <tassilo@member.fsf.org> 122010-12-07 Tassilo Horn <tassilo@member.fsf.org>
2 13
3 * simple.el (just-one-space): Make argument n default to 1 if 14 * simple.el (just-one-space): Make argument n default to 1 if
diff --git a/lisp/files.el b/lisp/files.el
index 2e2d4eeb1fb..43ba34f8bef 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3370,22 +3370,29 @@ ROOT is the root directory of the project.
3370Return the new variables list." 3370Return the new variables list."
3371 (let* ((file-name (buffer-file-name)) 3371 (let* ((file-name (buffer-file-name))
3372 (sub-file-name (if file-name 3372 (sub-file-name (if file-name
3373 ;; FIXME: Why not use file-relative-name?
3373 (substring file-name (length root))))) 3374 (substring file-name (length root)))))
3374 (dolist (entry class-variables variables) 3375 (condition-case err
3375 (let ((key (car entry))) 3376 (dolist (entry class-variables variables)
3376 (cond 3377 (let ((key (car entry)))
3377 ((stringp key) 3378 (cond
3378 ;; Don't include this in the previous condition, because we 3379 ((stringp key)
3379 ;; want to filter all strings before the next condition. 3380 ;; Don't include this in the previous condition, because we
3380 (when (and sub-file-name 3381 ;; want to filter all strings before the next condition.
3381 (>= (length sub-file-name) (length key)) 3382 (when (and sub-file-name
3382 (string= key (substring sub-file-name 0 (length key)))) 3383 (>= (length sub-file-name) (length key))
3383 (setq variables (dir-locals-collect-variables 3384 (string-prefix-p key sub-file-name))
3384 (cdr entry) root variables)))) 3385 (setq variables (dir-locals-collect-variables
3385 ((or (not key) 3386 (cdr entry) root variables))))
3386 (derived-mode-p key)) 3387 ((or (not key)
3387 (setq variables (dir-locals-collect-mode-variables 3388 (derived-mode-p key))
3388 (cdr entry) variables)))))))) 3389 (setq variables (dir-locals-collect-mode-variables
3390 (cdr entry) variables))))))
3391 (error
3392 ;; The file's content might be invalid (e.g. have a merge conflict), but
3393 ;; that shouldn't prevent the user from opening the file.
3394 (message ".dir-locals error: %s" (error-message-string err))
3395 nil))))
3389 3396
3390(defun dir-locals-set-directory-class (directory class &optional mtime) 3397(defun dir-locals-set-directory-class (directory class &optional mtime)
3391 "Declare that the DIRECTORY root is an instance of CLASS. 3398 "Declare that the DIRECTORY root is an instance of CLASS.
@@ -3516,7 +3523,9 @@ and `file-local-variables-alist', without applying them."
3516 (dir-name nil)) 3523 (dir-name nil))
3517 (cond 3524 (cond
3518 ((stringp variables-file) 3525 ((stringp variables-file)
3519 (setq dir-name (if (buffer-file-name) (file-name-directory (buffer-file-name)) default-directory)) 3526 (setq dir-name (if (buffer-file-name)
3527 (file-name-directory (buffer-file-name))
3528 default-directory))
3520 (setq class (dir-locals-read-from-file variables-file))) 3529 (setq class (dir-locals-read-from-file variables-file)))
3521 ((consp variables-file) 3530 ((consp variables-file)
3522 (setq dir-name (nth 0 variables-file)) 3531 (setq dir-name (nth 0 variables-file))
@@ -3826,21 +3835,25 @@ BACKUPNAME is the backup file name, which is the old file renamed."
3826 (and context 3835 (and context
3827 (set-file-selinux-context to-name context))) 3836 (set-file-selinux-context to-name context)))
3828 3837
3838(defvar file-name-version-regexp
3839 "\\(?:~\\|\\.~[-[:alnum:]:#@^._]+~\\)"
3840 "Regular expression matching the backup/version part of a file name.
3841Used by `file-name-sans-versions'.")
3842
3829(defun file-name-sans-versions (name &optional keep-backup-version) 3843(defun file-name-sans-versions (name &optional keep-backup-version)
3830 "Return file NAME sans backup versions or strings. 3844 "Return file NAME sans backup versions or strings.
3831This is a separate procedure so your site-init or startup file can 3845This is a separate procedure so your site-init or startup file can
3832redefine it. 3846redefine it.
3833If the optional argument KEEP-BACKUP-VERSION is non-nil, 3847If the optional argument KEEP-BACKUP-VERSION is non-nil,
3834we do not remove backup version numbers, only true file version numbers." 3848we do not remove backup version numbers, only true file version numbers.
3849See also `file-name-version-regexp'."
3835 (let ((handler (find-file-name-handler name 'file-name-sans-versions))) 3850 (let ((handler (find-file-name-handler name 'file-name-sans-versions)))
3836 (if handler 3851 (if handler
3837 (funcall handler 'file-name-sans-versions name keep-backup-version) 3852 (funcall handler 'file-name-sans-versions name keep-backup-version)
3838 (substring name 0 3853 (substring name 0
3839 (if keep-backup-version 3854 (unless keep-backup-version
3840 (length name) 3855 (string-match (concat file-name-version-regexp "\\'")
3841 (or (string-match "\\.~[-[:alnum:]:#@^._]+~\\'" name) 3856 name))))))
3842 (string-match "~\\'" name)
3843 (length name)))))))
3844 3857
3845(defun file-ownership-preserved-p (file) 3858(defun file-ownership-preserved-p (file)
3846 "Return t if deleting FILE and rewriting it would preserve the owner." 3859 "Return t if deleting FILE and rewriting it would preserve the owner."
diff --git a/lisp/jka-cmpr-hook.el b/lisp/jka-cmpr-hook.el
index 68f564c488f..aba9dac1434 100644
--- a/lisp/jka-cmpr-hook.el
+++ b/lisp/jka-cmpr-hook.el
@@ -73,10 +73,18 @@ Otherwise, it is nil.")
73 73
74(defun jka-compr-build-file-regexp () 74(defun jka-compr-build-file-regexp ()
75 (purecopy 75 (purecopy
76 (mapconcat 76 (let ((re-anchored '())
77 'jka-compr-info-regexp 77 (re-free '()))
78 jka-compr-compression-info-list 78 (dolist (e jka-compr-compression-info-list)
79 "\\|"))) 79 (let ((re (jka-compr-info-regexp e)))
80 (if (string-match "\\\\'\\'" re)
81 (push (substring re 0 (match-beginning 0)) re-anchored)
82 (push re re-free))))
83 (concat
84 (if re-free (concat (mapconcat 'identity re-free "\\|") "\\|"))
85 "\\(?:"
86 (mapconcat 'identity re-anchored "\\|")
87 "\\)" file-name-version-regexp "?\\'"))))
80 88
81;; Functions for accessing the return value of jka-compr-get-compression-info 89;; Functions for accessing the return value of jka-compr-get-compression-info
82(defun jka-compr-info-regexp (info) (aref info 0)) 90(defun jka-compr-info-regexp (info) (aref info 0))
@@ -97,11 +105,9 @@ The determination as to which compression scheme, if any, to use is
97based on the filename itself and `jka-compr-compression-info-list'." 105based on the filename itself and `jka-compr-compression-info-list'."
98 (catch 'compression-info 106 (catch 'compression-info
99 (let ((case-fold-search nil)) 107 (let ((case-fold-search nil))
100 (mapc 108 (dolist (x jka-compr-compression-info-list)
101 (function (lambda (x) 109 (and (string-match (jka-compr-info-regexp x) filename)
102 (and (string-match (jka-compr-info-regexp x) filename) 110 (throw 'compression-info x)))
103 (throw 'compression-info x))))
104 jka-compr-compression-info-list)
105 nil))) 111 nil)))
106 112
107(defun jka-compr-install () 113(defun jka-compr-install ()
@@ -198,7 +204,7 @@ options through Custom does this automatically."
198 ;; uncomp-message uncomp-prog uncomp-args 204 ;; uncomp-message uncomp-prog uncomp-args
199 ;; can-append strip-extension-flag file-magic-bytes] 205 ;; can-append strip-extension-flag file-magic-bytes]
200 (mapcar 'purecopy 206 (mapcar 'purecopy
201 '(["\\.Z\\(~\\|\\.~[0-9]+~\\)?\\'" 207 '(["\\.Z\\'"
202 "compressing" "compress" ("-c") 208 "compressing" "compress" ("-c")
203 ;; gzip is more common than uncompress. It can only read, not write. 209 ;; gzip is more common than uncompress. It can only read, not write.
204 "uncompressing" "gzip" ("-c" "-q" "-d") 210 "uncompressing" "gzip" ("-c" "-q" "-d")
@@ -206,7 +212,7 @@ options through Custom does this automatically."
206 ;; Formerly, these had an additional arg "-c", but that fails with 212 ;; Formerly, these had an additional arg "-c", but that fails with
207 ;; "Version 0.1pl2, 29-Aug-97." (RedHat 5.1 GNU/Linux) and 213 ;; "Version 0.1pl2, 29-Aug-97." (RedHat 5.1 GNU/Linux) and
208 ;; "Version 0.9.0b, 9-Sept-98". 214 ;; "Version 0.9.0b, 9-Sept-98".
209 ["\\.bz2\\(~\\|\\.~[0-9]+~\\)?\\'" 215 ["\\.bz2\\'"
210 "bzip2ing" "bzip2" nil 216 "bzip2ing" "bzip2" nil
211 "bunzip2ing" "bzip2" ("-d") 217 "bunzip2ing" "bzip2" ("-d")
212 nil t "BZh"] 218 nil t "BZh"]
@@ -214,15 +220,15 @@ options through Custom does this automatically."
214 "bzip2ing" "bzip2" nil 220 "bzip2ing" "bzip2" nil
215 "bunzip2ing" "bzip2" ("-d") 221 "bunzip2ing" "bzip2" ("-d")
216 nil nil "BZh"] 222 nil nil "BZh"]
217 ["\\.\\(?:tgz\\|svgz\\|sifz\\)\\(~\\|\\.~[0-9]+~\\)?\\'" 223 ["\\.\\(?:tgz\\|svgz\\|sifz\\)\\'"
218 "compressing" "gzip" ("-c" "-q") 224 "compressing" "gzip" ("-c" "-q")
219 "uncompressing" "gzip" ("-c" "-q" "-d") 225 "uncompressing" "gzip" ("-c" "-q" "-d")
220 t nil "\037\213"] 226 t nil "\037\213"]
221 ["\\.g?z\\(~\\|\\.~[0-9]+~\\)?\\'" 227 ["\\.g?z\\'"
222 "compressing" "gzip" ("-c" "-q") 228 "compressing" "gzip" ("-c" "-q")
223 "uncompressing" "gzip" ("-c" "-q" "-d") 229 "uncompressing" "gzip" ("-c" "-q" "-d")
224 t t "\037\213"] 230 t t "\037\213"]
225 ["\\.xz\\(~\\|\\.~[0-9]+~\\)?\\'" 231 ["\\.xz\\'"
226 "XZ compressing" "xz" ("-c" "-q") 232 "XZ compressing" "xz" ("-c" "-q")
227 "XZ uncompressing" "xz" ("-c" "-q" "-d") 233 "XZ uncompressing" "xz" ("-c" "-q" "-d")
228 t t "\3757zXZ\0"] 234 t t "\3757zXZ\0"]