First, from the look of your function, you are likely to do this in the current buffer, so no, you do not need to have the "buffer" argument. If this is a bad guess, I can change the code. Further, in "let", if you assign variables, you need another set of parsers around each var / value pair. Finally, when navigating through the list, I prefer to use functionally programmable functions (mapcar, mapc, etc.). I will try to insert some comments here:
(defun my-func () "Do some replacements" (interactive) (let ((replacements (list '("foo" . "bar") '("baz" . "quux")))) (save-excursion ; So point isn't moved after this function (mapc (lambda (x) ; Go through the list, with this 'inline' function ; being called with each element as the variable 'x' (goto-char (point-min)) ; Start at the beginning of the buffer (while (re-search-forward (car x) nil t) ; Search for the car of the replacement (replace-match (cdr x)))) ; And replace it with the cdr replacements)))) ; The list we're mapc'ing through
As for reading, I would suggest the Elisp manual that comes with Emacs.
source share