> "Stephen" == Stephen J Turnbull
<stephen(a)xemacs.org> writes:
Uwe Brauer writes:
> - a function which does the replacement and
(while (search-forward TARGET nil t)
(replace-match REPLACEMENT))
is extremely fast assuming multiple replacements per TARGET. If you
expect most of your words to occur many times, I would put this in the
inner loop unless your file is more than a megabyte or two.
Depends on what you're going to do with it. If you're just
going to
search one file for each word once, 2000 or 3000 is not that big. I
would guess that the very naive program which loops over words and
searches the whole file for each one as in the while-search-forward
loop would take minutes (maybe up to 30, but I bet much less).
The idea is to have a pkg which I could apply to any file with hebrew
text in the future. These files itself maybe small, corresponding to 2 o
three written pages. However the list containing niqqud and no niqqud
could have at least 2000 entries maybe more.
The code I was thinking to use is basically as follows
(defun niqqud-translate-conventions (trans-tab)
"Use the translation table argument to translate the current buffer."
(save-excursion
(let ((beg (point-min-marker))
(end (point-max-marker)))
(unwind-protect
(progn
(widen)
(goto-char (point-min))
(let ((buffer-read-only nil) ; (inhibit-read-only t)?
(case-fold-search nil))
(while trans-tab
(save-excursion
(let ((trans-this (car trans-tab)))
(while (search-forward (car trans-this) nil t)
(replace-match (car (cdr trans-this)) t t)))
(setq trans-tab (cdr trans-tab))))))
(narrow-to-region beg end)))))
I am not sure the narrow stuff is necessary, the basic functionality is
replace-match.
(defvar niqqud-trans-tab
'(
("הם" "הֶם")
)
"Translation table from niqqud to NO niqqud.")
(defun hebrew-fix-niqqud ()
"Remove Niqqud."
(interactive)
(let ((buffer-modified-p (buffer-modified-p)))
(unwind-protect
(niqqud-translate-conventions niqqud-trans-tab)
(set-buffer-modified-p buffer-modified-p))))
And the question is how big could niqqud-trans-tab be. 10 Megas?
I see the code you have in mind is very different.
BTW which format is supposed to have your file "load-my-table.el" ?
Thanks to both of you.
Uwe
_______________________________________________
XEmacs-Beta mailing list
XEmacs-Beta(a)xemacs.org
http://lists.xemacs.org/mailman/listinfo/xemacs-beta