;;; remove-iso8859-15.el --- workaround for an iso8859-15 font problem ;; Copyright (C) 2003 Dr. Heiko Münkel ;; email: muenkel@tnt.uni-hannover.de ;; This 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 2, or (at your option) ;; any later version. ;; This file 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 file; see the file COPYING. If not, write to the ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, ;; Boston, MA 02111-1307, USA. ;;; Commentary: ;;; The code in this file is a workaround for the following problem: ;;; If one uses the the iso8859-15 coding and copy some text from ;;; a X11 selection in the XEmacs, which contains iso8859-1 Umlaute ;;; (äöüÄÖÜß), strings like %/1€Œiso8859-15 will be inserted ;;; in the buffer. This is (was) at least true for KDE 3.1 and the ;;; XEmacs 21.4 (patch 8). ;;; The workaround defines the function get-selection-1 with the same ;;; body as the original funtion get-selection. It also defines a new ;;; function get-selection, which uses get-selection-1 and removes the ;;; "bad" iso8859-15 strings from the selection. ;;; Note: Workaround works also in the GNU Emacs 21.2.1. ;;; ;;; Installation: ;;; Put the following form in your ~/.emacs (or maybe ~/.xemacs/init.el): ;;; (when (eq window-system 'x) ;;; (require 'remove-iso8859-15)) ;;; and put this file somewhere in your loadpath. ;;; Code: (provide 'remove-iso8859-15) (setq get-selection-iso-string (concat (regexp-quote "%/1€") "." (regexp-quote "iso8859-15"))) (if (string-match "XEmacs" emacs-version) (progn (defun get-selection-1 (&optional type data-type) "Same as the original function get-selection from select.el." (or type (setq type 'PRIMARY)) (or data-type (setq data-type selected-text-type)) (if (consp data-type) (condition-case err (get-selection-internal type (car data-type)) (selection-conversion-error (if (cdr data-type) (get-selection type (cdr data-type)) (signal (car err) (cdr err))))) (get-selection-internal type data-type))) (defun get-selection (&optional type data-type) "Return the value of a window-system selection. The argument TYPE (default `PRIMARY') says which selection, and the argument DATA-TYPE (default `STRING', or `COMPOUND_TEXT' under Mule) says how to convert the data. If there is no selection an error is signalled. Not suitable in a `interprogram-paste-function', q.v." (replace-in-string (get-selection-1 type data-type) get-selection-iso-string "")) ) (defun yank-1 (&optional arg) "Same as the original function yank from simple.el." (interactive "*P") ;; If we don't get all the way thru, make last-command indicate that ;; for the following command. (setq this-command t) (push-mark (point)) (let ((opoint (point))) (insert (current-kill (cond ((listp arg) 0) ((eq arg '-) -1) (t (1- arg))))) (let ((inhibit-read-only t)) (remove-text-properties opoint (point) '(read-only nil)))) (if (consp arg) ;; This is like exchange-point-and-mark, but doesn't activate the mark. ;; It is cleaner to avoid activation, even though the command ;; loop would deactivate the mark because we inserted text. (goto-char (prog1 (mark t) (set-marker (mark-marker) (point) (current-buffer))))) ;; If we do get all the way thru, make this-command indicate that. (setq this-command 'yank) nil) (defun yank (&optional arg) "Reinsert the last stretch of killed text. More precisely, reinsert the stretch of killed text most recently killed OR yanked. Put point at end, and set mark at beginning. With just C-u as argument, same but put point at beginning (and mark at end). With argument N, reinsert the Nth most recently killed stretch of killed text. See also the command \\[yank-pop]." (interactive "*P") (let ((start (point))) (yank-1 arg) (save-excursion (replace-regexp get-selection-iso-string "" nil start (point)) ))) )