bytecomp.el fix for bug#8647
[bpt/emacs.git] / lisp / disp-table.el
index a71ef02..7a9043a 100644 (file)
@@ -1,19 +1,20 @@
 ;;; disp-table.el --- functions for dealing with char tables
 
-;; Copyright (C) 1987, 1994, 1995, 1999, 2001, 2002, 2003, 2004,
-;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 1987, 1994-1995, 1999, 2001-2011
+;;   Free Software Foundation, Inc.
 
 ;; Author: Erik Naggum <erik@naggum.no>
 ;; Based on a previous version by Howard Gayle
 ;; Maintainer: FSF
 ;; Keywords: i18n
+;; Package: emacs
 
 ;; This file is part of GNU Emacs.
 
-;; GNU Emacs is free software; you can redistribute it and/or modify
+;; GNU Emacs 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, or (at your option)
-;; any later version.
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -21,9 +22,7 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to the
-;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-;; Boston, MA 02110-1301, USA.
+;; along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.
 
 ;;; Commentary:
 
@@ -89,8 +88,7 @@ Valid symbols are `truncation', `wrap', `escape', `control',
     (princ "\nVertical window border glyph: ")
     (prin1 (display-table-slot dt 'vertical-border))
     (princ "\nCharacter display glyph sequences:\n")
-    (save-excursion
-      (set-buffer standard-output)
+    (with-current-buffer standard-output
       (let ((vector (make-vector 256 nil))
            (i 0))
        (while (< i 256)
@@ -112,11 +110,27 @@ Valid symbols are `truncation', `wrap', `escape', `control',
 
 ;;;###autoload
 (defun standard-display-8bit (l h)
-  "Display characters in the range L to H literally."
+  "Display characters representing raw bytes in the range L to H literally.
+
+On a terminal display, each character in the range is displayed
+by sending the corresponding byte directly to the terminal.
+
+On a graphic display, each character in the range is displayed
+using the default font by a glyph whose code is the corresponding
+byte.
+
+Note that ASCII printable characters (SPC to TILDA) are displayed
+in the default way after this call."
   (or standard-display-table
       (setq standard-display-table (make-display-table)))
+  (if (> h 255)
+      (setq h 255))
   (while (<= l h)
-    (aset standard-display-table l (if (or (< l ?\s) (>= l 127)) (vector l)))
+    (if (< l 128)
+       (aset standard-display-table l
+             (if (or (< l ?\s) (= l 127)) (vector l)))
+      (let ((c (unibyte-char-to-multibyte l)))
+       (aset standard-display-table c (vector c))))
     (setq l (1+ l))))
 
 ;;;###autoload
