2009-05-22 12 views
10

मैं कैसे जांचूं कि Emacs Lisp में एक स्ट्रिंग पहले से मौजूद है या नहीं? मुझे यह जांचने की ज़रूरत है कि कोई निश्चित पथ स्ट्रिंग पहले से ही exec-path में है या नहीं, और फिर इसे उस सूची में जोड़ें यदि यह नहीं है। धन्यवाद!Emacs Lisp: डुप्लिकेट सूची आइटम डालने से कैसे बचें?

उत्तर

17

समारोह जोड़ने करने वाली सूची

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

जोड़ने से पहले स्वचालित रूप से जाँच करने के लिए a (4 1 2 3)

Ch च से

बराबर का परिणाम देगा होगा जोड़ने करने के लिए सूची:

 
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

यह बहुत अच्छा है! धन्यवाद! –

संबंधित मुद्दे