X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/41306318777a942420bc4feadbfacf662ea179dc..5feeead12693cd97c6d77b14ef05d29ba5cf18bb:/lisp/files-x.el diff --git a/lisp/files-x.el b/lisp/files-x.el index adc2b8b3bf..05ad7f57c5 100644 --- a/lisp/files-x.el +++ b/lisp/files-x.el @@ -1,9 +1,9 @@ ;;; files-x.el --- extended file handling commands -;; Copyright (C) 2009-2013 Free Software Foundation, Inc. +;; Copyright (C) 2009-2016 Free Software Foundation, Inc. ;; Author: Juri Linkov -;; Maintainer: FSF +;; Maintainer: emacs-devel@gnu.org ;; Keywords: files ;; Package: emacs @@ -247,7 +247,14 @@ then this function adds the first line containing the string `Local Variables:' and the last line containing the string `End:'." (interactive (let ((variable (read-file-local-variable "Add file-local variable"))) + ;; Error before reading value. + (if (equal variable 'lexical-binding) + (user-error "The `%s' variable must be set at the start of the file" + variable)) (list variable (read-file-local-variable-value variable) t))) + (if (equal variable 'lexical-binding) + (user-error "The `%s' variable must be set at the start of the file" + variable)) (modify-file-local-variable variable value 'add-or-replace interactive)) ;;;###autoload @@ -422,18 +429,24 @@ from the MODE alist ignoring the input argument VALUE." (catch 'exit (unless enable-local-variables (throw 'exit (message "Directory-local variables are disabled"))) - (let ((variables-file (or (and (buffer-file-name) - (not (file-remote-p (buffer-file-name))) - (dir-locals-find-file (buffer-file-name))) - dir-locals-file)) - variables) - (if (consp variables-file) ; result from cache - ;; If cache element has an mtime, assume it came from a file. - ;; Otherwise, assume it was set directly. - (setq variables-file (if (nth 2 variables-file) - (expand-file-name dir-locals-file - (car variables-file)) - (cadr variables-file)))) + (let* ((dir-or-cache (and (buffer-file-name) + (not (file-remote-p (buffer-file-name))) + (dir-locals-find-file (buffer-file-name)))) + (variables-file + ;; If there are several .dir-locals, the user probably + ;; wants to edit the last one (the highest priority). + (cond ((stringp dir-or-cache) + (car (last (dir-locals--all-files dir-or-cache)))) + ((consp dir-or-cache) ; result from cache + ;; If cache element has an mtime, assume it came + ;; from a file. Otherwise, assume it was set + ;; directly. + (if (nth 2 dir-or-cache) + (car (last (dir-locals--all-files (car dir-or-cache)))) + (cadr dir-or-cache))) + ;; Try to make a proper file-name. + (t (expand-file-name dir-locals-file)))) + variables) ;; I can't be bothered to handle this case right now. ;; Dir locals were set directly from a class. You need to ;; directly modify the class in dir-locals-class-alist.