Note that there are some explanatory texts on larger screens.

plurals
  1. POElisp - adding multiple insertions to buffer-undo-list (saving undo information)
    primarykey
    data
    text
    <p><strong>Update: my original question was answered, but I'd like to know the more general approach - how can I define multiple operations which will be undone with a single C-/.</strong></p> <p>I'm trying to write a function which will automatically insert TODO comment into my code. I want this function to have an "undo option".</p> <p>I figured out how to add a mark to buffer-undo-list:</p> <pre><code>(setq buffer-undo-list (cons (point) buffer-undo-list)) </code></pre> <p>This allows me to return the point to the position from which this function was executed (if I decide to undo).</p> <p>My question is: how can I add multiple insertions to buffer-undo-list? What I mean is that there are multiple (insert str) statements in my function, but I want to undo all of them together with a single C-/ (if I decide to undo).</p> <p>I tried to copy exactly from other function which has this property, but this didn't work out. The code below is what I have now:</p> <pre><code>(defun insert-todo () "Appednd 'TODO username: date - ' at the end of line and set point to where this string ends" (interactive) (setq buffer-undo-list (cons (point) buffer-undo-list)) ;; save the point for undo (save-excursion (end-of-line) (setq eol (point)) (let ((buffer-undo-list t)) ;; do not record following commands for undo (insert " " comment-start (save-excursion comment-end)) (insert (format " TODO %s: " (getenv "USER")) (format-time-string "%d.%m.%Y") " - ") (setq buffer-undo-list (cons (cons eol (point)) buffer-undo-list)))) (end-of-line) ) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload