1

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.

tarsius
  • 25,685
  • 4
  • 70
  • 109
Tim
  • 5,007
  • 7
  • 32
  • 61

1 Answers1

2

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)))))))
jch
  • 5,720
  • 1
  • 23
  • 39