Commit | Line | Data |
---|---|---|
60370d40 | 1 | ;;; lucid.el --- emulate some Lucid Emacs functions |
b578f267 | 2 | |
3731a850 | 3 | ;; Copyright (C) 1993, 1995, 2001, 2002, 2003, 2004, |
8b72699e | 4 | ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
6de6752c | 5 | |
070c251e | 6 | ;; Maintainer: FSF |
284b3043 | 7 | ;; Keywords: emulations |
070c251e | 8 | |
6de6752c RS |
9 | ;; This file is part of GNU Emacs. |
10 | ||
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 | |
e0085d62 | 13 | ;; the Free Software Foundation; either version 3, or (at your option) |
6de6752c RS |
14 | ;; any later version. |
15 | ||
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. | |
20 | ||
21 | ;; You should have received a copy of the GNU General Public License | |
b578f267 | 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
3a35cf56 LK |
23 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 | ;; Boston, MA 02110-1301, USA. | |
6de6752c | 25 | |
60370d40 PJ |
26 | ;;; Commentary: |
27 | ||
b578f267 | 28 | ;;; Code: |
6de6752c | 29 | |
5e2dfaa4 SM |
30 | ;; XEmacs autoloads CL so we might as well make use of it. |
31 | (require 'cl) | |
330fba95 | 32 | |
31e1d920 | 33 | (defalias 'current-time-seconds 'current-time) |
330fba95 | 34 | |
3b787dc3 RS |
35 | (defun read-number (prompt &optional integers-only) |
36 | "Read a number from the minibuffer. | |
37 | Keep reentering the minibuffer until we get suitable input. | |
38 | If optional argument INTEGERS-ONLY is non-nil, insist on an integer." | |
39 | (interactive) | |
40 | (let (success | |
41 | (number nil) | |
42 | (predicate (if integers-only 'integerp 'numberp))) | |
43 | (while (not success) | |
44 | (let ((input-string (read-string prompt))) | |
45 | (condition-case () | |
46 | (setq number (read input-string)) | |
47 | (error)) | |
48 | (if (funcall predicate number) | |
49 | (setq success t) | |
50 | (let ((cursor-in-echo-area t)) | |
51 | (message "Please type %s" | |
52 | (if integers-only "an integer" "a number")) | |
53 | (sit-for 1))))) | |
54 | number)) | |
55 | ||
7d18d35c JB |
56 | (defun real-path-name (name &optional default) |
57 | (file-truename (expand-file-name name default))) | |
58 | ||
59 | ;; It's not clear what to return if the mouse is not in FRAME. | |
60 | (defun read-mouse-position (frame) | |
61 | (let ((pos (mouse-position))) | |
62 | (if (eq (car pos) frame) | |
63 | (cdr pos)))) | |
64 | ||
65 | (defun switch-to-other-buffer (arg) | |
66 | "Switch to the previous buffer. | |
67 | With a numeric arg N, switch to the Nth most recent buffer. | |
68 | With an arg of 0, buries the current buffer at the | |
69 | bottom of the buffer stack." | |
70 | (interactive "p") | |
71 | (if (eq arg 0) | |
72 | (bury-buffer (current-buffer))) | |
73 | (switch-to-buffer | |
74 | (if (<= arg 1) (other-buffer (current-buffer)) | |
7c7daa22 | 75 | (nth arg |
e084483d JB |
76 | (apply 'nconc |
77 | (mapcar | |
78 | (lambda (buf) | |
0b9be2e7 | 79 | (if (= ?\ (string-to-char (buffer-name buf))) |
e084483d | 80 | nil |
0b9be2e7 JB |
81 | (list buf))) |
82 | (buffer-list))))))) | |
e15765f5 | 83 | |
efcc2791 SM |
84 | (defun device-class (&optional device) |
85 | "Return the class (color behavior) of DEVICE. | |
86 | This will be one of 'color, 'grayscale, or 'mono. | |
87 | This function exists for compatibility with XEmacs." | |
88 | (cond | |
89 | ((display-color-p device) 'color) | |
90 | ((display-grayscale-p device) 'grayscale) | |
91 | (t 'mono))) | |
92 | ||
31e1d920 ER |
93 | (defalias 'find-face 'internal-find-face) |
94 | (defalias 'get-face 'internal-get-face) | |
95 | (defalias 'try-face-font 'internal-try-face-font) | |
6b4268b0 RS |
96 | |
97 | (defalias 'exec-to-string 'shell-command-to-string) | |
7d18d35c | 98 | \f |
efcc2791 SM |
99 | |
100 | ;; Buffer context | |
101 | ||
102 | (defun buffer-syntactic-context (&optional buffer) | |
103 | "Syntactic context at point in BUFFER. | |
89a5038d | 104 | Either of `string', `comment' or nil. |
efcc2791 SM |
105 | This is an XEmacs compatibility function." |
106 | (with-current-buffer (or buffer (current-buffer)) | |
107 | (let ((state (syntax-ppss (point)))) | |
108 | (cond | |
109 | ((nth 3 state) 'string) | |
110 | ((nth 4 state) 'comment))))) | |
111 | ||
112 | ||
113 | (defun buffer-syntactic-context-depth (&optional buffer) | |
114 | "Syntactic parenthesis depth at point in BUFFER. | |
115 | This is an XEmacs compatibility function." | |
116 | (with-current-buffer (or buffer (current-buffer)) | |
117 | (nth 0 (syntax-ppss (point))))) | |
118 | ||
119 | ||
120 | ;; Extents | |
51566783 RS |
121 | (defun make-extent (beg end &optional buffer) |
122 | (make-overlay beg end buffer)) | |
123 | ||
5e2dfaa4 SM |
124 | (defun extent-properties (extent) (overlay-properties extent)) |
125 | (unless (fboundp 'extent-property) (defalias 'extent-property 'overlay-get)) | |
c9411d2f RS |
126 | |
127 | (defun extent-at (pos &optional object property before) | |
128 | (with-current-buffer (or object (current-buffer)) | |
129 | (let ((overlays (overlays-at pos))) | |
130 | (when property | |
131 | (let (filtered) | |
132 | (while overlays | |
133 | (if (overlay-get (car overlays) property) | |
134 | (setq filtered (cons (car overlays) filtered))) | |
135 | (setq overlays (cdr overlays))) | |
136 | (setq overlays filtered))) | |
137 | (setq overlays | |
138 | (sort overlays | |
139 | (function (lambda (o1 o2) | |
140 | (let ((p1 (or (overlay-get o1 'priority) 0)) | |
141 | (p2 (or (overlay-get o2 'priority) 0))) | |
142 | (or (> p1 p2) | |
143 | (and (= p1 p2) | |
144 | (> (overlay-start o1) (overlay-start o2))))))))) | |
145 | (if before | |
146 | (nth 1 (memq before overlays)) | |
147 | (car overlays))))) | |
148 | ||
51566783 | 149 | (defun set-extent-property (extent prop value) |
c27d895b RS |
150 | ;; Make sure that separate adjacent extents |
151 | ;; with the same mouse-face value | |
152 | ;; do not run together as one extent. | |
153 | (and (eq prop 'mouse-face) | |
154 | (symbolp value) | |
155 | (setq value (list value))) | |
51566783 RS |
156 | (if (eq prop 'duplicable) |
157 | (cond ((and value (not (overlay-get extent prop))) | |
158 | ;; If becoming duplicable, copy all overlayprops to text props. | |
159 | (add-text-properties (overlay-start extent) | |
160 | (overlay-end extent) | |
161 | (overlay-properties extent) | |
162 | (overlay-buffer extent))) | |
163 | ;; If becoming no longer duplicable, remove these text props. | |
164 | ((and (not value) (overlay-get extent prop)) | |
165 | (remove-text-properties (overlay-start extent) | |
166 | (overlay-end extent) | |
167 | (overlay-properties extent) | |
168 | (overlay-buffer extent)))) | |
169 | ;; If extent is already duplicable, put this property | |
170 | ;; on the text as well as on the overlay. | |
171 | (if (overlay-get extent 'duplicable) | |
172 | (put-text-property (overlay-start extent) | |
173 | (overlay-end extent) | |
174 | prop value (overlay-buffer extent)))) | |
175 | (overlay-put extent prop value)) | |
176 | ||
177 | (defun set-extent-face (extent face) | |
178 | (set-extent-property extent 'face face)) | |
179 | ||
5e2dfaa4 SM |
180 | (defun set-extent-end-glyph (extent glyph) |
181 | (set-extent-property extent 'after-string glyph)) | |
182 | ||
51566783 RS |
183 | (defun delete-extent (extent) |
184 | (set-extent-property extent 'duplicable nil) | |
185 | (delete-overlay extent)) | |
186 | \f | |
7d18d35c JB |
187 | ;; Support the Lucid names with `screen' instead of `frame'. |
188 | ||
31e1d920 ER |
189 | (defalias 'current-screen-configuration 'current-frame-configuration) |
190 | (defalias 'delete-screen 'delete-frame) | |
191 | (defalias 'find-file-new-screen 'find-file-other-frame) | |
192 | (defalias 'find-file-read-only-new-screen 'find-file-read-only-other-frame) | |
193 | (defalias 'find-tag-new-screen 'find-tag-other-frame) | |
194 | ;;(defalias 'focus-screen 'focus-frame) | |
195 | (defalias 'iconify-screen 'iconify-frame) | |
196 | (defalias 'mail-new-screen 'mail-other-frame) | |
197 | (defalias 'make-screen-invisible 'make-frame-invisible) | |
198 | (defalias 'make-screen-visible 'make-frame-visible) | |
199 | ;; (defalias 'minibuffer-screen-list 'minibuffer-frame-list) | |
200 | (defalias 'modify-screen-parameters 'modify-frame-parameters) | |
201 | (defalias 'next-screen 'next-frame) | |
202 | ;; (defalias 'next-multiscreen-window 'next-multiframe-window) | |
203 | ;; (defalias 'previous-multiscreen-window 'previous-multiframe-window) | |
204 | ;; (defalias 'redirect-screen-focus 'redirect-frame-focus) | |
205 | (defalias 'redraw-screen 'redraw-frame) | |
206 | ;; (defalias 'screen-char-height 'frame-char-height) | |
207 | ;; (defalias 'screen-char-width 'frame-char-width) | |
208 | ;; (defalias 'screen-configuration-to-register 'frame-configuration-to-register) | |
209 | ;; (defalias 'screen-focus 'frame-focus) | |
31e1d920 ER |
210 | (defalias 'screen-list 'frame-list) |
211 | ;; (defalias 'screen-live-p 'frame-live-p) | |
212 | (defalias 'screen-parameters 'frame-parameters) | |
213 | (defalias 'screen-pixel-height 'frame-pixel-height) | |
214 | (defalias 'screen-pixel-width 'frame-pixel-width) | |
215 | (defalias 'screen-root-window 'frame-root-window) | |
216 | (defalias 'screen-selected-window 'frame-selected-window) | |
217 | (defalias 'lower-screen 'lower-frame) | |
218 | (defalias 'raise-screen 'raise-frame) | |
219 | (defalias 'screen-visible-p 'frame-visible-p) | |
31e1d920 ER |
220 | (defalias 'screenp 'framep) |
221 | (defalias 'select-screen 'select-frame) | |
222 | (defalias 'selected-screen 'selected-frame) | |
223 | ;; (defalias 'set-screen-configuration 'set-frame-configuration) | |
224 | ;; (defalias 'set-screen-height 'set-frame-height) | |
225 | (defalias 'set-screen-position 'set-frame-position) | |
226 | (defalias 'set-screen-size 'set-frame-size) | |
e084483d | 227 | ;; (defalias 'set-screen-width 'set-frame-width) |
31e1d920 ER |
228 | (defalias 'switch-to-buffer-new-screen 'switch-to-buffer-other-frame) |
229 | ;; (defalias 'unfocus-screen 'unfocus-frame) | |
230 | (defalias 'visible-screen-list 'visible-frame-list) | |
231 | (defalias 'window-screen 'window-frame) | |
232 | (defalias 'x-create-screen 'x-create-frame) | |
c731cd93 | 233 | (defalias 'x-new-screen 'make-frame) |
6de6752c | 234 | |
e084483d JB |
235 | (provide 'lucid) |
236 | ||
cbee283d | 237 | ;; arch-tag: 80f9ab46-0b36-4151-86ed-3edb6d449c9e |
60370d40 | 238 | ;;; lucid.el ends here |