From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Dave Love Newsgroups: gmane.emacs.devel Subject: Re: enhanced select-safe-coding-system Date: 02 May 2002 23:39:58 +0100 Sender: emacs-devel-admin@gnu.org Message-ID: References: <200205010714.g417Eq607434@aztec.santafe.edu> NNTP-Posting-Host: localhost.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: main.gmane.org 1020379360 8371 127.0.0.1 (2 May 2002 22:42:40 GMT) X-Complaints-To: usenet@main.gmane.org NNTP-Posting-Date: Thu, 2 May 2002 22:42:40 +0000 (UTC) Cc: emacs-devel@gnu.org Return-path: Original-Received: from quimby.gnus.org ([80.91.224.244]) by main.gmane.org with esmtp (Exim 3.33 #1 (Debian)) id 173PHb-0002Au-00 for ; Fri, 03 May 2002 00:42:39 +0200 Original-Received: from fencepost.gnu.org ([199.232.76.164]) by quimby.gnus.org with esmtp (Exim 3.12 #1 (Debian)) id 173PN1-00070e-00 for ; Fri, 03 May 2002 00:48:15 +0200 Original-Received: from localhost ([127.0.0.1] helo=fencepost.gnu.org) by fencepost.gnu.org with esmtp (Exim 3.34 #1 (Debian)) id 173PH3-0007mK-00; Thu, 02 May 2002 18:42:05 -0400 Original-Received: from djlvig.dl.ac.uk ([148.79.112.146]) by fencepost.gnu.org with smtp (Exim 3.34 #1 (Debian)) id 173PF5-0007Xm-00; Thu, 02 May 2002 18:40:03 -0400 Original-Received: from fx by djlvig.dl.ac.uk with local (Exim 3.12 #1 (Debian)) id 173PF3-0003vV-00; Thu, 02 May 2002 23:40:01 +0100 Original-To: rms@gnu.org Original-Lines: 64 User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.1.95 Errors-To: emacs-devel-admin@gnu.org X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.0.9 Precedence: bulk List-Help: List-Post: List-Subscribe: , List-Id: Emacs development discussions. List-Unsubscribe: , List-Archive: Xref: main.gmane.org gmane.emacs.devel:3516 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:3516 Richard Stallman writes: > Your code was based on an older version Yes, probably over a year old. > did not have some other changes that are in the sources now. I > merged it, and the changes you made seem to be these. They look like the right sort of changes, but you want to break this line so that it's obvious that `coding-system' is being returned. > ! (error "Save aborted"))))) coding-system)) Incidentally, I think Emacs should have `remove-if', or whatever Common Lisp calls the function for filtering lists according to a predicate, as I needed to filter the coding list. That operation seems quite common. If you want to make select-safe-coding-system more helpful, you could also use code like this to find at least the first unencodable character and display that part of the buffer when select-safe-coding-system needs to prompt for a coding system. Emacs 20 used to do something similar, but it was only necessary to check charsets then. (defun unencodable-char-position (start end coding-system) "Return position of first un-encodable character in a region. START and END specfiy the region and CODING-SYSTEM specifies the encoding to check. Return nil if CODING-SYSTEM does encode the region. CODING-SYSTEM may also be a list of coding systems, in which case return the first position not encodable by any of them. This function is fairly slow." ;; Use recursive calls in the binary chop below, since we're ;; O(logN), and the call overhead shouldn't be a bottleneck. (unless enable-multibyte-characters (error "unibyte buffer")) ;; Recurse if list of coding systems. (if (consp coding-system) (let ((end end) res) (dolist (elt coding-system (and res (>= res 0) res)) (let ((pos (unencodable-char-position start end elt))) (if pos (setq end pos res pos))))) ;; Skip ASCII initially. (save-excursion (skip-chars-forward "\000-\177" end) (setq start (point))) (unless (= start end) (setq coding-system (coding-system-base coding-system)) ; canonicalize (let ((codings (find-coding-systems-region start end))) (unless (or (equal codings '(undecided)) (memq coding-system (find-coding-systems-region start end))) ;; Binary chop. (if (= start (1- end)) start (or (unencodable-char-position start (/ (+ start end) 2) coding-system) (unencodable-char-position (/ (+ start end) 2) end coding-system))))))))