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.

1
  • 2
    Aside: the term you're looking for is "ligature."
    – Dan
    Jan 5, 2015 at 1:52

1 Answer 1

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)))))))
2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.