GNU bug report logs - #19140
dir-locals-collect-variables discrepancy in handling non-file buffers

Previous Next

Package: emacs;

Reported by: Ivan Shmakov <ivan <at> siamics.net>

Date: Fri, 21 Nov 2014 16:14:02 UTC

Severity: minor

Tags: patch

Fixed in version 25.1

Done: Ivan Shmakov <ivan <at> siamics.net>

Bug is archived. No further changes may be made.

Full log


Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ivan Shmakov <ivan <at> siamics.net>
To: submit <at> debbugs.gnu.org
Subject: dir-locals-collect-variables discrepancy in handling non-file buffers
Date: Fri, 21 Nov 2014 16:12:52 +0000
[Message part 1 (text/plain, inline)]
Package:  emacs
Severity: minor

	Please consider the patch MIMEd.

	* lisp/files.el (dir-locals-collect-variables): Use
	default-directory in place of the file name while working on
	non-file buffers (as hack-dir-local-variables already does.)

	The issue I observe is as follows.  First, I create ~/foo and
	~/foo/ru directories, and a ~/foo/.dir-locals.el file like:

((nil
  (ispell-local-dictionary  . "esperanto"))
 ("ru"
  (nil
   (ispell-local-dictionary . "russian"))))

	Then:

(with-temp-buffer
  (cd "~/foo/ru/")
  (hack-dir-local-variables-non-file-buffer)
  ;; .
  dir-local-variables-alist)

	The result is '((ispell-local-dictionary . "esperanto")),
	contrary to the expected '((… . "russian")).

	This does not happen for buffers associated with files:

(with-current-buffer (find-file-noselect "~/foo/ru/bar")
  (hack-dir-local-variables)
  ;; .
  dir-local-variables-alist)

	Reading the code suggests that dir-locals-collect-variables
	fails to handle the (stringp key) case properly when ‘file-name’
	is nil, which is what my patch is intended to fix.

-- 
FSF associate member #7257  np. Conclusion — Apocalyptica    … B6A0 230E 334A
[Message part 2 (text/diff, inline)]
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3567,8 +3569,10 @@
 (defun dir-locals-collect-variables (class-variables root variables)
   "Collect entries from CLASS-VARIABLES into VARIABLES.
 ROOT is the root directory of the project.
 Return the new variables list."
-  (let* ((file-name (buffer-file-name))
+  (let* ((file-name (or (buffer-file-name)
+			;; handle non-file buffers, too
+			default-directory))
 	 (sub-file-name (if file-name
                             ;; FIXME: Why not use file-relative-name?
 			    (substring file-name (length root)))))

This bug report was last modified 10 years and 100 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.