I have a text file, whose content is from a pdf file.
I would like to replace two letter combos, such as "fl" and more, with the two letters.
Is it possible to do that in Emacs just once, without repeating for each specific combo?
Thanks.
I have a text file, whose content is from a pdf file.
I would like to replace two letter combos, such as "fl" and more, with the two letters.
Is it possible to do that in Emacs just once, without repeating for each specific combo?
Thanks.
I don't think there's a built-in function to do that. The obvious candidate would be translate-region
, but it uses an extremely unwieldy data structure.
Fortunately, this is easily solved with just a little bit of ELisp hacking:
(defvar funky-chars-alist '((?fl . "fl") (?fi . "fi")))
(defun replace-all-funky-chars ()
(interactive)
(save-excursion
(while (not (eobp))
(let ((string (cdr (assoc (char-after) funky-chars-alist))))
(cond
(string (delete-char 1) (insert string))
(t (forward-char)))))))
funky-chars-alist
.
– Greg Hendershott
Jan 05 '15 at 03:55