;;; dumlaut.el --- Fix Broken Umlate from Kill Ring -*- lexical-binding: t; -*- ;; Copyright (C) 2022, 2023 Philip Kaludercic ;; Author: Philip Kaludercic ;; Version: $Id: dumlaut.el,v 1.3 2023/05/04 09:36:10 oj14ozun Exp $ ;; URL: https://wwwcip.cs.fau.de/~oj14ozun/src+etc/dumlate.el ;; Package-Version: 1 ;; Keywords: convenience ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; Enable `dumlate-on-yank-mode' to fix broke umlaute when pasting ;; from PDFs. ;;; Code: (defgroup dumlat () "Fix Broken Umlate from Kill Ring." :group 'convenience) (defcustom dumlaut-mapping '((" ̈a" . "ä") (" ̈u" . "ü") (" ̈o" . "ö")) "Alist of mappings, translating faulty input to the correct replacement." :type '(alist :key-type string :value-type string)) (defun dumlat-cleanup (str) "Fix broken umlaute in STR." (replace-regexp-in-string (rx " ̈" alpha) (lambda (str) (alist-get str str nil #'string=)) str)) (defun dumlate-advise-insert-for-yank (args) "Apply `dumlat-cleanup' to the first argument in ARGS." (list (dumlat-cleanup (car args)))) ;;;###autoload (define-minor-mode dumlate-on-yank-mode "Minor mode to advise `insert-for-yank'." :global t (if dumlate-on-yank-mode (advice-add 'insert-for-yank :filter-args #'dumlate-advise-insert-for-yank) (advice-remove 'insert-for-yank #'dumlate-advise-insert-for-yank))) (provide 'dumlaut) ;;; dumlaut.el ends here