From 49bc8586b7abc8e1e36027ca5eec0d0488a27474 Mon Sep 17 00:00:00 2001 From: Stefan Kangas Date: Fri, 23 Oct 2020 16:29:46 +0200 Subject: Move some test data to follow our conventions * test/data/emacs-module/mod-test.c: Move from here... * test/src/emacs-module-resources/mod-test.c: ...to here. * test/src/emacs-module-tests.el (ert-x): Require. (mod-test-file, module/describe-function-1): * test/Makefile.in (test_module_dir): Adjust for move. * test/data/files-bug18141.el.gz: Move from here... * test/lisp/files-resources/files-bug18141.el.gz: ... to here. * test/lisp/files-tests.el (ert-x): Require. (files-test-bug-18141-file): Use ert-resource-file. * test/data/mailcap/mime.types: Move from here... * test/lisp/net/mailcap-resources/mime.types: ...to here. * test/lisp/net/mailcap-tests.el (ert-x): Require. (mailcap-tests-path): Use ert-resource-file. * test/data/somelib.el: * test/data/somelib2.el: Move from here... * test/src/lread-resources/somelib.el: * test/src/lread-resources/somelib2.el: ...to here. * test/src/lread-tests.el (ert, ert-x): Require. (lread-test-bug26837): Use ert-resource-directory. * test/data/syntax-comments.txt: Move from here.... * test/src/syntax-resources/syntax-comments.txt: ...to here. * test/src/syntax-tests.el (ert-x): Require. (syntax-comments, syntax-br-comments, syntax-pps-comments): Use ert-resource-file. * test/data/xref/file1.txt: * test/data/xref/file2.txt: Move from here... * test/lisp/progmodes/xref-resources/file1.txt: * test/lisp/progmodes/xref-resources/file2.txt: ...to here. * test/lisp/progmodes/xref-tests.el (ert, ert-x): Require. (xref-tests-data-dir): Use ert-resource-directory. --- test/lisp/files-resources/files-bug18141.el.gz | Bin 0 -> 77 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/lisp/files-resources/files-bug18141.el.gz (limited to 'test/lisp/files-resources') diff --git a/test/lisp/files-resources/files-bug18141.el.gz b/test/lisp/files-resources/files-bug18141.el.gz new file mode 100644 index 00000000000..53d463e85b5 Binary files /dev/null and b/test/lisp/files-resources/files-bug18141.el.gz differ -- cgit v1.2.3 From ad5faa424a5d2f0d67265906d21f7af98220df26 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Fri, 23 Jul 2021 15:51:11 +0200 Subject: Add auto-mode-alist functionality to .dir-locals.el * doc/emacs/custom.texi (Directory Variables): Document auto-mode-alist in .dir-locals.el (Bug#18721) * doc/emacs/modes.texi (Choosing Modes): Update. * lisp/files.el (set-auto-mode--apply-alist): New function, from set-auto-mode. (set-auto-mode): Check directory locals for auto-mode-alist. (dir-locals-collect-variables): Add "predicate" parameter. (hack-dir-local--get-variables): New function, from hack-dir-local-variables. (hack-dir-local-variables): Call hack-dir-local--get-variables. * test/lisp/files-resources/.dir-locals.el: New file. * test/lisp/files-resources/whatever.quux: New file. * test/lisp/files-tests.el (files-tests-data-dir): New variable. (files-test-dir-locals-auto-mode-alist): New test. --- doc/emacs/custom.texi | 10 ++ doc/emacs/modes.texi | 10 +- etc/NEWS | 6 ++ lisp/files.el | 169 +++++++++++++++++++------------ test/lisp/files-resources/.dir-locals.el | 2 + test/lisp/files-resources/whatever.quux | 2 + test/lisp/files-tests.el | 5 + 7 files changed, 136 insertions(+), 68 deletions(-) create mode 100644 test/lisp/files-resources/.dir-locals.el create mode 100644 test/lisp/files-resources/whatever.quux (limited to 'test/lisp/files-resources') diff --git a/doc/emacs/custom.texi b/doc/emacs/custom.texi index ce6290c1171..999234e6d33 100644 --- a/doc/emacs/custom.texi +++ b/doc/emacs/custom.texi @@ -1415,6 +1415,16 @@ meanings as they would have in file local variables. @code{coding} cannot be specified as a directory local variable. @xref{File Variables}. +The special key @code{auto-mode-alist} in a @file{.dir-locals.el} lets +you set a file's major mode. It works much like the variable +@code{auto-mode-alist} (@pxref{Choosing Modes}). For example, here is +how you can tell Emacs that @file{.def} source files in this directory +should be in C mode: + +@example +((auto-mode-alist . (("\\.def\\'" . c-mode)))) +@end example + @findex add-dir-local-variable @findex delete-dir-local-variable @findex copy-file-locals-to-dir-locals diff --git a/doc/emacs/modes.texi b/doc/emacs/modes.texi index cc25d3e1e33..9014221edff 100644 --- a/doc/emacs/modes.texi +++ b/doc/emacs/modes.texi @@ -357,8 +357,12 @@ preferences. If you personally want to use a minor mode for a particular file type, it is better to enable the minor mode via a major mode hook (@pxref{Major Modes}). + Second, Emacs checks whether the file's extension matches an entry +in any directory-local @code{auto-mode-alist}. These are found using +the @file{.dir-locals.el} facility (@pxref{Directory Variables}). + @vindex interpreter-mode-alist - Second, if there is no file variable specifying a major mode, Emacs + Third, if there is no file variable specifying a major mode, Emacs checks whether the file's contents begin with @samp{#!}. If so, that indicates that the file can serve as an executable shell command, which works by running an interpreter named on the file's first line @@ -376,7 +380,7 @@ same is true for man pages which start with the magic string @samp{'\"} to specify a list of troff preprocessors. @vindex magic-mode-alist - Third, Emacs tries to determine the major mode by looking at the + Fourth, Emacs tries to determine the major mode by looking at the text at the start of the buffer, based on the variable @code{magic-mode-alist}. By default, this variable is @code{nil} (an empty list), so Emacs skips this step; however, you can customize it @@ -404,7 +408,7 @@ where @var{match-function} is a Lisp function that is called at the beginning of the buffer; if the function returns non-@code{nil}, Emacs set the major mode with @var{mode-function}. - Fourth---if Emacs still hasn't found a suitable major mode---it + Fifth---if Emacs still hasn't found a suitable major mode---it looks at the file's name. The correspondence between file names and major modes is controlled by the variable @code{auto-mode-alist}. Its value is a list in which each element has this form, diff --git a/etc/NEWS b/etc/NEWS index 29953a8fa26..c7249456ff6 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2289,6 +2289,12 @@ This command, called interactively, toggles the local value of ** Miscellaneous ++++ +*** .dir-locals.el now supports setting 'auto-mode-alist'. +The new 'auto-mode-alist' specification in .dir-local.el files can now +be used to override the global 'auto-mode-alist' in the current +directory tree. + --- *** New utility function 'make-separator-line'. diff --git a/lisp/files.el b/lisp/files.el index 412562fc9a3..dc803d3a4cf 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3195,11 +3195,62 @@ If FUNCTION is nil, then it is not called.") "Upper limit on `magic-mode-alist' regexp matches. Also applies to `magic-fallback-mode-alist'.") +(defun set-auto-mode--apply-alist (alist keep-mode-if-same dir-local) + "Helper function for `set-auto-mode'. +This function takes an alist of the same form as +`auto-mode-alist'. It then tries to find the appropriate match +in the alist for the current buffer; setting the mode if +possible. Returns non-`nil' if the mode was set, `nil' +otherwise. DIR-LOCAL is a boolean which, if true, says that this +call is via directory-locals and extra checks should be done." + (if buffer-file-name + (let (mode + (name buffer-file-name) + (remote-id (file-remote-p buffer-file-name)) + (case-insensitive-p (file-name-case-insensitive-p + buffer-file-name))) + ;; Remove backup-suffixes from file name. + (setq name (file-name-sans-versions name)) + ;; Remove remote file name identification. + (when (and (stringp remote-id) + (string-match (regexp-quote remote-id) name)) + (setq name (substring name (match-end 0)))) + (while name + ;; Find first matching alist entry. + (setq mode + (if case-insensitive-p + ;; Filesystem is case-insensitive. + (let ((case-fold-search t)) + (assoc-default alist 'string-match)) + ;; Filesystem is case-sensitive. + (or + ;; First match case-sensitively. + (let ((case-fold-search nil)) + (assoc-default name alist 'string-match)) + ;; Fallback to case-insensitive match. + (and auto-mode-case-fold + (let ((case-fold-search t)) + (assoc-default name alist 'string-match)))))) + (if (and mode + (consp mode) + (cadr mode)) + (setq mode (car mode) + name (substring name 0 (match-beginning 0))) + (setq name nil))) + (when (and dir-local mode) + (unless (string-suffix-p "-mode" (symbol-name mode)) + (message "Ignoring invalid mode `%s'" (symbol-name mode)) + (setq mode nil))) + (when mode + (set-auto-mode-0 mode keep-mode-if-same) + t)))) + (defun set-auto-mode (&optional keep-mode-if-same) "Select major mode appropriate for current buffer. To find the right major mode, this function checks for a -*- mode tag checks for a `mode:' entry in the Local Variables section of the file, +checks if there an `auto-mode-alist' entry in `.dir-locals.el', checks if it uses an interpreter listed in `interpreter-mode-alist', matches the buffer beginning against `magic-mode-alist', compares the file name against the entries in `auto-mode-alist', @@ -3256,6 +3307,14 @@ we don't actually set it to the same mode the buffer already has." (or (set-auto-mode-0 mode keep-mode-if-same) ;; continuing would call minor modes again, toggling them off (throw 'nop nil)))))) + ;; Check for auto-mode-alist entry in dir-locals. + (unless done + (with-demoted-errors "Directory-local variables error: %s" + ;; Note this is a no-op if enable-local-variables is nil. + (let* ((mode-alist (cdr (hack-dir-local--get-variables + (lambda (key) (eq key 'auto-mode-alist)))))) + (setq done (set-auto-mode--apply-alist mode-alist + keep-mode-if-same t))))) (and (not done) (setq mode (hack-local-variables t (not try-locals))) (not (memq mode modes)) ; already tried and failed @@ -3307,45 +3366,8 @@ we don't actually set it to the same mode the buffer already has." (set-auto-mode-0 done keep-mode-if-same))) ;; Next compare the filename against the entries in auto-mode-alist. (unless done - (if buffer-file-name - (let ((name buffer-file-name) - (remote-id (file-remote-p buffer-file-name)) - (case-insensitive-p (file-name-case-insensitive-p - buffer-file-name))) - ;; Remove backup-suffixes from file name. - (setq name (file-name-sans-versions name)) - ;; Remove remote file name identification. - (when (and (stringp remote-id) - (string-match (regexp-quote remote-id) name)) - (setq name (substring name (match-end 0)))) - (while name - ;; Find first matching alist entry. - (setq mode - (if case-insensitive-p - ;; Filesystem is case-insensitive. - (let ((case-fold-search t)) - (assoc-default name auto-mode-alist - 'string-match)) - ;; Filesystem is case-sensitive. - (or - ;; First match case-sensitively. - (let ((case-fold-search nil)) - (assoc-default name auto-mode-alist - 'string-match)) - ;; Fallback to case-insensitive match. - (and auto-mode-case-fold - (let ((case-fold-search t)) - (assoc-default name auto-mode-alist - 'string-match)))))) - (if (and mode - (consp mode) - (cadr mode)) - (setq mode (car mode) - name (substring name 0 (match-beginning 0))) - (setq name nil)) - (when mode - (set-auto-mode-0 mode keep-mode-if-same) - (setq done t)))))) + (setq done (set-auto-mode--apply-alist auto-mode-alist + keep-mode-if-same nil))) ;; Next try matching the buffer beginning against magic-fallback-mode-alist. (unless done (if (setq done (save-excursion @@ -4166,10 +4188,13 @@ Returns the new list." ;; Need a new cons in case we setcdr later. (push (cons variable value) variables))))) -(defun dir-locals-collect-variables (class-variables root variables) +(defun dir-locals-collect-variables (class-variables root variables + &optional predicate) "Collect entries from CLASS-VARIABLES into VARIABLES. ROOT is the root directory of the project. -Return the new variables list." +Return the new variables list. +If PREDICATE is given, it is used to test a symbol key in the alist +to see whether it should be considered." (let* ((file-name (or (buffer-file-name) ;; Handle non-file buffers, too. (expand-file-name default-directory))) @@ -4188,9 +4213,11 @@ Return the new variables list." (>= (length sub-file-name) (length key)) (string-prefix-p key sub-file-name)) (setq variables (dir-locals-collect-variables - (cdr entry) root variables)))) - ((or (not key) - (derived-mode-p key)) + (cdr entry) root variables predicate)))) + ((if predicate + (funcall predicate key) + (or (not key) + (derived-mode-p key))) (let* ((alist (cdr entry)) (subdirs (assq 'subdirs alist))) (if (or (not subdirs) @@ -4487,13 +4514,13 @@ Return the new class name, which is a symbol named DIR." (defvar hack-dir-local-variables--warned-coding nil) -(defun hack-dir-local-variables () +(defun hack-dir-local--get-variables (predicate) "Read per-directory local variables for the current buffer. -Store the directory-local variables in `dir-local-variables-alist' -and `file-local-variables-alist', without applying them. - -This does nothing if either `enable-local-variables' or -`enable-dir-local-variables' are nil." +Return a cons of the form (DIR . ALIST), where DIR is the +directory name (maybe nil) and ALIST is an alist of all variables +that might apply. These will be filtered according to the +buffer's directory, but not according to its mode. +PREDICATE is passed to `dir-locals-collect-variables'." (when (and enable-local-variables enable-dir-local-variables (or enable-remote-dir-locals @@ -4512,21 +4539,33 @@ This does nothing if either `enable-local-variables' or (setq dir-name (nth 0 dir-or-cache)) (setq class (nth 1 dir-or-cache)))) (when class - (let ((variables - (dir-locals-collect-variables - (dir-locals-get-class-variables class) dir-name nil))) - (when variables - (dolist (elt variables) - (if (eq (car elt) 'coding) - (unless hack-dir-local-variables--warned-coding - (setq hack-dir-local-variables--warned-coding t) - (display-warning 'files - "Coding cannot be specified by dir-locals")) - (unless (memq (car elt) '(eval mode)) - (setq dir-local-variables-alist - (assq-delete-all (car elt) dir-local-variables-alist))) - (push elt dir-local-variables-alist))) - (hack-local-variables-filter variables dir-name))))))) + (cons dir-name + (dir-locals-collect-variables + (dir-locals-get-class-variables class) + dir-name nil predicate)))))) + +(defun hack-dir-local-variables () + "Read per-directory local variables for the current buffer. +Store the directory-local variables in `dir-local-variables-alist' +and `file-local-variables-alist', without applying them. + +This does nothing if either `enable-local-variables' or +`enable-dir-local-variables' are nil." + (let* ((items (hack-dir-local--get-variables nil)) + (dir-name (car items)) + (variables (cdr items))) + (when variables + (dolist (elt variables) + (if (eq (car elt) 'coding) + (unless hack-dir-local-variables--warned-coding + (setq hack-dir-local-variables--warned-coding t) + (display-warning 'files + "Coding cannot be specified by dir-locals")) + (unless (memq (car elt) '(eval mode)) + (setq dir-local-variables-alist + (assq-delete-all (car elt) dir-local-variables-alist))) + (push elt dir-local-variables-alist))) + (hack-local-variables-filter variables dir-name)))) (defun hack-dir-local-variables-non-file-buffer () "Apply directory-local variables to a non-file buffer. diff --git a/test/lisp/files-resources/.dir-locals.el b/test/lisp/files-resources/.dir-locals.el new file mode 100644 index 00000000000..84997b8a0c0 --- /dev/null +++ b/test/lisp/files-resources/.dir-locals.el @@ -0,0 +1,2 @@ +;; This is used by files-tests.el. +((auto-mode-alist . (("\\.quux\\'" . tcl-mode)))) diff --git a/test/lisp/files-resources/whatever.quux b/test/lisp/files-resources/whatever.quux new file mode 100644 index 00000000000..595583b911e --- /dev/null +++ b/test/lisp/files-resources/whatever.quux @@ -0,0 +1,2 @@ +# Used by files-test.el. +# Due to .dir-locals.el this should end up in Tcl mode. diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index a6b0c900bec..fce7e3fd719 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1534,5 +1534,10 @@ The door of all subtleties! (should-error (file-name-with-extension "Jack" ".")) (should-error (file-name-with-extension "/is/a/directory/" "css"))) +(ert-deftest files-test-dir-locals-auto-mode-alist () + "Test an `auto-mode-alist' entry in `.dir-locals.el'" + (find-file (ert-resource-file "whatever.quux")) + (should (eq major-mode 'tcl-mode))) + (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From 9ac6ff53b105925400a773a5088c9d0ec5b095a4 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 24 Jul 2021 11:16:15 +0200 Subject: Make the test for auto-mode-alist from .dir-local.el stricter * lisp/files.el (set-auto-mode--dir-local-valid-p): New function. (set-auto-mode--apply-alist): Use it as a stricter test. --- lisp/files.el | 15 +++++++++++---- test/lisp/files-resources/.dir-locals.el | 5 ++++- test/lisp/files-resources/auto-test.zot1 | 1 + test/lisp/files-resources/auto-test.zot2 | 1 + test/lisp/files-resources/auto-test.zot3 | 1 + test/lisp/files-tests.el | 8 +++++++- 6 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 test/lisp/files-resources/auto-test.zot1 create mode 100644 test/lisp/files-resources/auto-test.zot2 create mode 100644 test/lisp/files-resources/auto-test.zot3 (limited to 'test/lisp/files-resources') diff --git a/lisp/files.el b/lisp/files.el index d915c2a30b5..aab839eab10 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3238,14 +3238,21 @@ extra checks should be done." (setq mode (car mode) name (substring name 0 (match-beginning 0))) (setq name nil))) - (when (and dir-local mode) - (unless (string-suffix-p "-mode" (symbol-name mode)) - (message "Ignoring invalid mode `%s'" (symbol-name mode)) - (setq mode nil))) + (when (and dir-local mode + (not (set-auto-mode--dir-local-valid-p mode))) + (message "Ignoring invalid mode `%s'" mode) + (setq mode nil)) (when mode (set-auto-mode-0 mode keep-mode-if-same) t)))) +(defun set-auto-mode--dir-local-valid-p (mode) + "Say whether MODE can be used in a .dir-local.el `auto-mode-alist'." + (and (symbolp mode) + (string-suffix-p "-mode" (symbol-name mode)) + (commandp mode) + (not (provided-mode-derived-p mode 'special-mode)))) + (defun set-auto-mode (&optional keep-mode-if-same) "Select major mode appropriate for current buffer. diff --git a/test/lisp/files-resources/.dir-locals.el b/test/lisp/files-resources/.dir-locals.el index 84997b8a0c0..84393aa54d5 100644 --- a/test/lisp/files-resources/.dir-locals.el +++ b/test/lisp/files-resources/.dir-locals.el @@ -1,2 +1,5 @@ ;; This is used by files-tests.el. -((auto-mode-alist . (("\\.quux\\'" . tcl-mode)))) +((auto-mode-alist . (("\\.quux\\'" . tcl-mode) + ("\\.zot1\\'" . foobar) + ("\\.zot2\\'" . (lambda ())) + ("\\.zot3\\'" . dired-mode)))) diff --git a/test/lisp/files-resources/auto-test.zot1 b/test/lisp/files-resources/auto-test.zot1 new file mode 100644 index 00000000000..80acfcc9f7a --- /dev/null +++ b/test/lisp/files-resources/auto-test.zot1 @@ -0,0 +1 @@ +zot1 diff --git a/test/lisp/files-resources/auto-test.zot2 b/test/lisp/files-resources/auto-test.zot2 new file mode 100644 index 00000000000..975fc765513 --- /dev/null +++ b/test/lisp/files-resources/auto-test.zot2 @@ -0,0 +1 @@ +zot2 diff --git a/test/lisp/files-resources/auto-test.zot3 b/test/lisp/files-resources/auto-test.zot3 new file mode 100644 index 00000000000..faa07151606 --- /dev/null +++ b/test/lisp/files-resources/auto-test.zot3 @@ -0,0 +1 @@ +zot3 diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index fce7e3fd719..a5c82360177 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1537,7 +1537,13 @@ The door of all subtleties! (ert-deftest files-test-dir-locals-auto-mode-alist () "Test an `auto-mode-alist' entry in `.dir-locals.el'" (find-file (ert-resource-file "whatever.quux")) - (should (eq major-mode 'tcl-mode))) + (should (eq major-mode 'tcl-mode)) + (find-file (ert-resource-file "auto-test.zot1")) + (should (eq major-mode 'fundamental-mode)) + (find-file (ert-resource-file "auto-test.zot2")) + (should (eq major-mode 'fundamental-mode)) + (find-file (ert-resource-file "auto-test.zot3")) + (should (eq major-mode 'fundamental-mode))) (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From 9b80fe55f9725a039a2f367ffccea164c6ca9cf9 Mon Sep 17 00:00:00 2001 From: John Cummings Date: Thu, 11 Nov 2021 04:37:46 +0100 Subject: Add tests for 'insert-directory' * test/lisp/files-tests.el: Add 'insert-directory' tests. * test/lisp/files-resources/insert-directory/: Create directories and files to use for testing 'insert-directory'. Add tests for 'insert-directory' base functionality and regression tests for the issue where free space was reported for the current directory instead of the target of 'list-directory' (Bug#50630). --- .../files-resources/insert-directory/test_dir/bar | 0 .../files-resources/insert-directory/test_dir/foo | 0 .../insert-directory/test_dir_other/bar | 0 .../insert-directory/test_dir_other/foo | 0 test/lisp/files-tests.el | 74 ++++++++++++++++++++++ 5 files changed, 74 insertions(+) create mode 100644 test/lisp/files-resources/insert-directory/test_dir/bar create mode 100644 test/lisp/files-resources/insert-directory/test_dir/foo create mode 100644 test/lisp/files-resources/insert-directory/test_dir_other/bar create mode 100644 test/lisp/files-resources/insert-directory/test_dir_other/foo (limited to 'test/lisp/files-resources') diff --git a/test/lisp/files-resources/insert-directory/test_dir/bar b/test/lisp/files-resources/insert-directory/test_dir/bar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/files-resources/insert-directory/test_dir/foo b/test/lisp/files-resources/insert-directory/test_dir/foo new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/bar b/test/lisp/files-resources/insert-directory/test_dir_other/bar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/foo b/test/lisp/files-resources/insert-directory/test_dir_other/foo new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 1e20317739a..d66ed62e286 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1807,5 +1807,79 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil." (should (equal (file-name-split "/foo/bar/") '("" "foo" "bar" ""))) (should (equal (file-name-split "foo/bar/") '("foo" "bar" "")))) +;; `insert-directory' output tests. +(let* ((data-dir "insert-directory") + (test-dir (file-name-as-directory + (ert-resource-file + (concat data-dir "/test_dir")))) + (test-dir-other (file-name-as-directory + (ert-resource-file + (concat data-dir "/test_dir_other")))) + (test-files `(,test-dir "foo" "bar")) ;expected files to be found + ;; Free space test data for `insert-directory'. + ;; Meaning: (path free-space-bytes-to-stub expected-free-space-string) + (free-data `((,test-dir 10 "available 10 B") + (,test-dir-other 100 "available 100 B") + (:default 999 "available 999 B")))) + + + (defun files-tests--look-up-free-data (path) + "Look up free space test data, with a default for unspecified paths." + (let ((path (file-name-as-directory path))) + (cdr (or (assoc path free-data) + (assoc :default free-data))))) + + (defun files-tests--make-file-system-info-stub (&optional static-path) + "Return a stub for `file-system-info' using dynamic or static test data. +If that data should be static, pass STATIC-PATH to choose which +path's data to use." + (lambda (path) + (let* ((path (cond (static-path) + ;; file-system-info knows how to handle ".", so we + ;; do the same thing + ((equal "." path) default-directory) + (path))) + (return-size + (car (files-tests--look-up-free-data path)))) + (list return-size return-size return-size)))) + + (defun files-tests--insert-directory-output (dir &optional verbose) + "Run `insert-directory' and return its output." + (with-current-buffer-window "files-tests--insert-directory" nil nil + (insert-directory dir "-l" nil t) + (buffer-substring-no-properties (point-min) (point-max)))) + + (ert-deftest files-tests-insert-directory-shows-files () + "Verify `insert-directory' reports the files in the directory." + (let* ((test-dir (car test-files)) + (files (cdr test-files)) + (output (files-tests--insert-directory-output test-dir))) + (dolist (file files) + (should (string-match-p file output))))) + + (defun files-tests--insert-directory-shows-given-free (dir &optional + info-func) + "Run `insert-directory' and verify it reports the correct available space. +Stub `file-system-info' to ensure the available space is consistent, +either with the given stub function or a default one using test data." + (cl-letf (((symbol-function 'file-system-info) + (or info-func + (files-tests--make-file-system-info-stub)))) + (should (string-match-p (cadr + (files-tests--look-up-free-data dir)) + (files-tests--insert-directory-output dir t))))) + + (ert-deftest files-tests-insert-directory-shows-free () + "Test that verbose `insert-directory' shows the correct available space." + (files-tests--insert-directory-shows-given-free + test-dir + (files-tests--make-file-system-info-stub test-dir))) + + (ert-deftest files-tests-bug-50630 () + "Verify verbose `insert-directory' shows free space of the target directory. +The current directory at call time should not affect the result (Bug#50630)." + (let ((default-directory test-dir-other)) + (files-tests--insert-directory-shows-given-free test-dir)))) + (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From 1914d946d62de4ab7bab1434bcea09087d61bb5a Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Wed, 1 Dec 2021 23:27:09 +0100 Subject: Change how Dired displays available space * doc/emacs/dired.texi (Misc Dired Features): Document it (bug#23812). * lisp/dired.el (dired-free-space): New user option. (dired-insert-directory): Use it from here. (dired--insert-disk-space): New function that uses the user option. * lisp/files.el (insert-directory): Don't transform "total" here. * lisp/ls-lisp.el (ls-lisp--insert-directory): Or here. Instead just leave the "total " bit alone, and let Dired transform it. * test/lisp/files-tests.el (files-tests): Move "available" tests to dired-tests. * test/lisp/dired-tests.el (data-dir): Moved here. --- doc/emacs/dired.texi | 8 +++ etc/NEWS | 7 ++ lisp/dired.el | 51 ++++++++++++++- lisp/files.el | 16 +---- lisp/ls-lisp.el | 13 +--- .../dired-resources/insert-directory/test_dir/bar | 0 .../dired-resources/insert-directory/test_dir/foo | 0 .../insert-directory/test_dir_other/bar | 0 .../insert-directory/test_dir_other/foo | 0 test/lisp/dired-tests.el | 74 ++++++++++++++++++++++ .../files-resources/insert-directory/test_dir/bar | 0 .../files-resources/insert-directory/test_dir/foo | 0 .../insert-directory/test_dir_other/bar | 0 .../insert-directory/test_dir_other/foo | 0 test/lisp/files-tests.el | 74 ---------------------- 15 files changed, 140 insertions(+), 103 deletions(-) create mode 100644 test/lisp/dired-resources/insert-directory/test_dir/bar create mode 100644 test/lisp/dired-resources/insert-directory/test_dir/foo create mode 100644 test/lisp/dired-resources/insert-directory/test_dir_other/bar create mode 100644 test/lisp/dired-resources/insert-directory/test_dir_other/foo delete mode 100644 test/lisp/files-resources/insert-directory/test_dir/bar delete mode 100644 test/lisp/files-resources/insert-directory/test_dir/foo delete mode 100644 test/lisp/files-resources/insert-directory/test_dir_other/bar delete mode 100644 test/lisp/files-resources/insert-directory/test_dir_other/foo (limited to 'test/lisp/files-resources') diff --git a/doc/emacs/dired.texi b/doc/emacs/dired.texi index 704850e584c..0edd8bc7da0 100644 --- a/doc/emacs/dired.texi +++ b/doc/emacs/dired.texi @@ -1567,6 +1567,14 @@ rotation is lossless, and uses an external utility called @node Misc Dired Features @section Other Dired Features +@vindex dired-free-space + By default, Dired will display the available space on the disk in +the first line. This is the @code{first} value of the +@code{dired-free-space} variable. If you set this to +@code{separate} instead, Dired will display this on a separate line +(including the space the files in the current directory takes). If +you set this to @code{nil}, the free space isn't displayed at all. + @kindex + @r{(Dired)} @findex dired-create-directory The command @kbd{+} (@code{dired-create-directory}) reads a diff --git a/etc/NEWS b/etc/NEWS index 7a94052625b..f1f1512a672 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -589,6 +589,13 @@ updating the thumbnail file. ** Dired +*** New user option 'dired-free-space'. +Dired will now, by default, include the free space in the first line +instead of having it on a separate line. To get the previous +behaviour back, say: + + (setq dired-free-space 'separate) + --- *** New user option 'dired-make-directory-clickable'. If non-nil (which is the default), hitting 'RET' or 'mouse-1' on diff --git a/lisp/dired.el b/lisp/dired.el index 9280c080a4c..c8add87a008 100644 --- a/lisp/dired.el +++ b/lisp/dired.el @@ -209,6 +209,17 @@ If a character, new links are unconditionally marked with that character." (character :tag "Mark")) :group 'dired-mark) +(defcustom dired-free-space 'first + "Whether to display free disk space in dired buffers. +If nil, don't display. +If `separate', display on a separate line (along with used count). +If `first', display the free disk space on the first line." + :type '(choice (const :tag "On a separate line" separate) + (const :tag "On the first line" first) + (const :tag "Don't display" nil)) + :version "29.1" + :group 'dired) + (defcustom dired-dwim-target nil "If non-nil, Dired tries to guess a default target directory. This means: if there is a Dired buffer displayed in some window, @@ -1614,15 +1625,51 @@ see `dired-use-ls-dired' for more details.") ;; by its expansion, so it does not matter whether what we insert ;; here is fully expanded, but it should be absolute. (insert " " (or (car-safe (insert-directory-wildcard-in-dir-p dir)) - (directory-file-name (file-name-directory dir))) ":\n") + (directory-file-name (file-name-directory dir))) + ":\n") (setq content-point (point))) (when wildcard ;; Insert "wildcard" line where "total" line would be for a full dir. (insert " wildcard " (or (cdr-safe (insert-directory-wildcard-in-dir-p dir)) (file-name-nondirectory dir)) - "\n"))) + "\n")) + (setq content-point (dired--insert-disk-space opoint dir))) (dired-insert-set-properties content-point (point))))) +(defun dired--insert-disk-space (beg file) + ;; Try to insert the amount of free space. + (save-excursion + (goto-char beg) + ;; First find the line to put it on. + (if (not (re-search-forward "^ *\\(total\\)" nil t)) + beg + (if (or (not dired-free-space) + (eq dired-free-space 'first)) + (delete-region (match-beginning 0) (line-beginning-position 2)) + ;; Replace "total" with "total used in directory" to + ;; avoid confusion. + (replace-match "total used in directory" nil nil nil 1)) + (when-let ((available (get-free-disk-space file))) + (cond + ((eq dired-free-space 'separate) + (end-of-line) + (insert " available " available) + (forward-line 1) + (point)) + ((eq dired-free-space 'first) + (goto-char beg) + (when (and (looking-at " */") + (progn + (end-of-line) + (eq (char-after (1- (point))) ?:))) + (put-text-property (1- (point)) (point) + 'display + (concat ": (" available " available)"))) + (forward-line 1) + (point)) + (t + beg)))))) + (defun dired-insert-set-properties (beg end) "Add various text properties to the lines in the region, from BEG to END." (save-excursion diff --git a/lisp/files.el b/lisp/files.el index c96e79cc63d..07279c4c871 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -7673,21 +7673,7 @@ normally equivalent short `-D' option is just passed on to (if val coding-no-eol coding)) (if val (put-text-property pos (point) - 'dired-filename t))))))) - - (if full-directory-p - ;; Try to insert the amount of free space. - (save-excursion - (goto-char beg) - ;; First find the line to put it on. - (when (re-search-forward "^ *\\(total\\)" nil t) - ;; Replace "total" with "total used in directory" to - ;; avoid confusion. - (replace-match "total used in directory" nil nil nil 1) - (let ((available (get-free-disk-space file))) - (when available - (end-of-line) - (insert " available " available)))))))))) + 'dired-filename t))))))))))) (defun insert-directory-adj-pos (pos error-lines) "Convert `ls --dired' file name position value POS to a buffer position. diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el index eea8089daa7..25d196392ab 100644 --- a/lisp/ls-lisp.el +++ b/lisp/ls-lisp.el @@ -337,18 +337,7 @@ are also supported; unsupported long options are silently ignored." (ls-lisp-insert-directory file switches (ls-lisp-time-index switches) nil full-directory-p)) - (signal (car err) (cdr err))))) - ;; Try to insert the amount of free space. - (save-excursion - (goto-char (point-min)) - ;; First find the line to put it on. - (when (re-search-forward "^total" nil t) - (let ((available (get-free-disk-space orig-file))) - (when available - ;; Replace "total" with "total used", to avoid confusion. - (replace-match "total used in directory") - (end-of-line) - (insert " available " available))))))))) + (signal (car err) (cdr err))))))))) (advice-add 'insert-directory :around #'ls-lisp--insert-directory) (defun ls-lisp-insert-directory diff --git a/test/lisp/dired-resources/insert-directory/test_dir/bar b/test/lisp/dired-resources/insert-directory/test_dir/bar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/dired-resources/insert-directory/test_dir/foo b/test/lisp/dired-resources/insert-directory/test_dir/foo new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/dired-resources/insert-directory/test_dir_other/bar b/test/lisp/dired-resources/insert-directory/test_dir_other/bar new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/dired-resources/insert-directory/test_dir_other/foo b/test/lisp/dired-resources/insert-directory/test_dir_other/foo new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el index ad1bca923d9..43791118f14 100644 --- a/test/lisp/dired-tests.el +++ b/test/lisp/dired-tests.el @@ -511,5 +511,79 @@ (when (file-directory-p testdir) (delete-directory testdir t))))) +;; `dired-insert-directory' output tests. +(let* ((data-dir "insert-directory") + (test-dir (file-name-as-directory + (ert-resource-file + (concat data-dir "/test_dir")))) + (test-dir-other (file-name-as-directory + (ert-resource-file + (concat data-dir "/test_dir_other")))) + (test-files `(,test-dir "foo" "bar")) ;expected files to be found + ;; Free space test data for `insert-directory'. + ;; Meaning: (path free-space-bytes-to-stub expected-free-space-string) + (free-data `((,test-dir 10 "available 10 B") + (,test-dir-other 100 "available 100 B") + (:default 999 "available 999 B")))) + + (defun files-tests--look-up-free-data (path) + "Look up free space test data, with a default for unspecified paths." + (let ((path (file-name-as-directory path))) + (cdr (or (assoc path free-data) + (assoc :default free-data))))) + + (defun files-tests--make-file-system-info-stub (&optional static-path) + "Return a stub for `file-system-info' using dynamic or static test data. +If that data should be static, pass STATIC-PATH to choose which +path's data to use." + (lambda (path) + (let* ((path (cond (static-path) + ;; file-system-info knows how to handle ".", so we + ;; do the same thing + ((equal "." path) default-directory) + (path))) + (return-size + (car (files-tests--look-up-free-data path)))) + (list return-size return-size return-size)))) + + (defun files-tests--insert-directory-output (dir &optional verbose) + "Run `insert-directory' and return its output." + (with-current-buffer-window "files-tests--insert-directory" nil nil + (let ((dired-free-space 'separate)) + (dired-insert-directory dir "-l" nil nil t)) + (buffer-substring-no-properties (point-min) (point-max)))) + + (ert-deftest files-tests-insert-directory-shows-files () + "Verify `insert-directory' reports the files in the directory." + (let* ((test-dir (car test-files)) + (files (cdr test-files)) + (output (files-tests--insert-directory-output test-dir))) + (dolist (file files) + (should (string-match-p file output))))) + + (defun files-tests--insert-directory-shows-given-free (dir &optional + info-func) + "Run `insert-directory' and verify it reports the correct available space. +Stub `file-system-info' to ensure the available space is consistent, +either with the given stub function or a default one using test data." + (cl-letf (((symbol-function 'file-system-info) + (or info-func + (files-tests--make-file-system-info-stub)))) + (should (string-match-p (cadr + (files-tests--look-up-free-data dir)) + (files-tests--insert-directory-output dir t))))) + + (ert-deftest files-tests-insert-directory-shows-free () + "Test that verbose `insert-directory' shows the correct available space." + (files-tests--insert-directory-shows-given-free + test-dir + (files-tests--make-file-system-info-stub test-dir))) + + (ert-deftest files-tests-bug-50630 () + "Verify verbose `insert-directory' shows free space of the target directory. +The current directory at call time should not affect the result (Bug#50630)." + (let ((default-directory test-dir-other)) + (files-tests--insert-directory-shows-given-free test-dir)))) + (provide 'dired-tests) ;;; dired-tests.el ends here diff --git a/test/lisp/files-resources/insert-directory/test_dir/bar b/test/lisp/files-resources/insert-directory/test_dir/bar deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/lisp/files-resources/insert-directory/test_dir/foo b/test/lisp/files-resources/insert-directory/test_dir/foo deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/bar b/test/lisp/files-resources/insert-directory/test_dir_other/bar deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/lisp/files-resources/insert-directory/test_dir_other/foo b/test/lisp/files-resources/insert-directory/test_dir_other/foo deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index d3d58aad5f2..462048802f0 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1822,79 +1822,5 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil." (should (equal (file-name-split "/foo/bar/") '("" "foo" "bar" ""))) (should (equal (file-name-split "foo/bar/") '("foo" "bar" "")))) -;; `insert-directory' output tests. -(let* ((data-dir "insert-directory") - (test-dir (file-name-as-directory - (ert-resource-file - (concat data-dir "/test_dir")))) - (test-dir-other (file-name-as-directory - (ert-resource-file - (concat data-dir "/test_dir_other")))) - (test-files `(,test-dir "foo" "bar")) ;expected files to be found - ;; Free space test data for `insert-directory'. - ;; Meaning: (path free-space-bytes-to-stub expected-free-space-string) - (free-data `((,test-dir 10 "available 10 B") - (,test-dir-other 100 "available 100 B") - (:default 999 "available 999 B")))) - - - (defun files-tests--look-up-free-data (path) - "Look up free space test data, with a default for unspecified paths." - (let ((path (file-name-as-directory path))) - (cdr (or (assoc path free-data) - (assoc :default free-data))))) - - (defun files-tests--make-file-system-info-stub (&optional static-path) - "Return a stub for `file-system-info' using dynamic or static test data. -If that data should be static, pass STATIC-PATH to choose which -path's data to use." - (lambda (path) - (let* ((path (cond (static-path) - ;; file-system-info knows how to handle ".", so we - ;; do the same thing - ((equal "." path) default-directory) - (path))) - (return-size - (car (files-tests--look-up-free-data path)))) - (list return-size return-size return-size)))) - - (defun files-tests--insert-directory-output (dir &optional verbose) - "Run `insert-directory' and return its output." - (with-current-buffer-window "files-tests--insert-directory" nil nil - (insert-directory dir "-l" nil t) - (buffer-substring-no-properties (point-min) (point-max)))) - - (ert-deftest files-tests-insert-directory-shows-files () - "Verify `insert-directory' reports the files in the directory." - (let* ((test-dir (car test-files)) - (files (cdr test-files)) - (output (files-tests--insert-directory-output test-dir))) - (dolist (file files) - (should (string-match-p file output))))) - - (defun files-tests--insert-directory-shows-given-free (dir &optional - info-func) - "Run `insert-directory' and verify it reports the correct available space. -Stub `file-system-info' to ensure the available space is consistent, -either with the given stub function or a default one using test data." - (cl-letf (((symbol-function 'file-system-info) - (or info-func - (files-tests--make-file-system-info-stub)))) - (should (string-match-p (cadr - (files-tests--look-up-free-data dir)) - (files-tests--insert-directory-output dir t))))) - - (ert-deftest files-tests-insert-directory-shows-free () - "Test that verbose `insert-directory' shows the correct available space." - (files-tests--insert-directory-shows-given-free - test-dir - (files-tests--make-file-system-info-stub test-dir))) - - (ert-deftest files-tests-bug-50630 () - "Verify verbose `insert-directory' shows free space of the target directory. -The current directory at call time should not affect the result (Bug#50630)." - (let ((default-directory test-dir-other)) - (files-tests--insert-directory-shows-given-free test-dir)))) - (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From 713a1997059fb823f9fa26f92cee032fb6bfdc25 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Mon, 18 Apr 2022 10:36:32 +0200 Subject: Fix major-mode setting regression when there's a mode: cookie * lisp/files.el (hack-local-variables): Fix regression in setting the major mode when there are mode: cookies in the file (bug#54993). --- lisp/files.el | 2 +- test/lisp/files-resources/file-mode | 3 +++ test/lisp/files-tests.el | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 test/lisp/files-resources/file-mode (limited to 'test/lisp/files-resources') diff --git a/lisp/files.el b/lisp/files.el index 80180276a99..135a6177e9c 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3899,7 +3899,7 @@ inhibited." (with-demoted-errors "Directory-local variables error: %s" ;; Note this is a no-op if enable-local-variables is nil. (hack-dir-local-variables)) - (let ((result (append (hack-local-variables--find-variables) + (let ((result (append (hack-local-variables--find-variables handle-mode) (hack-local-variables-prop-line)))) (if (and enable-local-variables (not (inhibit-local-variables-p))) diff --git a/test/lisp/files-resources/file-mode b/test/lisp/files-resources/file-mode new file mode 100644 index 00000000000..92ac4c30ef5 --- /dev/null +++ b/test/lisp/files-resources/file-mode @@ -0,0 +1,3 @@ +Local variables: +mode: text +end: diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index e4424f3cbed..f76d047f302 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1814,5 +1814,12 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil." (should (equal (file-name-split "/foo/bar/") '("" "foo" "bar" ""))) (should (equal (file-name-split "foo/bar/") '("foo" "bar" "")))) +(ert-deftest files-test-set-mode () + (find-file (ert-resource-file "file-mode")) + (should (eq major-mode 'text-mode)) + (emacs-lisp-mode) + ;; Check that the mode cookie doesn't override the explicit setting. + (should (eq major-mode 'emacs-lisp-mode))) + (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From 35592141cc8951c91a4bd6cc02f73d1ddd35aca4 Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 19 Apr 2022 16:22:37 +0200 Subject: Allow several mode: elements in the local variable section * etc/NEWS (mode): Fall back on outline-mode in older Emacsen. * lisp/files.el (hack-local-variables--find-variables): Use the final mode: line (which is the same as having several mode: bits in the header line. --- etc/NEWS | 1 + lisp/files.el | 11 +++++++---- test/lisp/files-resources/file-mode-multiple | 5 +++++ test/lisp/files-tests.el | 4 ++++ 4 files changed, 17 insertions(+), 4 deletions(-) create mode 100644 test/lisp/files-resources/file-mode-multiple (limited to 'test/lisp/files-resources') diff --git a/etc/NEWS b/etc/NEWS index 3e7788277d3..496ff32d202 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -2071,6 +2071,7 @@ along with GNU Emacs. If not, see . Local variables: coding: utf-8 +mode: outline mode: emacs-news paragraph-separate: "[ ]*$" end: diff --git a/lisp/files.el b/lisp/files.el index 135a6177e9c..a9d4b5aea81 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3978,8 +3978,7 @@ major-mode." (forward-line 1)) (goto-char (point-min)) - (while (not (or (eobp) - (and (eq handle-mode t) result))) + (while (not (eobp)) ;; Find the variable name; (unless (looking-at hack-local-variable-regexp) (user-error "Malformed local variable line: %S" @@ -4005,7 +4004,8 @@ major-mode." (not (string-match "-minor\\'" (setq val2 (downcase (symbol-name val))))) - (setq result (intern (concat val2 "-mode")))) + ;; Allow several mode: elements. + (push (intern (concat val2 "-mode")) result)) (cond ((eq var 'coding)) ((eq var 'lexical-binding) (unless hack-local-variables--warned-lexical @@ -4029,7 +4029,10 @@ major-mode." val) result)))))) (forward-line 1))))))) - result)) + (if (eq handle-mode t) + ;; Return the final mode: setting that's defined. + (car (seq-filter #'fboundp result)) + result))) (defun hack-local-variables-apply () "Apply the elements of `file-local-variables-alist'. diff --git a/test/lisp/files-resources/file-mode-multiple b/test/lisp/files-resources/file-mode-multiple new file mode 100644 index 00000000000..ac051ccbcbd --- /dev/null +++ b/test/lisp/files-resources/file-mode-multiple @@ -0,0 +1,5 @@ +Local variables: +mode: text +mode: test-mode-undef +mode: outline +end: diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index f76d047f302..c886bd79851 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1821,5 +1821,9 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil." ;; Check that the mode cookie doesn't override the explicit setting. (should (eq major-mode 'emacs-lisp-mode))) +(ert-deftest files-test-set-mode-multiple () + (find-file (ert-resource-file "file-mode-multiple")) + (should (eq major-mode 'outline-mode))) + (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From e45abc832db7d1a64a0761dcb51565b7c282999a Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Tue, 19 Apr 2022 18:06:31 +0200 Subject: Fix regression with multiple mode: entries in the prop line * lisp/files.el (hack-local-variables--find-variables): Use the final mode: line (which is the same as having several mode: bits in the header line. --- lisp/files.el | 2 +- test/lisp/files-resources/file-mode-prop-line | 1 + test/lisp/files-tests.el | 4 ++++ 3 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 test/lisp/files-resources/file-mode-prop-line (limited to 'test/lisp/files-resources') diff --git a/lisp/files.el b/lisp/files.el index a9d4b5aea81..2b0dc54db8f 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3900,7 +3900,7 @@ inhibited." ;; Note this is a no-op if enable-local-variables is nil. (hack-dir-local-variables)) (let ((result (append (hack-local-variables--find-variables handle-mode) - (hack-local-variables-prop-line)))) + (hack-local-variables-prop-line handle-mode)))) (if (and enable-local-variables (not (inhibit-local-variables-p))) (progn diff --git a/test/lisp/files-resources/file-mode-prop-line b/test/lisp/files-resources/file-mode-prop-line new file mode 100644 index 00000000000..e0e7ad24d71 --- /dev/null +++ b/test/lisp/files-resources/file-mode-prop-line @@ -0,0 +1 @@ +-*- mode: notexist; mode: text -*- diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index c886bd79851..c5b0fe0bbbc 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1825,5 +1825,9 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil." (find-file (ert-resource-file "file-mode-multiple")) (should (eq major-mode 'outline-mode))) +(ert-deftest files-test-set-mode-prop-line () + (find-file (ert-resource-file "file-mode-prop-line")) + (should (eq major-mode 'text-mode))) + (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From e00edf20e7d13277781712c5bbcec7b34f3a829e Mon Sep 17 00:00:00 2001 From: Lars Ingebrigtsen Date: Sat, 23 Apr 2022 18:14:26 +0200 Subject: Add a failing test case for bug#12598 Author: --- test/lisp/files-resources/compile-utf8.el | 11 +++++++++++ test/lisp/files-tests.el | 29 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 test/lisp/files-resources/compile-utf8.el (limited to 'test/lisp/files-resources') diff --git a/test/lisp/files-resources/compile-utf8.el b/test/lisp/files-resources/compile-utf8.el new file mode 100644 index 00000000000..ea67626365d --- /dev/null +++ b/test/lisp/files-resources/compile-utf8.el @@ -0,0 +1,11 @@ +(defun zot () + "Yes." + nil) + +(defun foo () + "Yés." + nil) + +(defun bar () + "Nó." + nil) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index 34c002be271..1633f3b34cf 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -1829,5 +1829,34 @@ Prompt users for any modified buffer with `buffer-offer-save' non-nil." (find-file (ert-resource-file "file-mode-prop-line")) (should (eq major-mode 'text-mode))) +(ert-deftest files-load-elc-gz-file () + :expected-result :failed + (skip-unless (executable-find "gzip")) + (ert-with-temp-directory dir + (let* ((pref (expand-file-name "compile-utf8" dir)) + (el (concat pref ".el"))) + (copy-file (ert-resource-file "compile-utf8.el") el) + (push dir load-path) + (should (load pref t)) + (should (fboundp 'foo)) + (should (documentation 'foo)) + (should (documentation 'bar)) + (should (documentation 'zot)) + + (byte-compile-file el) + (should (load (concat pref ".elc") t)) + (should (fboundp 'foo)) + (should (documentation 'foo)) + (should (documentation 'bar)) + (should (documentation 'zot)) + + (dired-compress-file (concat pref ".elc")) + (should (load (concat pref ".elc.gz") t)) + (should (fboundp 'foo)) + ;; This fails due to bug#12598. + (should (documentation 'foo)) + (should (documentation 'bar)) + (should (documentation 'zot))))) + (provide 'files-tests) ;;; files-tests.el ends here -- cgit v1.2.3 From 77b5840d4ab37c1485745def5ec0c9b9f6cb137f Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Thu, 26 May 2022 12:16:04 -0400 Subject: * test/lisp/files-resources/compile-utf8.el: Use lexical-binding --- test/lisp/files-resources/compile-utf8.el | 1 + 1 file changed, 1 insertion(+) (limited to 'test/lisp/files-resources') diff --git a/test/lisp/files-resources/compile-utf8.el b/test/lisp/files-resources/compile-utf8.el index ea67626365d..1f804dcf8dc 100644 --- a/test/lisp/files-resources/compile-utf8.el +++ b/test/lisp/files-resources/compile-utf8.el @@ -1,3 +1,4 @@ +;; -*- lexical-binding: t; -*- (defun zot () "Yes." nil) -- cgit v1.2.3