Free recode package

Next: , Previous: Mixed, Up: Invoking recode


3.8 Using Recode within Emacs

The fact the recode program acts as a filter, when given no file arguments, makes it quite easy to use from within GNU Emacs. For example, recoding the whole buffer from the IBM-PC charset to current charset (for example, UTF-8 on Unix) is easily done with:

     C-x h C-u M-| recode ibmpc RET

C-x h’ selects the whole buffer, and ‘C-u M-|’ filters and replaces the current region through the given shell command. Here is another example, binding the keys ‘C-c T to the recoding of the current region from Easy French to Latin-1 (on Unix) and the key ‘C-u C-c T from Latin-1 (on Unix) to Easy French:

     (global-set-key "\C-cT" 'recode-texte)
     
     (defun recode-texte (flag)
       (interactive "P")
       (shell-command-on-region
        (region-beginning) (region-end)
        (concat "recode " (if flag "..txte" "txte")) t)
       (exchange-point-and-mark))