]> code.delx.au - gnu-emacs/blobdiff - lisp/enriched.el
(Fbuffer_substring): Doc fix.
[gnu-emacs] / lisp / enriched.el
index 362a537d846001f5af466b00c9e94b1707af5ec5..8f4bf4f0392d6a72efed535e11ad22d0a12a23ad 100644 (file)
@@ -2,7 +2,7 @@
 
 ;; Copyright (c) 1994, 1995, 1996 Free Software Foundation, Inc.
 
-;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu>
+;; Author: Boris Goldowsky <boris@gnu.org>
 ;; Keywords: wp, faces
 
 ;; This file is part of GNU Emacs.
 ;;; Variables controlling the display
 ;;;
 
-(defvar enriched-verbose t
-  "*If non-nil, give status messages when reading and writing files.")
+(defgroup enriched nil
+  "Read and save files in text/enriched format"
+  :group 'wp)
+
+(defcustom enriched-verbose t
+  "*If non-nil, give status messages when reading and writing files."
+  :type 'boolean
+  :group 'enriched)
 
 ;;;
 ;;; Set up faces & display table
 ;;;
 
-;; A slight cheat - all emacs's faces are fixed-width.  
-;; The idea is just to pick one that looks different from the default.
-(if (internal-find-face 'fixed)
-    nil
-  (make-face 'fixed)
-  (if window-system
-      (set-face-font 'fixed
-                    (car (or (x-list-fonts "*fixed-medium*" 
-                                           'default (selected-frame))
-                             (x-list-fonts "*fixed*" 
-                                           'default (selected-frame)))))))
-                             
-(if (internal-find-face 'excerpt)
-    nil
-  (make-face 'excerpt)
-  (if window-system
-      (make-face-italic 'excerpt nil t)))
+;; Emacs doesn't have a "fixed" face by default, since all faces currently
+;; have to be fixed-width.  So we just pick one that looks different from the
+;; default.
+(defface fixed
+  '((t (:bold t)))
+  "Face used for text that must be shown in fixed width.
+Currently, emacs can only display fixed-width fonts, but this may change.
+This face is used for text specifically marked as fixed-width, for example
+in text/enriched files."
+  :group 'enriched)
+
+(defface excerpt
+  '((t (:italic t)))
+  "Face used for text that is an excerpt from another document.
+This is used in enriched-mode for text explicitly marked as an excerpt."
+  :group 'enriched)
 
 (defconst enriched-display-table (or (copy-sequence standard-display-table)
                                     (make-display-table)))
@@ -94,7 +99,7 @@ expression, which is evaluated to get the string to insert.")
 (defconst enriched-annotation-format "<%s%s>"
   "General format of enriched-text annotations.")
 
-(defconst enriched-annotation-regexp "<\\(/\\)?\\([-A-za-z0-9]+\\)>"
+(defconst enriched-annotation-regexp "<\\(/\\)?\\([-A-Za-z0-9]+\\)>"
   "Regular expression matching enriched-text annotations.")
 
 (defconst enriched-translations
@@ -116,8 +121,10 @@ expression, which is evaluated to get the string to insert.")
     (PARAMETER     (t           "param")) ; Argument of preceding annotation
     ;; The following are not part of the standard:
     (FUNCTION      (enriched-decode-foreground "x-color")
-                  (enriched-decode-background "x-bg-color"))
+                  (enriched-decode-background "x-bg-color")
+                  (enriched-decode-display-prop "x-display"))
     (read-only     (t           "x-read-only"))
+    (display      (nil         enriched-handle-display-prop))
     (unknown       (nil         format-annotate-value))
 ;   (font-size     (2           "bigger")       ; unimplemented
 ;                 (-2          "smaller"))
@@ -137,17 +144,20 @@ Any property that is neither on this list nor dealt with by
 (defvar enriched-mode nil
   "True if Enriched mode is in use.")
 (make-variable-buffer-local 'enriched-mode)
+(put 'enriched-mode 'permanent-local t)
 
 (if (not (assq 'enriched-mode minor-mode-alist))
     (setq minor-mode-alist
          (cons '(enriched-mode " Enriched")
                minor-mode-alist)))
 
-(defvar enriched-mode-hook nil
+(defcustom enriched-mode-hook nil
   "Functions to run when entering Enriched mode.
 If you set variables in this hook, you should arrange for them to be restored
 to their old values if you leave Enriched mode.  One way to do this is to add
-them and their old values to `enriched-old-bindings'.")
+them and their old values to `enriched-old-bindings'."
+  :type 'hook
+  :group 'enriched)
 
 (defvar enriched-old-bindings nil
   "Store old variable values that we change when entering mode.
@@ -338,17 +348,23 @@ One annotation each for foreground color, background color, italic, etc."
            
 (defun enriched-face-ans (face)
   "Return annotations specifying FACE."
-  (cond ((string-match "^fg:" (symbol-name face))
+  (cond ((and (consp face) (eq (car face) 'foreground-color))
+        (list (list "x-color" (cdr face))))
+       ((and (consp face) (eq (car face) 'background-color))
+        (list (list "x-bg-color" (cdr face))))
+       ((string-match "^fg:" (symbol-name face))
         (list (list "x-color" (substring (symbol-name face) 3))))
        ((string-match "^bg:" (symbol-name face))
         (list (list "x-bg-color" (substring (symbol-name face) 3))))
-       ((let* ((fg (face-foreground face))
-               (bg (face-background face))
+       ((let* ((fg (face-attribute face :foreground))
+               (bg (face-attribute face :background))
                (props (face-font face t))
                (ans (cdr (format-annotate-single-property-change
                           'face nil props enriched-translations))))
-          (if fg (setq ans (cons (list "x-color" fg) ans)))
-          (if bg (setq ans (cons (list "x-bg-color" bg) ans)))
+          (unless (eq fg 'unspecified)
+            (setq ans (cons (list "x-color" fg) ans)))
+          (unless (eq bg 'unspecified)
+            (setq ans (cons (list "x-bg-color" bg) ans)))
           ans))))
 
 ;;;
@@ -424,24 +440,57 @@ Return value is \(begin end name positive-p), or nil if none was found."
   (if (looking-at "^\n")
       (delete-char 1)))
 
-(defun enriched-decode-foreground (from to color)
+(defun enriched-decode-foreground (from to &optional color)
   (let ((face (intern (concat "fg:" color))))
-    (cond ((internal-find-face face))
-         ((and window-system (facemenu-get-face face)))
-         (window-system
-          (message "Warning: color \"%s\" is not defined." color))
+    (cond ((null color)
+          (message "Warning: no color specified for <x-color>"))
+         ((facep face))
+         ((and (display-color-p) (facemenu-get-face face)))
          ((make-face face)
-          (message "Warning: Color \"%s\" can't be displayed." color)))
+          (message "Warning: color `%s' can't be displayed" color)))
     (list from to 'face face)))
 
-(defun enriched-decode-background (from to color)
+(defun enriched-decode-background (from to &optional color)
   (let ((face (intern (concat "bg:" color))))
-    (cond ((internal-find-face face))
-         ((and window-system (facemenu-get-face face)))
-         (window-system
-          (message "Warning: color \"%s\" is not defined." color))
+    (cond ((null color)
+          (message "Warning: no color specified for <x-bg-color>"))
+         ((facep face))
+         ((and (display-color-p) (facemenu-get-face face)))
          ((make-face face)
-          (message "Warning: Color \"%s\" can't be displayed." color)))
+          (message "Warning: color `%s' can't be displayed" color)))
     (list from to 'face face)))
 
+
+\f
+;;; Handling the `display' property.
+
+
+(defun enriched-handle-display-prop (old new)
+  "Return a list of annotations for a change in the `display' property.
+OLD is the old value of the property, NEW is the new value.  Value
+is a list `(CLOSE OPEN)', where CLOSE is a list of annotations to
+close and OPEN a list of annotations to open.  Each of these lists
+has the form `(ANNOTATION PARAM ...)'."
+  (let ((annotation "x-display")
+       (param (prin1-to-string (or old new)))
+       close open)
+    (if (null old)
+       (list nil (list annotation param))
+      (list (list annotation param)))))
+
+
+(defun enriched-decode-display-prop (start end &optional param)
+  "Decode a `display' property for text between START and END.
+PARAM is a `<param>' found for the property.
+Value is a list `(START END SYMBOL VALUE)' with START and END denoting
+the range of text to assign text property SYMBOL with value VALUE "
+  (let ((prop (when (stringp param)
+               (condition-case ()
+                   (car (read-from-string param))
+                 (error nil)))))
+    (unless prop
+      (message "Warning: invalid <x-display> parameter %s" param))
+    (list start end 'display prop)))
+              
+          
 ;;; enriched.el ends here