* bookmark.el (bookmark-alist): Allow the 2 slightly different formats
[emacs.git] / lisp / emacs-lisp / lucid.el
blobb46107e7fc39806b095061233ef9418091d7483e
1 ;;; lucid.el --- emulate some Lucid Emacs functions
3 ;; Copyright (C) 1993, 1995, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: emulations
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
24 ;;; Commentary:
26 ;;; Code:
28 ;; XEmacs autoloads CL so we might as well make use of it.
29 (require 'cl)
31 (defalias 'current-time-seconds 'current-time)
33 (defun read-number (prompt &optional integers-only)
34 "Read a number from the minibuffer.
35 Keep reentering the minibuffer until we get suitable input.
36 If optional argument INTEGERS-ONLY is non-nil, insist on an integer."
37 (interactive)
38 (let (success
39 (number nil)
40 (predicate (if integers-only 'integerp 'numberp)))
41 (while (not success)
42 (let ((input-string (read-string prompt)))
43 (condition-case ()
44 (setq number (read input-string))
45 (error))
46 (if (funcall predicate number)
47 (setq success t)
48 (let ((cursor-in-echo-area t))
49 (message "Please type %s"
50 (if integers-only "an integer" "a number"))
51 (sit-for 1)))))
52 number))
54 (defun real-path-name (name &optional default)
55 (file-truename (expand-file-name name default)))
57 ;; It's not clear what to return if the mouse is not in FRAME.
58 (defun read-mouse-position (frame)
59 (let ((pos (mouse-position)))
60 (if (eq (car pos) frame)
61 (cdr pos))))
63 (defun switch-to-other-buffer (arg)
64 "Switch to the previous buffer.
65 With a numeric arg N, switch to the Nth most recent buffer.
66 With an arg of 0, buries the current buffer at the
67 bottom of the buffer stack."
68 (interactive "p")
69 (if (eq arg 0)
70 (bury-buffer (current-buffer)))
71 (switch-to-buffer
72 (if (<= arg 1) (other-buffer (current-buffer))
73 (nth arg
74 (apply 'nconc
75 (mapcar
76 (lambda (buf)
77 (if (= ?\ (string-to-char (buffer-name buf)))
78 nil
79 (list buf)))
80 (buffer-list)))))))
82 (defun device-class (&optional device)
83 "Return the class (color behavior) of DEVICE.
84 This will be one of 'color, 'grayscale, or 'mono.
85 This function exists for compatibility with XEmacs."
86 (cond
87 ((display-color-p device) 'color)
88 ((display-grayscale-p device) 'grayscale)
89 (t 'mono)))
91 (defalias 'find-face 'internal-find-face)
92 (defalias 'get-face 'internal-get-face)
93 (defalias 'try-face-font 'internal-try-face-font)
95 (defalias 'exec-to-string 'shell-command-to-string)
98 ;; Buffer context
100 (defun buffer-syntactic-context (&optional buffer)
101 "Syntactic context at point in BUFFER.
102 Either of `string', `comment' or nil.
103 This is an XEmacs compatibility function."
104 (with-current-buffer (or buffer (current-buffer))
105 (let ((state (syntax-ppss (point))))
106 (cond
107 ((nth 3 state) 'string)
108 ((nth 4 state) 'comment)))))
111 (defun buffer-syntactic-context-depth (&optional buffer)
112 "Syntactic parenthesis depth at point in BUFFER.
113 This is an XEmacs compatibility function."
114 (with-current-buffer (or buffer (current-buffer))
115 (nth 0 (syntax-ppss (point)))))
118 ;; Extents
119 (defun make-extent (beg end &optional buffer)
120 (make-overlay beg end buffer))
122 (defun extent-properties (extent) (overlay-properties extent))
123 (unless (fboundp 'extent-property) (defalias 'extent-property 'overlay-get))
125 (defun extent-at (pos &optional object property before)
126 (with-current-buffer (or object (current-buffer))
127 (let ((overlays (overlays-at pos)))
128 (when property
129 (let (filtered)
130 (while overlays
131 (if (overlay-get (car overlays) property)
132 (setq filtered (cons (car overlays) filtered)))
133 (setq overlays (cdr overlays)))
134 (setq overlays filtered)))
135 (setq overlays
136 (sort overlays
137 (function (lambda (o1 o2)
138 (let ((p1 (or (overlay-get o1 'priority) 0))
139 (p2 (or (overlay-get o2 'priority) 0)))
140 (or (> p1 p2)
141 (and (= p1 p2)
142 (> (overlay-start o1) (overlay-start o2)))))))))
143 (if before
144 (nth 1 (memq before overlays))
145 (car overlays)))))
147 (defun set-extent-property (extent prop value)
148 ;; Make sure that separate adjacent extents
149 ;; with the same mouse-face value
150 ;; do not run together as one extent.
151 (and (eq prop 'mouse-face)
152 (symbolp value)
153 (setq value (list value)))
154 (if (eq prop 'duplicable)
155 (cond ((and value (not (overlay-get extent prop)))
156 ;; If becoming duplicable, copy all overlayprops to text props.
157 (add-text-properties (overlay-start extent)
158 (overlay-end extent)
159 (overlay-properties extent)
160 (overlay-buffer extent)))
161 ;; If becoming no longer duplicable, remove these text props.
162 ((and (not value) (overlay-get extent prop))
163 (remove-text-properties (overlay-start extent)
164 (overlay-end extent)
165 (overlay-properties extent)
166 (overlay-buffer extent))))
167 ;; If extent is already duplicable, put this property
168 ;; on the text as well as on the overlay.
169 (if (overlay-get extent 'duplicable)
170 (put-text-property (overlay-start extent)
171 (overlay-end extent)
172 prop value (overlay-buffer extent))))
173 (overlay-put extent prop value))
175 (defun set-extent-face (extent face)
176 (set-extent-property extent 'face face))
178 (defun set-extent-end-glyph (extent glyph)
179 (set-extent-property extent 'after-string glyph))
181 (defun delete-extent (extent)
182 (set-extent-property extent 'duplicable nil)
183 (delete-overlay extent))
185 ;; Support the Lucid names with `screen' instead of `frame'.
187 (defalias 'current-screen-configuration 'current-frame-configuration)
188 (defalias 'delete-screen 'delete-frame)
189 (defalias 'find-file-new-screen 'find-file-other-frame)
190 (defalias 'find-file-read-only-new-screen 'find-file-read-only-other-frame)
191 (defalias 'find-tag-new-screen 'find-tag-other-frame)
192 ;;(defalias 'focus-screen 'focus-frame)
193 (defalias 'iconify-screen 'iconify-frame)
194 (defalias 'mail-new-screen 'mail-other-frame)
195 (defalias 'make-screen-invisible 'make-frame-invisible)
196 (defalias 'make-screen-visible 'make-frame-visible)
197 ;; (defalias 'minibuffer-screen-list 'minibuffer-frame-list)
198 (defalias 'modify-screen-parameters 'modify-frame-parameters)
199 (defalias 'next-screen 'next-frame)
200 ;; (defalias 'next-multiscreen-window 'next-multiframe-window)
201 ;; (defalias 'previous-multiscreen-window 'previous-multiframe-window)
202 ;; (defalias 'redirect-screen-focus 'redirect-frame-focus)
203 (defalias 'redraw-screen 'redraw-frame)
204 ;; (defalias 'screen-char-height 'frame-char-height)
205 ;; (defalias 'screen-char-width 'frame-char-width)
206 ;; (defalias 'screen-configuration-to-register 'frame-configuration-to-register)
207 ;; (defalias 'screen-focus 'frame-focus)
208 (defalias 'screen-list 'frame-list)
209 ;; (defalias 'screen-live-p 'frame-live-p)
210 (defalias 'screen-parameters 'frame-parameters)
211 (defalias 'screen-pixel-height 'frame-pixel-height)
212 (defalias 'screen-pixel-width 'frame-pixel-width)
213 (defalias 'screen-root-window 'frame-root-window)
214 (defalias 'screen-selected-window 'frame-selected-window)
215 (defalias 'lower-screen 'lower-frame)
216 (defalias 'raise-screen 'raise-frame)
217 (defalias 'screen-visible-p 'frame-visible-p)
218 (defalias 'screenp 'framep)
219 (defalias 'select-screen 'select-frame)
220 (defalias 'selected-screen 'selected-frame)
221 ;; (defalias 'set-screen-configuration 'set-frame-configuration)
222 ;; (defalias 'set-screen-height 'set-frame-height)
223 (defalias 'set-screen-position 'set-frame-position)
224 (defalias 'set-screen-size 'set-frame-size)
225 ;; (defalias 'set-screen-width 'set-frame-width)
226 (defalias 'switch-to-buffer-new-screen 'switch-to-buffer-other-frame)
227 ;; (defalias 'unfocus-screen 'unfocus-frame)
228 (defalias 'visible-screen-list 'visible-frame-list)
229 (defalias 'window-screen 'window-frame)
230 (defalias 'x-create-screen 'x-create-frame)
231 (defalias 'x-new-screen 'make-frame)
233 (provide 'lucid)
235 ;; arch-tag: 80f9ab46-0b36-4151-86ed-3edb6d449c9e
236 ;;; lucid.el ends here