错误的类型参数:listp,eval-after-load in .dir-locals.el [英] Wrong type argument: listp, eval-after-load in .dir-locals.el

查看:127
本文介绍了错误的类型参数:listp,eval-after-load in .dir-locals.el的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写我的第一个 .dir-locals.el ,我在中收到错误*消息*

代码:

 (eval-after-加载grep
'(add-to-list'grep-find-ignored-directoriesblur))

跟踪:

  .dir-localals错误:类型参数错误:listp,eval-after-load 

我做错了什么?

解决方案

这里介绍 .dir-locals.el 的一般格式:





要评估代码,您必须使用特殊的伪变量名称 eval ,如下所述:





例如:

 ((nil。 ((indent-tabs-mode。t)
(eval。(eval-after-loadgrep
'(add-to-list'grep-find-ignored-directoriesblur)) )
(fill-column。80)))
(c-mode。((c-file-style。BSD)
(subdirs。nil))))

然而 grep-find-ignored-directories 不是一个自动的缓冲区局部变量,我们没有将它显式设置为目录本地变量(这里的'局部变量'是 eval ),所以当 grep-find-ignored-directories 设置为全局设置时,这肯定不是你想要的 1



您可能会尝试这样:

 ((nil。 ((eval-after-loadgrep
'(add-to-list
(make-local-variable'grep-find-ignored-directories)
blur ))))))

实际上这仍然是错误的,因为一旦你访问了这个目录下的一个文件,那么 eval-after-load (这是一个全局设置) code> grep 被加载,无论您当时使用哪种缓冲区,您可以轻松地将blur值添加到某些不需要的缓冲区中你称之为grep,而且失败将它添加到您想要的任何先前访问过的缓冲区中。



最简单的解决方案可能在设置变量之前强制要求grep:

 ((nil。 ((eval)(progn 
(require'grep)
(add-to-list
(make-local-variable'grep-find-ignored-directories)
blur )))))))

确保目录下的所有文件都将获得本地值而在其他地方的文件不会)。



现在,这是一般问题的一种方法,但是看看这个具体的例子,而 Ch v grep-find-ignored-directories ,此变量提供了一些功能,可以使解决方案更简单,并且不需要grep加载不必要。



您的.dir-locals.el文件可以设置一个局部变量:

 code>((nil。((my-ignore-blur-p。t))))



 (defun my-ignore -blur-p(dir)
返回非零当设置'my-ignore-blur-p'局部变量时,
(local-variable-if-set-p'my-ignore-blur-p))

eval-after-loadgrep
'(add-to-list'grep-find-ignored-directories
(cons'my-ignore-blur-pblur)))

然后当您从其中的任何缓冲区执行 rgrep 局部变量被设置,我们在全局 grep-find-ignored-directories 变量中指定的自定义函数将返回一个非 nil 值,这将导致模糊被包含在忽略的目录列表中。



(nb我为函数和变量使用相同的名称,因为我可以 - elisp具有用于变量和函数的单独的名称空间 - 但这不是必需的。为了清楚起见,我指的是 eval-after-load 代码中的函数,而变量功能代码和.dir-locals.el文件)。



或者你可以根据 my-ignore-blur- p 函数在 dir 参数(正在搜索的目录)中,并且完全忽略局部变量。这将使得决定从列表中完全独立于您启动rgrep命令的缓冲区中包含或忽略模糊,这可能更为可取。






1 如果在中添加模糊grep-find-ignored-directories 全局您想要的,然后不要使用 .dir-locals.el ,只需添加 eval-after-加载调用.emacs文件。


I'm writing my first .dir-locals.el, and I'm getting an error in *Messages*.

Code:

(eval-after-load "grep"
  '(add-to-list 'grep-find-ignored-directories "blur"))

Trace:

.dir-locals error: Wrong type argument: listp, eval-after-load

What am I doing wrong?

解决方案

The general format for .dir-locals.el is described here:

To evaluate code, you must use the special pseudo variable name eval, as described at:

e.g.:

((nil . ((indent-tabs-mode . t)
         (eval . (eval-after-load "grep"
                   '(add-to-list 'grep-find-ignored-directories "blur")))
         (fill-column . 80)))
 (c-mode . ((c-file-style . "BSD")
            (subdirs . nil))))

However, grep-find-ignored-directories is not an automatic buffer-local variable, and we are not explicitly setting it as a directory local variable here (the 'local variable' in question here is eval), so when grep-find-ignored-directories gets set this way it is set globally, which is surely not what you intended1.

You might try something like this:

((nil . ((eval . (eval-after-load "grep"
                   '(add-to-list 
                     (make-local-variable 'grep-find-ignored-directories) 
                     "blur"))))))

but in fact that's still wrong, as once you have visited a file under this directory, that eval-after-load (which is a global setting) will be triggered as soon as grep is loaded, no matter which buffer you are in at the time, so you could easily add your "blur" value locally in some unwanted buffer from which you called grep, while also failing to add it for any of the previously-visited buffers in which you wanted it.

The simplest solution is probably to forcibly require grep before setting the variable:

((nil . ((eval . (progn
                   (require 'grep)
                   (add-to-list 
                    (make-local-variable 'grep-find-ignored-directories)
                    "blur"))))))

That ensures that all files under the directory will get the local value (and that files elsewhere will not).

Now, that's one approach to the general problem, but taking a look at this specific case, and C-hv grep-find-ignored-directories, this variable provide some functionality which can make the solution simpler, and not require grep to be loaded unnecessarily.

Your .dir-locals.el file can set a local variable thus:

((nil . ((my-ignore-blur-p . t))))

And in your .emacs you can do the following:

(defun my-ignore-blur-p (dir)
  "Return non-nil when the `my-ignore-blur-p' local variable is set."
  (local-variable-if-set-p 'my-ignore-blur-p))

(eval-after-load "grep"
  '(add-to-list 'grep-find-ignored-directories
                (cons 'my-ignore-blur-p "blur")))

Then when you execute rgrep from any buffer in which this local variable is set, the custom function we have specified in the global grep-find-ignored-directories variable will return a non-nil value, which will cause "blur" to be included in the list of ignored directories.

(n.b. I used the same name for both the function and the variable because I can -- elisp has separate name spaces for variables and functions -- but that's not necessary. For clarity, I'm referring to the function in the eval-after-load code, and the variable in the function code and the .dir-locals.el file).

Or you could just base the behaviour of the my-ignore-blur-p function on the dir argument (being the directory being searched), and ignore local variables altogether. That would make the decision to include or omit "blur" from the list completely independent of the buffer from which you initiated the rgrep command, which might be even more desirable.


1 If adding "blur" to grep-find-ignored-directories globally is what you wanted, then don't use .dir-locals.el at all -- just add your eval-after-load call to your .emacs file.

这篇关于错误的类型参数:listp,eval-after-load in .dir-locals.el的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