Fix up comment convention on the arch-tag lines.
[bpt/emacs.git] / lisp / emacs-lisp / lucid.el
index eaa405a..7684c9f 100644 (file)
@@ -1,11 +1,16 @@
-;;; lucid.el --- Emulate some Lucid Emacs functions.
-;; Copyright (C) 1993 Free Software Foundation, Inc.
+;;; lucid.el --- emulate some Lucid Emacs functions
+
+;; Copyright (C) 1993, 1995, 2001, 2002, 2003, 2004,
+;;   2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+
+;; Maintainer: FSF
+;; Keywords: emulations
 
 ;; This file is part of GNU Emacs.
 
 ;; 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 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
 ;; 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, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; 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.
 
+;;; Commentary:
 
-(defun add-timeout (secs function object &optional resignal)
-  (run-at-time secs resignal function object))
+;;; Code:
 
-(defun disable-timeout (timeout)
-  (cancel-timer timeout))
-
-(defun copy-tree (tree)
-  (if (consp tree)
-      (cons (copy-tree (car tree))
-           (copy-tree (cdr tree)))
-    (if (vectorp tree)
-       (let* ((new (copy-sequence tree))
-              (i (1- (length new))))
-         (while (>= i 0)
-           (aset new i (copy-tree (aref new i)))
-           (setq i (1- i)))
-         new)
-      tree)))
+;; XEmacs autoloads CL so we might as well make use of it.
+(require 'cl)
 
 (defalias 'current-time-seconds 'current-time)
 
-(defun keymap-parent (keymap)
-  (let ((tail (cdr keymap)))
-    (while (and tail (not (eq (car tail) 'keymap)))
-      (setq tail (cdr tail)))
-    tail))
-
-(defun set-keymap-parent (keymap new-parent)
-  (let ((tail (cdr keymap)))
-    (while (and tail (cdr tail) (not (eq (car (cdr tail)) 'keymap)))
-      (setq tail (cdr tail)))
-    (if tail
-       (setcdr tail new-parent))))
-
-(defun remove-hook (hook-var function)
-  "Remove a function from a hook, if it is present.
-First argument HOOK-VAR (a symbol) is the name of a hook, second
- argument FUNCTION is the function to remove (compared with `eq')."
-  (if (boundp 'hook-var)
-      (let ((old (symbol-value hook-var)))
-       ;; If the hook value is a single function, turn it into a list.
-       (if (or (not (listp old)) (eq (car old) 'lambda))
-           (set hook-var (list old)))
-       ;; Now delete FUNCTION.
-       (set hook-var (delq function (symbol-value hook-var))))))
-
-(defun remprop (symbol prop)
-  (let ((plist (symbol-plist symbol)))
-    (while (eq (car plist) prop)
-      (setplist symbol (setq plist (cdr (cdr plist)))))
-    (while plist
-      (if (eq (nth 2 plist) prop)
-         (setcdr (cdr plist) (nthcdr 4 plist)))
-      (setq plist (cdr (cdr plist))))))
-
-(defun map-keymap (function keymap &optional sort-first)
-  "Call FUNCTION for every binding in KEYMAP.
-This includes bindings inherited from a parent keymap.
-FUNCTION receives two arguments each time it is called:
-the character (more generally, the event type) that is bound,
-and the binding it has.
-
-Note that passing the event type directly to `define-key' does not work
-in Emacs 19.  We do not emulate that particular feature of Lucid Emacs.
-If your code does that, modify it to make a vector containing the event
-type that you get.  That will work in both versions of Emacs."
-  (if sort-first
-      (let (list)
-       (map-keymap (function (lambda (a b)
-                               (setq list (cons (cons a b) list))))
-                   keymap)
-       (setq list (sort list
-                        (function (lambda (a b)
-                                    (setq a (car a) b (car b))
-                                    (if (integerp a)
-                                        (if (integerp b) (< a b)
-                                          t)
-                                      (if (integerp b) t
-                                        (string< a b)))))))
-       (while list
-         (funcall function (car (car list)) (cdr (car list)))
-         (setq list (cdr list))))
-    (while (consp keymap)
-      (if (consp (car keymap))
-         (funcall function (car (car keymap)) (cdr (car keymap)))
-       (if (vectorp (car keymap))
-           (let ((i (1- (length (car keymap))))
-                 (vector (car keymap)))
-             (while (>= i 0)
-               (funcall function i (aref vector i))
-               (setq i (1- i))))))
-      (setq keymap (cdr keymap)))))
+(defun read-number (prompt &optional integers-only)
+  "Read a number from the minibuffer.
+Keep reentering the minibuffer until we get suitable input.
+If optional argument INTEGERS-ONLY is non-nil, insist on an integer."
+  (interactive)
+  (let (success
+       (number nil)
+       (predicate (if integers-only 'integerp 'numberp)))
+    (while (not success)
+      (let ((input-string (read-string prompt)))
+       (condition-case ()
+           (setq number (read input-string))
+         (error))
+       (if (funcall predicate number)
+           (setq success t)
+         (let ((cursor-in-echo-area t))
+           (message "Please type %s"
+                    (if integers-only "an integer" "a number"))
+           (sit-for 1)))))
+    number))
 
 (defun real-path-name (name &optional default)
   (file-truename (expand-file-name name default)))
@@ -130,7 +72,7 @@ bottom of the buffer stack."
       (bury-buffer (current-buffer)))
   (switch-to-buffer
    (if (<= arg 1) (other-buffer (current-buffer))
-     (nth (1+ arg)
+     (nth arg
          (apply 'nconc
                 (mapcar
                  (lambda (buf)
@@ -139,9 +81,108 @@ bottom of the buffer stack."
                      (list buf)))
                  (buffer-list)))))))
 
+(defun device-class (&optional device)
+  "Return the class (color behavior) of DEVICE.
+This will be one of 'color, 'grayscale, or 'mono.
+This function exists for compatibility with XEmacs."
+  (cond
+   ((display-color-p device) 'color)
+   ((display-grayscale-p device) 'grayscale)
+   (t 'mono)))
+
 (defalias 'find-face 'internal-find-face)
 (defalias 'get-face 'internal-get-face)
 (defalias 'try-face-font 'internal-try-face-font)
+
+(defalias 'exec-to-string 'shell-command-to-string)
+\f
+
+;; Buffer context
+
+(defun buffer-syntactic-context (&optional buffer)
+  "Syntactic context at point in BUFFER.
+Either of `string', `comment' or nil.
+This is an XEmacs compatibility function."
+  (with-current-buffer (or buffer (current-buffer))
+    (let ((state (syntax-ppss (point))))
+      (cond
+       ((nth 3 state) 'string)
+       ((nth 4 state) 'comment)))))
+
+
+(defun buffer-syntactic-context-depth (&optional buffer)
+  "Syntactic parenthesis depth at point in BUFFER.
+This is an XEmacs compatibility function."
+  (with-current-buffer (or buffer (current-buffer))
+    (nth 0 (syntax-ppss (point)))))
+
+
+;; Extents
+(defun make-extent (beg end &optional buffer)
+  (make-overlay beg end buffer))
+
+(defun extent-properties (extent) (overlay-properties extent))
+(unless (fboundp 'extent-property) (defalias 'extent-property 'overlay-get))
+
+(defun extent-at (pos &optional object property before)
+  (with-current-buffer (or object (current-buffer))
+    (let ((overlays (overlays-at pos)))
+      (when property
+       (let (filtered)
+         (while overlays
+           (if (overlay-get (car overlays) property)
+               (setq filtered (cons (car overlays) filtered)))
+           (setq overlays (cdr overlays)))
+         (setq overlays filtered)))
+      (setq overlays
+           (sort overlays
+                 (function (lambda (o1 o2)
+                             (let ((p1 (or (overlay-get o1 'priority) 0))
+                                   (p2 (or (overlay-get o2 'priority) 0)))
+                               (or (> p1 p2)
+                                   (and (= p1 p2)
+                                        (> (overlay-start o1) (overlay-start o2)))))))))
+      (if before
+         (nth 1 (memq before overlays))
+       (car overlays)))))
+
+(defun set-extent-property (extent prop value)
+  ;; Make sure that separate adjacent extents
+  ;; with the same mouse-face value
+  ;; do not run together as one extent.
+  (and (eq prop 'mouse-face)
+       (symbolp value)
+       (setq value (list value)))
+  (if (eq prop 'duplicable)
+      (cond ((and value (not (overlay-get extent prop)))
+            ;; If becoming duplicable, copy all overlayprops to text props.
+            (add-text-properties (overlay-start extent)
+                                 (overlay-end extent)
+                                 (overlay-properties extent)
+                                 (overlay-buffer extent)))
+           ;; If becoming no longer duplicable, remove these text props.
+           ((and (not value) (overlay-get extent prop))
+            (remove-text-properties (overlay-start extent)
+                                    (overlay-end extent)
+                                    (overlay-properties extent)
+                                    (overlay-buffer extent))))
+    ;; If extent is already duplicable, put this property
+    ;; on the text as well as on the overlay.
+    (if (overlay-get extent 'duplicable)
+       (put-text-property  (overlay-start extent)
+                           (overlay-end extent)
+                           prop value (overlay-buffer extent))))
+  (overlay-put extent prop value))
+
+(defun set-extent-face (extent face)
+  (set-extent-property extent 'face face))
+
+(defun set-extent-end-glyph (extent glyph)
+  (set-extent-property extent 'after-string glyph))
+
+(defun delete-extent (extent)
+  (set-extent-property extent 'duplicable nil)
+  (delete-overlay extent))
 \f
 ;; Support the Lucid names with `screen' instead of `frame'.
 
@@ -166,7 +207,6 @@ bottom of the buffer stack."
 ;; (defalias 'screen-char-width 'frame-char-width)
 ;; (defalias 'screen-configuration-to-register 'frame-configuration-to-register)
 ;; (defalias 'screen-focus 'frame-focus)
-(defalias 'screen-height 'frame-height)
 (defalias 'screen-list 'frame-list)
 ;; (defalias 'screen-live-p 'frame-live-p)
 (defalias 'screen-parameters 'frame-parameters)
@@ -177,7 +217,6 @@ bottom of the buffer stack."
 (defalias 'lower-screen 'lower-frame)
 (defalias 'raise-screen 'raise-frame)
 (defalias 'screen-visible-p 'frame-visible-p)
-(defalias 'screen-width 'frame-width)
 (defalias 'screenp 'framep)
 (defalias 'select-screen 'select-frame)
 (defalias 'selected-screen 'selected-frame)
@@ -191,8 +230,9 @@ bottom of the buffer stack."
 (defalias 'visible-screen-list 'visible-frame-list)
 (defalias 'window-screen 'window-frame)
 (defalias 'x-create-screen 'x-create-frame)
-(defalias 'x-new-screen 'new-frame)
+(defalias 'x-new-screen 'make-frame)
 
 (provide 'lucid)
 
-;;; end of lucid.el
+;; arch-tag: 80f9ab46-0b36-4151-86ed-3edb6d449c9e
+;;; lucid.el ends here