I struggled with some „profane“ text edit duties, but well, in
over 100 files, and as a programmer … you know what we do.
Spend 3 hours to save repeating a task a few hundred times 😉
My problem, I had to match [[SomeContent]]
And I had an assoc list
setq 'assoc-listt'(("Key-1", "Value1"
("SomeContent", "Some Link to")
I did not get the regular expression right, ChatGPT did it:
(defun my-function ()
(interactive)
(with-temp-buffer
(insert-file-contents "filename.txt")
(goto-char (point-min))
;; Search and replace
(while (re-search-forward "\\[\\[\\(.*?\\)\\]\\]" nil t)
(let* ((match (match-string 1))
(value (cdr (assoc match some-alist))))
(when value
(replace-match (format "[[file://%s][%s]]" value match) nil t nil 1))))))
Just one problem the last 1 , that lead to the non replacement of [[ and]] replace it with zero and you’re fine. With some stuff around, with some saving of buffers, did I get what I wanted.
It’s always nice if you can program your editor, and I doubt there is anything as programmable as an Emacs 😉
Thanks for the fish – ah sorry code …