@@ -144,7 +158,7 @@ Valid symbols are `truncation', `wrap', `escape', `control',
   "Display character C as character SC in the g1 character set.
 This function assumes that your terminal uses the SO/SI characters;
 it is meaningless for an X frame."
-  (if (memq window-system '(x w32 mac))
+  (if (memq window-system '(x w32 ns))
       (error "Cannot use string glyphs in a windowing system"))
   (or standard-display-table
       (setq standard-display-table (make-display-table)))
@@ -156,7 +170,7 @@ it is meaningless for an X frame."
   "Display character C as character GC in graphics character set.
 This function assumes VT100-compatible escapes; it is meaningless for an
 X frame."
-  (if (memq window-system '(x w32 mac))
+  (if (memq window-system '(x w32 ns))
       (error "Cannot use string glyphs in a windowing system"))
   (or standard-display-table
       (setq standard-display-table (make-display-table)))
@@ -190,37 +204,39 @@ X frame."
   "Return a glyph code representing char CHAR with face FACE."
   ;; Due to limitations on Emacs integer values, faces with
   ;; face id greater that 512 are silently ignored.
-  (if (and face (<= (face-id face) #x1ff))
-      (logior char (lsh (face-id face) 22))
-    char))
+  (if (not face)
+      char
+    (let ((fid (face-id face)))
+      (if (< fid 64) ; we have 32 - 3(LSB) - 1(SIGN) - 22(CHAR) = 6 bits for face id
+         (logior char (lsh fid 22))
+       (cons char fid)))))
 
 ;;;###autoload
 (defun glyph-char (glyph)
   "Return the character of glyph code GLYPH."
-  (logand glyph #x3fffff))
+  (if (consp glyph)
+      (car glyph)
+    (logand glyph #x3fffff)))
 
 ;;;###autoload
 (defun glyph-face (glyph)
   "Return the face of glyph code GLYPH, or nil if glyph has default face."
-  (let ((face-id (lsh glyph -22)))
+  (let ((face-id (if (consp glyph) (cdr glyph) (lsh glyph -22))))
     (and (> face-id 0)
-        (car (delq nil (mapcar (lambda (face)
-                                 (and (eq (get face 'face) face-id)
-                                      face))
-                               (face-list)))))))
+        (catch 'face
+          (dolist (face (face-list))
+            (when (eq (face-id face) face-id)
+              (throw 'face face)))))))
 
 ;;;###autoload
 (defun standard-display-european (arg)
   "Semi-obsolete way to toggle display of ISO 8859 European characters.
 
-This function is semi-obsolete; if you want to do your editing with
-unibyte characters, it is better to `set-language-environment' coupled
-with either the `--unibyte' option or the EMACS_UNIBYTE environment
-variable, or else customize `enable-multibyte-characters'.
+This function is semi-obsolete; you probably don't need it, or else you
+probably should use `set-language-environment' or `set-locale-environment'.
 
-With prefix argument, this command enables European character display
-if ARG is positive, disables it otherwise.  Otherwise, it toggles
-European character display.
+This function enables European character display if ARG is positive,
+disables it if negative.  Otherwise, it toggles European character display.
 
 When this mode is enabled, characters in the range of 160 to 255
 display not as octal escapes, but as accented characters.  Codes 146
@@ -228,19 +244,21 @@ and 160 display as apostrophe and space, even though they are not the
 ASCII codes for apostrophe and space.
 
 Enabling European character display with this command noninteractively
-from Lisp code also selects Latin-1 as the language environment, and
-selects unibyte mode for all Emacs buffers \(both existing buffers and
-those created subsequently).  This provides increased compatibility
-for users who call this function in `.emacs'."
+from Lisp code also selects Latin-1 as the language environment.
+This provides increased compatibility for users who call this function
+in `.emacs'."
 
   (if (or (<= (prefix-numeric-value arg) 0)
          (and (null arg)
               (char-table-p standard-display-table)
               ;; Test 161, because 160 displays as a space.
-              (equal (aref standard-display-table 161) [161])))
+              (equal (aref standard-display-table
+                           (unibyte-char-to-multibyte 161))
+                     (vector (unibyte-char-to-multibyte 161)))))
       (progn
-       (standard-display-default 160 255)
-       (unless (or (memq window-system '(x w32 mac)))
+       (standard-display-default
+        (unibyte-char-to-multibyte 160) (unibyte-char-to-multibyte 255))
+       (unless (or (memq window-system '(x w32 ns)))
          (and (terminal-coding-system)
               (set-terminal-coding-system nil))))
 
@@ -252,7 +270,7 @@ for users who call this function in `.emacs'."
     ;; unless some other has been specified.
     (if (equal current-language-environment "English")
        (set-language-environment "latin-1"))
-    (unless (or noninteractive (memq window-system '(x w32 mac)))
+    (unless (or noninteractive (memq window-system '(x w32 ns)))
       ;; Send those codes literally to a character-based terminal.
       ;; If we are using single-byte characters,
       ;; it doesn't matter which coding system we use.
@@ -263,5 +281,4 @@ for users who call this function in `.emacs'."
 
 (provide 'disp-table)
 
-;; arch-tag: ffe4c28c-960c-47aa-b8a8-ae89d371ffc7
 ;;; disp-table.el ends here