From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Francesco Potorti` Newsgroups: gmane.emacs.devel Subject: buffer-charset Date: Thu, 10 Oct 2002 15:34:24 +0200 Sender: emacs-devel-admin@gnu.org Message-ID: NNTP-Posting-Host: localhost.gmane.org X-Trace: main.gmane.org 1034257346 24596 127.0.0.1 (10 Oct 2002 13:42:26 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 10 Oct 2002 13:42:26 +0000 (UTC) Cc: Joanna Pluta Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 17zda5-0006Oa-00 for ; Thu, 10 Oct 2002 15:42:25 +0200 Original-Received: from monty-python.gnu.org ([199.232.76.173]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 17zeOZ-0001V2-00 for ; Thu, 10 Oct 2002 16:34:39 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.10) id 17zdWz-0003kZ-00; Thu, 10 Oct 2002 09:39:13 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.10) id 17zdWH-0003KK-00 for emacs-devel@gnu.org; Thu, 10 Oct 2002 09:38:29 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.10) id 17zdWF-0003Jl-00 for emacs-devel@gnu.org; Thu, 10 Oct 2002 09:38:28 -0400 Original-Received: from pot.cnuce.cnr.it ([146.48.83.182]) by monty-python.gnu.org with esmtp (Exim 4.10) id 17zdWD-0003JY-00 for emacs-devel@gnu.org; Thu, 10 Oct 2002 09:38:26 -0400 Original-Received: from pot by pot.cnuce.cnr.it with local (Exim 3.36 #1 (Debian)) id 17zdWD-00034r-00; Thu, 10 Oct 2002 15:38:25 +0200 Original-To: Emacs developers X-fingerprint: 4B2 6187 5C3 D6B1 2E31 7666 9DF 2DC9 BE21 6115 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.11 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:8506 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:8506 Some time ago I advocated the use of buffer-charset.el (appended) to ease users' problems when meeting strange characters in their buffers. I was answered that this was not the right solution. However, unless something better has come up in the meantme, I found it very useful in the last month or so. I'll give an example. I take the file in and save it into `ann'. Then emacs -q C-x m C-c TAB ann RET C-c C-c I get a pop-up window proposing a bunch of "safe" coding systems. Obviously I have no idea why ever I should change my coding system, given that the file I included is apparently text only. So I do: M-x load-library RET buffer-charset RET M-x highlight-charset-characters RET TAB and I get a completion window with these possible charset to higlight: ascii latin-iso8859-1 mule-unicode-0100-24ff Obviously the last one is strange. So I select that to highlight, look in the buffer and discover that there are two such characters, which I can change or leave alone, if I know what I do (I don't). In summary, I find this to be a really useful and comfortable user interface for dealing with these problems, until a better one is introduced. ===File ~/elisp/buffer-charset.el=========================== ;;; buffer-charsets.el --- show usage of charsets in a buffer ;; Copyright (C) 2002 Joanna Pluta. ;; Keywords: mule, hi-lock ;; This file is [not yet] part of GNU Emacs. ;; 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 2, 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. ;; A copy of the GNU General Public License can be obtained from this ;; program's author (send electronic mail to ) or ;; from the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, ;; MA 02139, USA. ;;; Commentary: ;; - display-buffer-charsets ;; Displays list of charsets used in current buffer. ;; - show-buffer-charset-characters C-x w c ;; Uses hi-lock-mode to highlight in current buffer characters ;; from chosen charset. ;; Creates and adds to local history (hi-lock-interactive-patterns) ;; regexpx matching characters from a given charset. ;; Characters from different charsets can be highlighted by ;; different colors according to chosen face. ;; - unhighlight-charset C-x w u ;; unhighlights characters from given charset ;; ;;; Code: ;;; (require 'hi-lock) (defun charset-chars-regexp (charset) (let ((dim (charset-dimension charset)) (chars (charset-chars charset)) (plane (charset-iso-graphic-plane charset)) min max) (cond ((eq charset 'eight-bit-control) (setq min 128 max 159)) ((eq charset 'eight-bit-graphic) (setq min 160 max 255)) (t (if (= chars 94) (setq min 33 max 126) (setq min 32 max 127)) (or (= plane 0) (setq min (+ min 128) max (+ max 128))))) (if (= dim 1) (format "[%c-%c]" (make-char charset min) (make-char charset max)) (format "[%c-%c]" (make-char charset min min) (make-char charset max max))))) (defun buffer-charsets () (find-charset-region (point-min) (point-max))) (defun display-buffer-charsets () "Displays list of charsets used in current buffer" (interactive) (let ((charsets (buffer-charsets)) (curr-buf-name (current-buffer))) (with-output-to-temp-buffer "*Buffer Charsets*" (save-excursion (set-buffer standard-output) (insert (format "Buffer %s uses the following charsets:\n" curr-buf-name)) (while charsets (insert (symbol-name (car charsets))) (insert "\n") (setq charsets (cdr charsets))))))) (defun charset-alist (charset-list) (let ((l (charset-list)) charset-alist) (while l (setq charset-alist (cons (list (symbol-name (car l))) charset-alist)) (setq l (cdr l))) charset-alist)) (defalias 'highlight-charset-characters 'show-buffer-charset-characters) (defun show-buffer-charset-characters (charset face) "Uses hi-lock-mode to highlight by face characters of charset." (interactive (let ((completion-ignore-case t)) (list (completing-read "Charset:" (charset-alist (buffer-charsets)) nil t nil nil) (hi-lock-read-face-name)))) (highlight-regexp (charset-chars-regexp (intern charset)) face)) (defun unhighlight-charset (charset) (interactive (let ((completion-ignore-case t)) (list (completing-read "Charset:" (charset-alist (buffer-charsets)) nil t nil nil)))) (unhighlight-regexp (charset-chars-regexp (intern charset)))) (define-key hi-lock-map "\C-xwc" 'show-buffer-charset-characters) (define-key hi-lock-map "\C-xwu" 'unhighlight-charset) ;;; mule-utils.el ends here ============================================================