@Anonymous wrote:
That's ok, but it should make a replacement automatically. No need to type in the command line. So, by running the script, the text should change automatically.
I'm guessing you meant not typing the old and new pattern on the command prompt.
All calls to (txtfind ol nt) At the bottom end of trc.lsp file will run when the file is loaded, now if you want to run the find and replace thing again on an already opened, you can either load the lisp again or add the code below at the end of the file, and type txtfind at the command prompt.
command: txtfind <-- [ "the text should change automatically." ]
(defun c:txtfind ()
(foreach itm '(("Ĺ " "Š")
("š" "š")
("Ä" "Ä")
("Ä‘" "đ")
("ÄŚ" "Č")
("ÄŤ" "Ä")
("Ć" "Ć")
("ć" "Ć")
("ĹË" "Ž")
("Ĺľ" "ž")
)
(txtfind (Car itm) (cadr itm))
)(princ)
)
or as per @hak_vz suggestion use an external source file for the pattern. That way you can add new patterns to find and replace
(defun c:txtfind ( / f opf a)
(if (setq f (findfile "patterns.txt")) ;<-- you can hard code the location here
(progn
(setq opf (open f "r"))
(while (setq a (read-line opf))
(eval (read a))
)
(close opf)
)
)
(princ)
)
and this as "patterns.txt" [ save this file within reach of SFSP or change the path on the code
(txtfind "Ĺ " "Š")
(txtfind "š" "š")
(txtfind "Ä" "Ä")
(txtfind "Ä‘" "đ")
(txtfind "ÄŚ" "Č")
(txtfind "ÄŤ" "Ä")
(txtfind "Ć" "Ć")
(txtfind "ć" "Ć")
(txtfind "ĹË" "Ž")
(txtfind "Ĺľ" "ž")
Even better is @Sea-Haven suggestion of using reactors, no typing of command, but its always lurking on the background. To get into that discussion would mean to open a can of worms and i'm not doing that 🙂
HTH