diff options
| author | Juri Linkov | 2008-11-22 19:02:47 +0000 |
|---|---|---|
| committer | Juri Linkov | 2008-11-22 19:02:47 +0000 |
| commit | 75fd7f12d5ffeb218c53144b47f5fb7bcf81a62b (patch) | |
| tree | cb352e9c3915e33c15369b43e0122c0bd1273da5 | |
| parent | a208633805e2181f6c63b8f60103f4e369eb8e8d (diff) | |
| download | emacs-75fd7f12d5ffeb218c53144b47f5fb7bcf81a62b.tar.gz emacs-75fd7f12d5ffeb218c53144b47f5fb7bcf81a62b.zip | |
(hack-local-variables-confirm): Rename arg `project' to
`dir-name'. Move `(or dir-name name)' to let-binding of `name'.
(hack-local-variables-filter): Rename arg `project' to `dir-name'.
(hack-local-variables): Rename call of `hack-project-variables' to
`hack-dir-local-variables'. Change error text to "Directory-local
variables error".
(dir-locals-class-alist): Rename from `project-class-alist'.
(dir-locals-directory-alist): Rename from `project-directory-alist'.
(dir-locals-get-class-variables): Rename from `project-get-alist'.
(dir-locals-collect-mode-variables): Rename from
`project-collect-bindings-from-alist'. Rename arg `mode-alist' to
`mode-variables', and arg `settings' to `variables'.
(dir-locals-collect-variables): Rename from
`project-collect-binding-list'. Rename arg `binding-list' to
`class-variables', and arg `settings' to `variables'.
(dir-locals-set-directory-class): Rename from `set-directory-project'.
(dir-locals-set-class-variables): Rename from `define-project-bindings'.
Rename arg `settings' to `variables'.
(dir-locals-file): New defconst.
(dir-locals-find-file): Rename from `project-find-settings-file'.
Use `dir-locals-file'. Rename let-bound `settings' to `locals-file',
and `pda' to `dir-elt'.
(dir-locals-read-from-file): Rename from
`project-define-from-project-file'. Rename arg `settings-file'
to `file'. Rename let-bound `list' to `variables'.
(hack-dir-local-variables): Rename from `hack-project-variables'.
Rename let-bound `settings' to `variables-file', `root-dir'
to `dir-name', and `bindings' to `variables'.
| -rw-r--r-- | lisp/ChangeLog | 31 | ||||
| -rw-r--r-- | lisp/files.el | 216 |
2 files changed, 142 insertions, 105 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 9eb1ac93df2..1f113e5d5e8 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,34 @@ | |||
| 1 | 2008-11-22 Juri Linkov <juri@jurta.org> | ||
| 2 | |||
| 3 | * files.el (hack-local-variables-confirm): Rename arg `project' to | ||
| 4 | `dir-name'. Move `(or dir-name name)' to let-binding of `name'. | ||
| 5 | (hack-local-variables-filter): Rename arg `project' to `dir-name'. | ||
| 6 | (hack-local-variables): Rename call of `hack-project-variables' to | ||
| 7 | `hack-dir-local-variables'. Change error text to "Directory-local | ||
| 8 | variables error". | ||
| 9 | (dir-locals-class-alist): Rename from `project-class-alist'. | ||
| 10 | (dir-locals-directory-alist): Rename from `project-directory-alist'. | ||
| 11 | (dir-locals-get-class-variables): Rename from `project-get-alist'. | ||
| 12 | (dir-locals-collect-mode-variables): Rename from | ||
| 13 | `project-collect-bindings-from-alist'. Rename arg `mode-alist' to | ||
| 14 | `mode-variables', and arg `settings' to `variables'. | ||
| 15 | (dir-locals-collect-variables): Rename from | ||
| 16 | `project-collect-binding-list'. Rename arg `binding-list' to | ||
| 17 | `class-variables', and arg `settings' to `variables'. | ||
| 18 | (dir-locals-set-directory-class): Rename from `set-directory-project'. | ||
| 19 | (dir-locals-set-class-variables): Rename from `define-project-bindings'. | ||
| 20 | Rename arg `settings' to `variables'. | ||
| 21 | (dir-locals-file): New defconst. | ||
| 22 | (dir-locals-find-file): Rename from `project-find-settings-file'. | ||
| 23 | Use `dir-locals-file'. Rename let-bound `settings' to `locals-file', | ||
| 24 | and `pda' to `dir-elt'. | ||
| 25 | (dir-locals-read-from-file): Rename from | ||
| 26 | `project-define-from-project-file'. Rename arg `settings-file' | ||
| 27 | to `file'. Rename let-bound `list' to `variables'. | ||
| 28 | (hack-dir-local-variables): Rename from `hack-project-variables'. | ||
| 29 | Rename let-bound `settings' to `variables-file', `root-dir' | ||
| 30 | to `dir-name', and `bindings' to `variables'. | ||
| 31 | |||
| 1 | 2008-11-22 Lute Kamstra <lute@gnu.org> | 32 | 2008-11-22 Lute Kamstra <lute@gnu.org> |
| 2 | 33 | ||
| 3 | * simple.el (goto-line): Rename argument. | 34 | * simple.el (goto-line): Rename argument. |
diff --git a/lisp/files.el b/lisp/files.el index f501e14b5f2..9b317252c36 100644 --- a/lisp/files.el +++ b/lisp/files.el | |||
| @@ -2708,18 +2708,19 @@ function is allowed to change the contents of this alist. | |||
| 2708 | This hook is called only if there is at least one file-local | 2708 | This hook is called only if there is at least one file-local |
| 2709 | variable to set.") | 2709 | variable to set.") |
| 2710 | 2710 | ||
| 2711 | (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars project) | 2711 | (defun hack-local-variables-confirm (all-vars unsafe-vars risky-vars dir-name) |
| 2712 | "Get confirmation before setting up local variable values. | 2712 | "Get confirmation before setting up local variable values. |
| 2713 | ALL-VARS is the list of all variables to be set up. | 2713 | ALL-VARS is the list of all variables to be set up. |
| 2714 | UNSAFE-VARS is the list of those that aren't marked as safe or risky. | 2714 | UNSAFE-VARS is the list of those that aren't marked as safe or risky. |
| 2715 | RISKY-VARS is the list of those that are marked as risky. | 2715 | RISKY-VARS is the list of those that are marked as risky. |
| 2716 | PROJECT is a directory name if these settings come from directory-local | 2716 | DIR-NAME is a directory name if these settings come from |
| 2717 | settings, or nil otherwise." | 2717 | directory-local variables, or nil otherwise." |
| 2718 | (if noninteractive | 2718 | (if noninteractive |
| 2719 | nil | 2719 | nil |
| 2720 | (let ((name (if buffer-file-name | 2720 | (let ((name (or dir-name |
| 2721 | (file-name-nondirectory buffer-file-name) | 2721 | (if buffer-file-name |
| 2722 | (concat "buffer " (buffer-name)))) | 2722 | (file-name-nondirectory buffer-file-name) |
| 2723 | (concat "buffer " (buffer-name))))) | ||
| 2723 | (offer-save (and (eq enable-local-variables t) unsafe-vars)) | 2724 | (offer-save (and (eq enable-local-variables t) unsafe-vars)) |
| 2724 | prompt char) | 2725 | prompt char) |
| 2725 | (save-window-excursion | 2726 | (save-window-excursion |
| @@ -2728,16 +2729,15 @@ settings, or nil otherwise." | |||
| 2728 | (set (make-local-variable 'cursor-type) nil) | 2729 | (set (make-local-variable 'cursor-type) nil) |
| 2729 | (erase-buffer) | 2730 | (erase-buffer) |
| 2730 | (if unsafe-vars | 2731 | (if unsafe-vars |
| 2731 | (insert "The local variables list in " (or project name) | 2732 | (insert "The local variables list in " name |
| 2732 | "\ncontains values that may not be safe (*)" | 2733 | "\ncontains values that may not be safe (*)" |
| 2733 | (if risky-vars | 2734 | (if risky-vars |
| 2734 | ", and variables that are risky (**)." | 2735 | ", and variables that are risky (**)." |
| 2735 | ".")) | 2736 | ".")) |
| 2736 | (if risky-vars | 2737 | (if risky-vars |
| 2737 | (insert "The local variables list in " (or project name) | 2738 | (insert "The local variables list in " name |
| 2738 | "\ncontains variables that are risky (**).") | 2739 | "\ncontains variables that are risky (**).") |
| 2739 | (insert "A local variables list is specified in " | 2740 | (insert "A local variables list is specified in " name "."))) |
| 2740 | (or project name) "."))) | ||
| 2741 | (insert "\n\nDo you want to apply it? You can type | 2741 | (insert "\n\nDo you want to apply it? You can type |
| 2742 | y -- to apply the local variables list. | 2742 | y -- to apply the local variables list. |
| 2743 | n -- to ignore the local variables list.") | 2743 | n -- to ignore the local variables list.") |
| @@ -2859,15 +2859,15 @@ and VAL is the specified value." | |||
| 2859 | mode-specified | 2859 | mode-specified |
| 2860 | result)))) | 2860 | result)))) |
| 2861 | 2861 | ||
| 2862 | (defun hack-local-variables-filter (variables project) | 2862 | (defun hack-local-variables-filter (variables dir-name) |
| 2863 | "Filter local variable settings, querying the user if necessary. | 2863 | "Filter local variable settings, querying the user if necessary. |
| 2864 | VARIABLES is the alist of variable-value settings. This alist is | 2864 | VARIABLES is the alist of variable-value settings. This alist is |
| 2865 | filtered based on the values of `ignored-local-variables', | 2865 | filtered based on the values of `ignored-local-variables', |
| 2866 | `enable-local-eval', `enable-local-variables', and (if necessary) | 2866 | `enable-local-eval', `enable-local-variables', and (if necessary) |
| 2867 | user interaction. The results are added to | 2867 | user interaction. The results are added to |
| 2868 | `file-local-variables-alist', without applying them. | 2868 | `file-local-variables-alist', without applying them. |
| 2869 | PROJECT is a directory name if these settings come from | 2869 | DIR-NAME is a directory name if these settings come from |
| 2870 | directory-local settings, or nil otherwise." | 2870 | directory-local variables, or nil otherwise." |
| 2871 | ;; Strip any variables that are in `ignored-local-variables'. | 2871 | ;; Strip any variables that are in `ignored-local-variables'. |
| 2872 | (dolist (ignored ignored-local-variables) | 2872 | (dolist (ignored ignored-local-variables) |
| 2873 | (setq variables (assq-delete-all ignored variables))) | 2873 | (setq variables (assq-delete-all ignored variables))) |
| @@ -2905,7 +2905,7 @@ PROJECT is a directory name if these settings come from | |||
| 2905 | (null risky-vars)) | 2905 | (null risky-vars)) |
| 2906 | (eq enable-local-variables :all) | 2906 | (eq enable-local-variables :all) |
| 2907 | (hack-local-variables-confirm | 2907 | (hack-local-variables-confirm |
| 2908 | variables unsafe-vars risky-vars project)) | 2908 | variables unsafe-vars risky-vars dir-name)) |
| 2909 | (dolist (elt variables) | 2909 | (dolist (elt variables) |
| 2910 | (push elt file-local-variables-alist))))))) | 2910 | (push elt file-local-variables-alist))))))) |
| 2911 | 2911 | ||
| @@ -2918,8 +2918,8 @@ is specified, returning t if it is specified." | |||
| 2918 | result) | 2918 | result) |
| 2919 | (unless mode-only | 2919 | (unless mode-only |
| 2920 | (setq file-local-variables-alist nil) | 2920 | (setq file-local-variables-alist nil) |
| 2921 | (report-errors "Project local-variables error: %s" | 2921 | (report-errors "Directory-local variables error: %s" |
| 2922 | (hack-project-variables))) | 2922 | (hack-dir-local-variables))) |
| 2923 | (when (or mode-only enable-local-variables) | 2923 | (when (or mode-only enable-local-variables) |
| 2924 | (setq result (hack-local-variables-prop-line mode-only)) | 2924 | (setq result (hack-local-variables-prop-line mode-only)) |
| 2925 | ;; Look for "Local variables:" line in last page. | 2925 | ;; Look for "Local variables:" line in last page. |
| @@ -3121,39 +3121,39 @@ already the major mode." | |||
| 3121 | (set-text-properties 0 (length val) nil val)) | 3121 | (set-text-properties 0 (length val) nil val)) |
| 3122 | (set (make-local-variable var) val)))) | 3122 | (set (make-local-variable var) val)))) |
| 3123 | 3123 | ||
| 3124 | ;;; Handling directory local variables, aka project settings. | 3124 | ;;; Handling directory-local variables, aka project settings. |
| 3125 | 3125 | ||
| 3126 | (defvar project-class-alist '() | 3126 | (defvar dir-locals-class-alist '() |
| 3127 | "Alist mapping project class names (symbols) to project variable lists.") | 3127 | "Alist mapping class names (symbols) to variable lists.") |
| 3128 | 3128 | ||
| 3129 | (defvar project-directory-alist '() | 3129 | (defvar dir-locals-directory-alist '() |
| 3130 | "Alist mapping project directory roots to project classes.") | 3130 | "Alist mapping directory roots to variable classes.") |
| 3131 | 3131 | ||
| 3132 | (defsubst project-get-alist (class) | 3132 | (defsubst dir-locals-get-class-variables (class) |
| 3133 | "Return the project variable list for project CLASS." | 3133 | "Return the variable list for CLASS." |
| 3134 | (cdr (assq class project-class-alist))) | 3134 | (cdr (assq class dir-locals-class-alist))) |
| 3135 | 3135 | ||
| 3136 | (defun project-collect-bindings-from-alist (mode-alist settings) | 3136 | (defun dir-locals-collect-mode-variables (mode-variables variables) |
| 3137 | "Collect local variable settings from MODE-ALIST. | 3137 | "Collect directory-local variables from MODE-VARIABLES. |
| 3138 | SETTINGS is the initial list of bindings. | 3138 | VARIABLES is the initial list of variables. |
| 3139 | Returns the new list." | 3139 | Returns the new list." |
| 3140 | (dolist (pair mode-alist settings) | 3140 | (dolist (pair mode-variables variables) |
| 3141 | (let* ((variable (car pair)) | 3141 | (let* ((variable (car pair)) |
| 3142 | (value (cdr pair)) | 3142 | (value (cdr pair)) |
| 3143 | (slot (assq variable settings))) | 3143 | (slot (assq variable variables))) |
| 3144 | (if slot | 3144 | (if slot |
| 3145 | (setcdr slot value) | 3145 | (setcdr slot value) |
| 3146 | ;; Need a new cons in case we setcdr later. | 3146 | ;; Need a new cons in case we setcdr later. |
| 3147 | (push (cons variable value) settings))))) | 3147 | (push (cons variable value) variables))))) |
| 3148 | 3148 | ||
| 3149 | (defun project-collect-binding-list (binding-list root settings) | 3149 | (defun dir-locals-collect-variables (class-variables root variables) |
| 3150 | "Collect entries from BINDING-LIST into SETTINGS. | 3150 | "Collect entries from CLASS-VARIABLES into VARIABLES. |
| 3151 | ROOT is the root directory of the project. | 3151 | ROOT is the root directory of the project. |
| 3152 | Return the new settings list." | 3152 | Return the new variables list." |
| 3153 | (let* ((file-name (buffer-file-name)) | 3153 | (let* ((file-name (buffer-file-name)) |
| 3154 | (sub-file-name (if file-name | 3154 | (sub-file-name (if file-name |
| 3155 | (substring file-name (length root))))) | 3155 | (substring file-name (length root))))) |
| 3156 | (dolist (entry binding-list settings) | 3156 | (dolist (entry class-variables variables) |
| 3157 | (let ((key (car entry))) | 3157 | (let ((key (car entry))) |
| 3158 | (cond | 3158 | (cond |
| 3159 | ((stringp key) | 3159 | ((stringp key) |
| @@ -3162,31 +3162,31 @@ Return the new settings list." | |||
| 3162 | (when (and sub-file-name | 3162 | (when (and sub-file-name |
| 3163 | (>= (length sub-file-name) (length key)) | 3163 | (>= (length sub-file-name) (length key)) |
| 3164 | (string= key (substring sub-file-name 0 (length key)))) | 3164 | (string= key (substring sub-file-name 0 (length key)))) |
| 3165 | (setq settings (project-collect-binding-list (cdr entry) | 3165 | (setq variables (dir-locals-collect-variables |
| 3166 | root settings)))) | 3166 | (cdr entry) root variables)))) |
| 3167 | ((or (not key) | 3167 | ((or (not key) |
| 3168 | (derived-mode-p key)) | 3168 | (derived-mode-p key)) |
| 3169 | (setq settings (project-collect-bindings-from-alist (cdr entry) | 3169 | (setq variables (dir-locals-collect-mode-variables |
| 3170 | settings)))))))) | 3170 | (cdr entry) variables)))))))) |
| 3171 | 3171 | ||
| 3172 | (defun set-directory-project (directory class) | 3172 | (defun dir-locals-set-directory-class (directory class) |
| 3173 | "Declare that the project rooted at DIRECTORY is an instance of CLASS. | 3173 | "Declare that the DIRECTORY root is an instance of CLASS. |
| 3174 | DIRECTORY is the name of a directory, a string. | 3174 | DIRECTORY is the name of a directory, a string. |
| 3175 | CLASS is the name of a project class, a symbol. | 3175 | CLASS is the name of a project class, a symbol. |
| 3176 | 3176 | ||
| 3177 | When a file beneath DIRECTORY is visited, the mode-specific | 3177 | When a file beneath DIRECTORY is visited, the mode-specific |
| 3178 | settings from CLASS will be applied to the buffer. The settings | 3178 | variables from CLASS will be applied to the buffer. The variables |
| 3179 | for a class are defined using `define-project-bindings'." | 3179 | for a class are defined using `dir-locals-set-class-variables'." |
| 3180 | (setq directory (file-name-as-directory (expand-file-name directory))) | 3180 | (setq directory (file-name-as-directory (expand-file-name directory))) |
| 3181 | (unless (assq class project-class-alist) | 3181 | (unless (assq class dir-locals-class-alist) |
| 3182 | (error "No such project class `%s'" (symbol-name class))) | 3182 | (error "No such class `%s'" (symbol-name class))) |
| 3183 | (push (cons directory class) project-directory-alist)) | 3183 | (push (cons directory class) dir-locals-directory-alist)) |
| 3184 | 3184 | ||
| 3185 | (defun define-project-bindings (class settings) | 3185 | (defun dir-locals-set-class-variables (class variables) |
| 3186 | "Map the project type CLASS to a list of variable settings. | 3186 | "Map the type CLASS to a list of variable settings. |
| 3187 | CLASS is the project class, a symbol. | 3187 | CLASS is the project class, a symbol. VARIABLES is a list |
| 3188 | SETTINGS is a list that declares variable settings for the class. | 3188 | that declares directory-local variables for the class. |
| 3189 | An element in SETTINGS is either of the form: | 3189 | An element in VARIABLES is either of the form: |
| 3190 | (MAJOR-MODE . ALIST) | 3190 | (MAJOR-MODE . ALIST) |
| 3191 | or | 3191 | or |
| 3192 | (DIRECTORY . LIST) | 3192 | (DIRECTORY . LIST) |
| @@ -3198,13 +3198,13 @@ In the second form, DIRECTORY is a directory name (a string), and | |||
| 3198 | LIST is a list of the form accepted by the function. | 3198 | LIST is a list of the form accepted by the function. |
| 3199 | 3199 | ||
| 3200 | When a file is visited, the file's class is found. A directory | 3200 | When a file is visited, the file's class is found. A directory |
| 3201 | may be assigned a class using `set-directory-project'. Then | 3201 | may be assigned a class using `dir-locals-set-directory-class'. |
| 3202 | variables are set in the file's buffer according to the class' | 3202 | Then variables are set in the file's buffer according to the |
| 3203 | LIST. The list is processed in order. | 3203 | class' LIST. The list is processed in order. |
| 3204 | 3204 | ||
| 3205 | * If the element is of the form (MAJOR-MODE . ALIST), and the | 3205 | * If the element is of the form (MAJOR-MODE . ALIST), and the |
| 3206 | buffer's major mode is derived from MAJOR-MODE (as determined | 3206 | buffer's major mode is derived from MAJOR-MODE (as determined |
| 3207 | by `derived-mode-p'), then all the settings in ALIST are | 3207 | by `derived-mode-p'), then all the variables in ALIST are |
| 3208 | applied. A MAJOR-MODE of nil may be used to match any buffer. | 3208 | applied. A MAJOR-MODE of nil may be used to match any buffer. |
| 3209 | `make-local-variable' is called for each variable before it is | 3209 | `make-local-variable' is called for each variable before it is |
| 3210 | set. | 3210 | set. |
| @@ -3212,77 +3212,83 @@ LIST. The list is processed in order. | |||
| 3212 | * If the element is of the form (DIRECTORY . LIST), and DIRECTORY | 3212 | * If the element is of the form (DIRECTORY . LIST), and DIRECTORY |
| 3213 | is an initial substring of the file's directory, then LIST is | 3213 | is an initial substring of the file's directory, then LIST is |
| 3214 | applied by recursively following these rules." | 3214 | applied by recursively following these rules." |
| 3215 | (let ((elt (assq class project-class-alist))) | 3215 | (let ((elt (assq class dir-locals-class-alist))) |
| 3216 | (if elt | 3216 | (if elt |
| 3217 | (setcdr elt settings) | 3217 | (setcdr elt variables) |
| 3218 | (push (cons class settings) project-class-alist)))) | 3218 | (push (cons class variables) dir-locals-class-alist)))) |
| 3219 | 3219 | ||
| 3220 | (defun project-find-settings-file (file) | 3220 | (defconst dir-locals-file ".dir-locals.el" |
| 3221 | "Find the settings file for FILE. | 3221 | "File that contains directory-local variables. |
| 3222 | It has to be constant to enforce uniform values | ||
| 3223 | across different environments and users.") | ||
| 3224 | |||
| 3225 | (defun dir-locals-find-file (file) | ||
| 3226 | "Find the directory-local variables FILE. | ||
| 3222 | This searches upward in the directory tree. | 3227 | This searches upward in the directory tree. |
| 3223 | If a settings file is found, the file name is returned. | 3228 | If a local variables file is found, the file name is returned. |
| 3224 | If the file is in a registered project, a cons from | 3229 | If the file is already registered, a cons from |
| 3225 | `project-directory-alist' is returned. | 3230 | `dir-locals-directory-alist' is returned. |
| 3226 | Otherwise this returns nil." | 3231 | Otherwise this returns nil." |
| 3227 | (setq file (expand-file-name file)) | 3232 | (setq file (expand-file-name file)) |
| 3228 | (let ((settings (locate-dominating-file file ".dir-settings.el")) | 3233 | (let ((locals-file (locate-dominating-file file dir-locals-file)) |
| 3229 | (pda nil)) | 3234 | (dir-elt nil)) |
| 3230 | ;; `locate-dominating-file' may have abbreviated the name. | 3235 | ;; `locate-dominating-file' may have abbreviated the name. |
| 3231 | (when settings | 3236 | (when locals-file |
| 3232 | (setq settings (expand-file-name ".dir-settings.el" settings))) | 3237 | (setq locals-file (expand-file-name dir-locals-file locals-file))) |
| 3233 | (dolist (x project-directory-alist) | 3238 | (dolist (elt dir-locals-directory-alist) |
| 3234 | (when (and (eq t (compare-strings file nil (length (car x)) | 3239 | (when (and (eq t (compare-strings file nil (length (car elt)) |
| 3235 | (car x) nil nil)) | 3240 | (car elt) nil nil)) |
| 3236 | (> (length (car x)) (length (car pda)))) | 3241 | (> (length (car elt)) (length (car dir-elt)))) |
| 3237 | (setq pda x))) | 3242 | (setq dir-elt elt))) |
| 3238 | (if (and settings pda) | 3243 | (if (and locals-file dir-elt) |
| 3239 | (if (> (length (file-name-directory settings)) | 3244 | (if (> (length (file-name-directory locals-file)) |
| 3240 | (length (car pda))) | 3245 | (length (car dir-elt))) |
| 3241 | settings pda) | 3246 | locals-file |
| 3242 | (or settings pda)))) | 3247 | dir-elt) |
| 3243 | 3248 | (or locals-file dir-elt)))) | |
| 3244 | (defun project-define-from-project-file (settings-file) | 3249 | |
| 3245 | "Load a settings file and register a new project class and instance. | 3250 | (defun dir-locals-read-from-file (file) |
| 3246 | SETTINGS-FILE is the name of the file holding the settings to apply. | 3251 | "Load a variables FILE and register a new class and instance. |
| 3247 | The new class name is the same as the directory in which SETTINGS-FILE | 3252 | FILE is the name of the file holding the variables to apply. |
| 3253 | The new class name is the same as the directory in which FILE | ||
| 3248 | is found. Returns the new class name." | 3254 | is found. Returns the new class name." |
| 3249 | (with-temp-buffer | 3255 | (with-temp-buffer |
| 3250 | ;; We should probably store the modtime of SETTINGS-FILE and then | 3256 | ;; We should probably store the modtime of FILE and then |
| 3251 | ;; reload it whenever it changes. | 3257 | ;; reload it whenever it changes. |
| 3252 | (insert-file-contents settings-file) | 3258 | (insert-file-contents file) |
| 3253 | (let* ((dir-name (file-name-directory settings-file)) | 3259 | (let* ((dir-name (file-name-directory file)) |
| 3254 | (class-name (intern dir-name)) | 3260 | (class-name (intern dir-name)) |
| 3255 | (list (read (current-buffer)))) | 3261 | (variables (read (current-buffer)))) |
| 3256 | (define-project-bindings class-name list) | 3262 | (dir-locals-set-class-variables class-name variables) |
| 3257 | (set-directory-project dir-name class-name) | 3263 | (dir-locals-set-directory-class dir-name class-name) |
| 3258 | class-name))) | 3264 | class-name))) |
| 3259 | 3265 | ||
| 3260 | (declare-function c-postprocess-file-styles "cc-mode" ()) | 3266 | (declare-function c-postprocess-file-styles "cc-mode" ()) |
| 3261 | 3267 | ||
| 3262 | (defun hack-project-variables () | 3268 | (defun hack-dir-local-variables () |
| 3263 | "Read local variables for the current buffer based on project settings. | 3269 | "Read per-directory local variables for the current buffer. |
| 3264 | Store the project variables in `file-local-variables-alist', | 3270 | Store the directory-local variables in `file-local-variables-alist', |
| 3265 | without applying them." | 3271 | without applying them." |
| 3266 | (when (and enable-local-variables | 3272 | (when (and enable-local-variables |
| 3267 | (buffer-file-name) | 3273 | (buffer-file-name) |
| 3268 | (not (file-remote-p (buffer-file-name)))) | 3274 | (not (file-remote-p (buffer-file-name)))) |
| 3269 | ;; Find the settings file. | 3275 | ;; Find the variables file. |
| 3270 | (let ((settings (project-find-settings-file (buffer-file-name))) | 3276 | (let ((variables-file (dir-locals-find-file (buffer-file-name))) |
| 3271 | (class nil) | 3277 | (class nil) |
| 3272 | (root-dir nil)) | 3278 | (dir-name nil)) |
| 3273 | (cond | 3279 | (cond |
| 3274 | ((stringp settings) | 3280 | ((stringp variables-file) |
| 3275 | (setq root-dir (file-name-directory (buffer-file-name))) | 3281 | (setq dir-name (file-name-directory (buffer-file-name))) |
| 3276 | (setq class (project-define-from-project-file settings))) | 3282 | (setq class (dir-locals-read-from-file variables-file))) |
| 3277 | ((consp settings) | 3283 | ((consp variables-file) |
| 3278 | (setq root-dir (car settings)) | 3284 | (setq dir-name (car variables-file)) |
| 3279 | (setq class (cdr settings)))) | 3285 | (setq class (cdr variables-file)))) |
| 3280 | (when class | 3286 | (when class |
| 3281 | (let ((bindings | 3287 | (let ((variables |
| 3282 | (project-collect-binding-list (project-get-alist class) | 3288 | (dir-locals-collect-variables |
| 3283 | root-dir nil))) | 3289 | (dir-locals-get-class-variables class) dir-name nil))) |
| 3284 | (when bindings | 3290 | (when variables |
| 3285 | (hack-local-variables-filter bindings root-dir))))))) | 3291 | (hack-local-variables-filter variables dir-name))))))) |
| 3286 | 3292 | ||
| 3287 | 3293 | ||
| 3288 | (defcustom change-major-mode-with-file-name t | 3294 | (defcustom change-major-mode-with-file-name t |