Is there any way to overwrite the "y" entry?

Every time when I evaluate this, it gets added as a new item on the list.

It makes it hard find an expression that works, when I can't replace the items on the list, without redefining the whole list again;)

(add-to-list 'org-agenda-custom-commands
      "f.emacs t.todo retry"  
      agenda                   ;type
      ""                       ;match - empty string for agenda type
      ((org-agenda-files '("/foo/bar.hukarz"))
       (org-agenda-skip-function '(org-agenda-skip-entry-if 'todo 'done))
       (org-agenda-span 'week)
       (org-deadline-warning-days 5)
       (org-super-agenda-groups '((:auto-category t :time-grid t))))))

1 Answer 1


One, relatively manual but relatively safe, way to do this is to define a symbol with the value of the element that you want to add:

(setq x '("y" ....))

The name of the symbol allows you to manipulate things much more easily. You can add it to the list, test and if you decide you need to change it, delete it from the list and redefine it differently before going back through the whole cycle again:

(add-to-list 'org-agenda-custom-cmmands x)
;;; test
(setq org-agenda-custom-commands (delete x org-agenda-custom-commands))
(setq x '("y" ....))
;;; lather, rinse, repeat

I find that convenient, and I get direct confirmation since both add-to-list and delete return the resulting list: I can eyeball it and make sure that things are as they should be.

You could automate the above, but automated solutions tend to lose that feedback.

If you have a list already constructed and you want to delete an element that you don't have a handle on (e.g. you don't have a variable that is set to this element as above), you could do something like this:

;; construct a list to play with - in the scenario, this is something 
;; that exists already, but for the sake of the example
;; I construct it explicitly here
(setq some-list '((a b c) (d e f) (g h i) (j k l)))

;; suppose you want to delete the third element, i.e. (g h i)
;; - you can get this element with (nth 2 some-list) 
;; - note that `nth' counts from 0.

(nth 2 some-list) ;; ---> (g h i)

;; You can then call `delete' to make you a new list with that
;; element deleted and assign it back to `some-list'
(setq some-list (delete (nth 2 some-list) some-list)) 
   ;; ---> ((a b c) (d e f) (j k l))

So you get the element in this case by using the index of the element in the list. If the list is short, it's easy to count elements.

You could also get a handle using `assoc':

;; Assume we are starting with the initial list again (i.e. containing (g h i)

(assoc 'g some-list) ;; ---> (g h i)

(setq some-list (delete (assoc 'g some-list) some-list))
    ;; ---> (a b c) (d e f) (j k l))

Here you get the element by searching the list for the element of interest.

If you have a preexisting list and you want to delete an element from it, one or the other of these methods might be useful. The important thing is the pattern: you somehow get the element and then you use delete with that element on the original list. That returns a new list which you assign back to the list variable.

  • Fixed a bug in the code: delete returns the modified list which has to be saved back to the original list in order to undo the change.
    – NickD
    Commented May 16, 2023 at 17:10
  • This does not work for me; i only get Debugger entered--Lisp error: (wrong-type-argument listp org-agenda-custom-commands) Commented Jun 23, 2023 at 22:15
  • Another bug: no quote on org-agenda-custom-commands in the delete form. Sorry about that: fixed.
    – NickD
    Commented Jun 24, 2023 at 2:08
  • Thank you; that works;) Commented Jun 24, 2023 at 11:05
  • I do experience though, that when I forget to delete an entry and I accidentally add it, that I have trouble deleting it. I'm thinking maybe I should rather go for a solution that overwrites the current entry, some kind of ID, so that I don't have to worry about it;) Commented Jun 24, 2023 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.