2
(add-hook 'org-mode-hook
          (lambda ()
            (setq-local ac-sources
                        (delq '(ac-source-dictionary ac-source-words-in-same-mode-buffers) ac-sources))))

I found here delq only can delete element from list, it can't delete a list from another list. neither delete.

So how to archive my effect.

stardiviner
  • 1,090
  • 1
  • 22
  • 33
  • I am surprised by the statement that `delete` does not delete a list from a list. In my emacs scratch buffer the result of `(delete '(first 2) '(first 2 (first 2) third 4))` is `(first 2 third 4)`. – Tobias Jul 29 '14 at 11:27

2 Answers2

3

Use delq in a loop:

(mapcar (lambda (x) (setq ac-sources (delq x ac-sources)))
        '(ac-source-dictionary ac-source-words-in-same-mode-buffers))
abo-abo
  • 20,038
  • 3
  • 50
  • 71
  • 2
    Probably better to use `mapc` if you don't require `mapcar`'s accumulated result. – phils Jul 29 '14 at 09:05
  • Sure, why not. I was surprised that I had to use `setq`. Do you know why a plain `delq` doesn't work? – abo-abo Jul 29 '14 at 09:20
  • 2
    @abo-abo The variable points to the first cons cell in the list, which stores the first list element. If `delq` drops that element and its cons cell, the variable still holds the *old* cons cell. –  Jul 29 '14 at 10:00
  • Oh, I see, this help me, I did some test with (1 2 3) and ((1 2 3) 4 5 6). I wander why (1 2 3) can't be delete. Now I see. – stardiviner Jul 30 '14 at 02:47
2

The function you are looking for is called cl-set-difference:

(add-hook 'org-mode-hook
  (lambda ()
    (setq-local ac-sources
                (cl-set-difference 
                 ac-sources
                 '(ac-source-dictionary ac-source-words-in-same-mode-buffers)))))

See also How to calculate difference between two sets in emacs lisp,the sets should be lists.

Community
  • 1
  • 1
sds
  • 58,617
  • 29
  • 161
  • 278