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.
Emacs Stack Exchange is a question and answer site for those using, extending or developing Emacs. It only takes a minute to sign up.
Sign up to join this communityI 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
.
Jan 5, 2015 at 3:55