Sync to HEAD
[bpt/emacs.git] / lisp / emacs-lisp / lucid.el
CommitLineData
60370d40 1;;; lucid.el --- emulate some Lucid Emacs functions
b578f267 2
284b3043 3;; Copyright (C) 1993, 1995, 2001 Free Software Foundation, Inc.
6de6752c 4
070c251e 5;; Maintainer: FSF
284b3043 6;; Keywords: emulations
070c251e 7
6de6752c
RS
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
b578f267
EN
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
6de6752c 24
60370d40
PJ
25;;; Commentary:
26
b578f267 27;;; Code:
6de6752c 28
5e2dfaa4
SM
29;; XEmacs autoloads CL so we might as well make use of it.
30(require 'cl)
330fba95 31
31e1d920 32(defalias 'current-time-seconds 'current-time)
330fba95 33
0d7a020a
SM
34;; In case cl-map-keymap is an alias for map-keymap, avoid circular calls.
35(fset 'cl-map-keymap (indirect-function 'cl-map-keymap))
36
7d18d35c 37(defun map-keymap (function keymap &optional sort-first)
3e6580d0 38 "Call FUNCTION for every binding in KEYMAP.
5e2dfaa4 39This does not include bindings inherited from a parent keymap.
3e6580d0
JB
40FUNCTION receives two arguments each time it is called:
41the character (more generally, the event type) that is bound,
aef4422e
RS
42and the binding it has.
43
44Note that passing the event type directly to `define-key' does not work
45in Emacs 19. We do not emulate that particular feature of Lucid Emacs.
46If your code does that, modify it to make a vector containing the event
47type that you get. That will work in both versions of Emacs."
7d18d35c
JB
48 (if sort-first
49 (let (list)
5e2dfaa4
SM
50 (cl-map-keymap (lambda (a b) (push (cons a b) list))
51 keymap)
7d18d35c 52 (setq list (sort list
5e2dfaa4
SM
53 (lambda (a b)
54 (setq a (car a) b (car b))
55 (if (integerp a)
56 (if (integerp b) (< a b)
57 t)
58 (if (integerp b) t
59 (string< a b))))))
60 (dolist (p list)
61 (funcall function (car p) (cdr p))))
62 (cl-map-keymap function keymap)))
7d18d35c 63
3b787dc3
RS
64(defun read-number (prompt &optional integers-only)
65 "Read a number from the minibuffer.
66Keep reentering the minibuffer until we get suitable input.
67If optional argument INTEGERS-ONLY is non-nil, insist on an integer."
68 (interactive)
69 (let (success
70 (number nil)
71 (predicate (if integers-only 'integerp 'numberp)))
72 (while (not success)
73 (let ((input-string (read-string prompt)))
74 (condition-case ()
75 (setq number (read input-string))
76 (error))
77 (if (funcall predicate number)
78 (setq success t)
79 (let ((cursor-in-echo-area t))
80 (message "Please type %s"
81 (if integers-only "an integer" "a number"))
82 (sit-for 1)))))
83 number))
84
7d18d35c
JB
85(defun real-path-name (name &optional default)
86 (file-truename (expand-file-name name default)))
87
88;; It's not clear what to return if the mouse is not in FRAME.
89(defun read-mouse-position (frame)
90 (let ((pos (mouse-position)))
91 (if (eq (car pos) frame)
92 (cdr pos))))
93
94(defun switch-to-other-buffer (arg)
95 "Switch to the previous buffer.
96With a numeric arg N, switch to the Nth most recent buffer.
97With an arg of 0, buries the current buffer at the
98bottom of the buffer stack."
99 (interactive "p")
100 (if (eq arg 0)
101 (bury-buffer (current-buffer)))
102 (switch-to-buffer
103 (if (<= arg 1) (other-buffer (current-buffer))
7c7daa22 104 (nth arg
e084483d
JB
105 (apply 'nconc
106 (mapcar
107 (lambda (buf)
0b9be2e7 108 (if (= ?\ (string-to-char (buffer-name buf)))
e084483d 109 nil
0b9be2e7
JB
110 (list buf)))
111 (buffer-list)))))))
e15765f5 112
efcc2791
SM
113(defun device-class (&optional device)
114 "Return the class (color behavior) of DEVICE.
115This will be one of 'color, 'grayscale, or 'mono.
116This function exists for compatibility with XEmacs."
117 (cond
118 ((display-color-p device) 'color)
119 ((display-grayscale-p device) 'grayscale)
120 (t 'mono)))
121
31e1d920
ER
122(defalias 'find-face 'internal-find-face)
123(defalias 'get-face 'internal-get-face)
124(defalias 'try-face-font 'internal-try-face-font)
6b4268b0
RS
125
126(defalias 'exec-to-string 'shell-command-to-string)
7d18d35c 127\f
efcc2791
SM
128
129;; Buffer context
130
131(defun buffer-syntactic-context (&optional buffer)
132 "Syntactic context at point in BUFFER.
89a5038d 133Either of `string', `comment' or nil.
efcc2791
SM
134This is an XEmacs compatibility function."
135 (with-current-buffer (or buffer (current-buffer))
136 (let ((state (syntax-ppss (point))))
137 (cond
138 ((nth 3 state) 'string)
139 ((nth 4 state) 'comment)))))
140
141
142(defun buffer-syntactic-context-depth (&optional buffer)
143 "Syntactic parenthesis depth at point in BUFFER.
144This is an XEmacs compatibility function."
145 (with-current-buffer (or buffer (current-buffer))
146 (nth 0 (syntax-ppss (point)))))
147
148
149;; Extents
51566783
RS
150(defun make-extent (beg end &optional buffer)
151 (make-overlay beg end buffer))
152
5e2dfaa4
SM
153(defun extent-properties (extent) (overlay-properties extent))
154(unless (fboundp 'extent-property) (defalias 'extent-property 'overlay-get))
c9411d2f
RS
155
156(defun extent-at (pos &optional object property before)
157 (with-current-buffer (or object (current-buffer))
158 (let ((overlays (overlays-at pos)))
159 (when property
160 (let (filtered)
161 (while overlays
162 (if (overlay-get (car overlays) property)
163 (setq filtered (cons (car overlays) filtered)))
164 (setq overlays (cdr overlays)))
165 (setq overlays filtered)))
166 (setq overlays
167 (sort overlays
168 (function (lambda (o1 o2)
169 (let ((p1 (or (overlay-get o1 'priority) 0))
170 (p2 (or (overlay-get o2 'priority) 0)))
171 (or (> p1 p2)
172 (and (= p1 p2)
173 (> (overlay-start o1) (overlay-start o2)))))))))
174 (if before
175 (nth 1 (memq before overlays))
176 (car overlays)))))
177
51566783 178(defun set-extent-property (extent prop value)
c27d895b
RS
179 ;; Make sure that separate adjacent extents
180 ;; with the same mouse-face value
181 ;; do not run together as one extent.
182 (and (eq prop 'mouse-face)
183 (symbolp value)
184 (setq value (list value)))
51566783
RS
185 (if (eq prop 'duplicable)
186 (cond ((and value (not (overlay-get extent prop)))
187 ;; If becoming duplicable, copy all overlayprops to text props.
188 (add-text-properties (overlay-start extent)
189 (overlay-end extent)
190 (overlay-properties extent)
191 (overlay-buffer extent)))
192 ;; If becoming no longer duplicable, remove these text props.
193 ((and (not value) (overlay-get extent prop))
194 (remove-text-properties (overlay-start extent)
195 (overlay-end extent)
196 (overlay-properties extent)
197 (overlay-buffer extent))))
198 ;; If extent is already duplicable, put this property
199 ;; on the text as well as on the overlay.
200 (if (overlay-get extent 'duplicable)
201 (put-text-property (overlay-start extent)
202 (overlay-end extent)
203 prop value (overlay-buffer extent))))
204 (overlay-put extent prop value))
205
206(defun set-extent-face (extent face)
207 (set-extent-property extent 'face face))
208
5e2dfaa4
SM
209(defun set-extent-end-glyph (extent glyph)
210 (set-extent-property extent 'after-string glyph))
211
51566783
RS
212(defun delete-extent (extent)
213 (set-extent-property extent 'duplicable nil)
214 (delete-overlay extent))
215\f
7d18d35c
JB
216;; Support the Lucid names with `screen' instead of `frame'.
217
31e1d920
ER
218(defalias 'current-screen-configuration 'current-frame-configuration)
219(defalias 'delete-screen 'delete-frame)
220(defalias 'find-file-new-screen 'find-file-other-frame)
221(defalias 'find-file-read-only-new-screen 'find-file-read-only-other-frame)
222(defalias 'find-tag-new-screen 'find-tag-other-frame)
223;;(defalias 'focus-screen 'focus-frame)
224(defalias 'iconify-screen 'iconify-frame)
225(defalias 'mail-new-screen 'mail-other-frame)
226(defalias 'make-screen-invisible 'make-frame-invisible)
227(defalias 'make-screen-visible 'make-frame-visible)
228;; (defalias 'minibuffer-screen-list 'minibuffer-frame-list)
229(defalias 'modify-screen-parameters 'modify-frame-parameters)
230(defalias 'next-screen 'next-frame)
231;; (defalias 'next-multiscreen-window 'next-multiframe-window)
232;; (defalias 'previous-multiscreen-window 'previous-multiframe-window)
233;; (defalias 'redirect-screen-focus 'redirect-frame-focus)
234(defalias 'redraw-screen 'redraw-frame)
235;; (defalias 'screen-char-height 'frame-char-height)
236;; (defalias 'screen-char-width 'frame-char-width)
237;; (defalias 'screen-configuration-to-register 'frame-configuration-to-register)
238;; (defalias 'screen-focus 'frame-focus)
31e1d920
ER
239(defalias 'screen-list 'frame-list)
240;; (defalias 'screen-live-p 'frame-live-p)
241(defalias 'screen-parameters 'frame-parameters)
242(defalias 'screen-pixel-height 'frame-pixel-height)
243(defalias 'screen-pixel-width 'frame-pixel-width)
244(defalias 'screen-root-window 'frame-root-window)
245(defalias 'screen-selected-window 'frame-selected-window)
246(defalias 'lower-screen 'lower-frame)
247(defalias 'raise-screen 'raise-frame)
248(defalias 'screen-visible-p 'frame-visible-p)
31e1d920
ER
249(defalias 'screenp 'framep)
250(defalias 'select-screen 'select-frame)
251(defalias 'selected-screen 'selected-frame)
252;; (defalias 'set-screen-configuration 'set-frame-configuration)
253;; (defalias 'set-screen-height 'set-frame-height)
254(defalias 'set-screen-position 'set-frame-position)
255(defalias 'set-screen-size 'set-frame-size)
e084483d 256;; (defalias 'set-screen-width 'set-frame-width)
31e1d920
ER
257(defalias 'switch-to-buffer-new-screen 'switch-to-buffer-other-frame)
258;; (defalias 'unfocus-screen 'unfocus-frame)
259(defalias 'visible-screen-list 'visible-frame-list)
260(defalias 'window-screen 'window-frame)
261(defalias 'x-create-screen 'x-create-frame)
c731cd93 262(defalias 'x-new-screen 'make-frame)
6de6752c 263
e084483d
JB
264(provide 'lucid)
265
6b61353c 266;;; arch-tag: 80f9ab46-0b36-4151-86ed-3edb6d449c9e
60370d40 267;;; lucid.el ends here