2009-05-22 60 views

回答

17

功能添加到列表将添加

(setq a '(1 2 3)) 
(add-to-list 'a 4) 
(add-to-list 'a 3) 

之前自动检查将导致a等于(4 1 2 3)

选自CH添加F到列表:

 
add-to-list is a compiled Lisp function in `subr.el'. 
(add-to-list list-var element &optional append compare-fn) 

Add element to the value of list-var if it isn't there yet. 
The test for presence of element is done with `equal', 
or with compare-fn if that's non-nil. 
If element is added, it is added at the beginning of the list, 
unless the optional argument append is non-nil, in which case 
element is added at the end. 

The return value is the new value of list-var. 

If you want to use `add-to-list' on a variable that is not defined 
until a certain package is loaded, you should put the call to `add-to-list' 
into a hook function that will be run only after loading the package. 
`eval-after-load' provides one way to do this. In some cases 
other hooks, such as major mode hooks, can do the job. 

+3

这太棒了!谢谢! – 2009-05-22 06:37:51