1 ;;; poe-18.el --- poe API implementation for Emacs 18.*
3 ;; Copyright (C) 1995,1996,1997,1998 Free Software Foundation, Inc.
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Keywords: emulation, compatibility
8 ;; This file is part of APEL (A Portable Emacs Library).
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
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.
27 (autoload 'setenv "env"
28 "Set the value of the environment variable named VARIABLE to VALUE.
29 VARIABLE should be a string. VALUE is optional; if not provided or is
30 `nil', the environment variable VARIABLE will be removed.
31 This function works by modifying `process-environment'."
34 (defvar data-directory exec-directory)
40 (defvar buffer-undo-list nil)
46 ;; These function are imported from EMACS 19.28.
47 (defun add-hook (hook function &optional append)
48 "Add to the value of HOOK the function FUNCTION.
49 FUNCTION is not added if already present.
50 FUNCTION is added (if necessary) at the beginning of the hook list
51 unless the optional argument APPEND is non-nil, in which case
52 FUNCTION is added at the end.
54 HOOK should be a symbol, and FUNCTION may be any valid function. If
55 HOOK is void, it is first set to nil. If HOOK's value is a single
56 function, it is changed to a list of functions.
57 \[poe-18.el; EMACS 19 emulating function]"
61 ;; If the hook value is a single function, turn it into a list.
62 (let ((old (symbol-value hook)))
63 (if (or (not (listp old))
64 (eq (car old) 'lambda))
67 (or (if (consp function)
68 ;; Clever way to tell whether a given lambda-expression
69 ;; is equal to anything in the hook.
70 (let ((tail (assoc (cdr function) (symbol-value hook))))
73 (memq function (symbol-value hook))
77 (nconc (symbol-value hook) (list function))
78 (cons function (symbol-value hook))
82 (defun remove-hook (hook function)
83 "Remove from the value of HOOK the function FUNCTION.
84 HOOK should be a symbol, and FUNCTION may be any valid function. If
85 FUNCTION isn't the value of HOOK, or, if FUNCTION doesn't appear in the
86 list of hooks to run in HOOK, then nothing is done. See `add-hook'.
87 \[poe-18.el; EMACS 19 emulating function]"
88 (if (or (not (boundp hook)) ;unbound symbol, or
89 (null (symbol-value hook)) ;value is nil, or
90 (null function)) ;function is nil, then
92 (let ((hook-value (symbol-value hook)))
93 (if (consp hook-value)
94 (setq hook-value (delete function hook-value))
95 (if (equal hook-value function)
105 (defun member (elt list)
106 "Return non-nil if ELT is an element of LIST. Comparison done with EQUAL.
107 The value is actually the tail of LIST whose car is ELT.
108 \[poe-18.el; EMACS 19 emulating function]"
109 (while (and list (not (equal elt (car list))))
110 (setq list (cdr list)))
113 (defun delete (elt list)
114 "Delete by side effect any occurrences of ELT as a member of LIST.
115 The modified LIST is returned. Comparison is done with `equal'.
116 If the first member of LIST is ELT, deleting it is not a side effect;
117 it is simply using a different list.
118 Therefore, write `(setq foo (delete element foo))'
119 to be sure of changing the value of `foo'.
120 \[poe-18.el; EMACS 19 emulating function]"
121 (if (equal elt (car list))
126 (while (and rrest (not (equal elt (car rrest))))
130 (rplacd rest (cdr rrest))
137 (defun defalias (sym newdef)
138 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.
139 Associates the function with the current load file, if any.
140 \[poe-18.el; EMACS 19 emulating function]"
144 (defun byte-code-function-p (exp)
145 "T if OBJECT is a byte-compiled function object.
146 \[poe-18.el; EMACS 19 emulating function]"
148 (let* ((rest (cdr (cdr exp))) elt)
149 (if (stringp (car rest))
150 (setq rest (cdr rest))
154 (setq elt (car rest))
155 (if (and (consp elt)(eq (car elt) 'byte-code))
158 (setq rest (cdr rest))
162 (defmacro-maybe defsubst (name arglist &rest body)
163 "Define an inline function. The syntax is just like that of `defun'."
164 (cons 'defun (cons name (cons arglist body)))
167 (defun-maybe make-obsolete (fn new)
168 "Make the byte-compiler warn that FUNCTION is obsolete.
169 The warning will say that NEW should be used instead.
170 If NEW is a string, that is the `use instead' message."
171 (interactive "aMake function obsolete: \nxObsoletion replacement: ")
172 (let ((handler (get fn 'byte-compile)))
173 (if (eq 'byte-compile-obsolete handler)
174 (setcar (get fn 'byte-obsolete-info) new)
175 (put fn 'byte-obsolete-info (cons new handler))
176 (put fn 'byte-compile 'byte-compile-obsolete)))
183 (defun make-directory-internal (dirname)
184 "Create a directory. One argument, a file name string.
185 \[poe-18.el; EMACS 19 emulating function]"
186 (if (file-exists-p dirname)
187 (error "Creating directory: %s is already exist" dirname)
188 (if (not (= (call-process "mkdir" nil nil nil dirname) 0))
189 (error "Creating directory: no such file or directory, %s" dirname)
192 (defun make-directory (dir &optional parents)
193 "Create the directory DIR and any nonexistent parent dirs.
194 The second (optional) argument PARENTS says whether
195 to create parent directories if they don't exist.
196 \[poe-18.el; EMACS 19 emulating function]"
197 (let ((len (length dir))
200 (while (and (< p len) (string-match "[^/]*/?" dir p))
201 (setq p1 (match-end 0))
205 (setq path (substring dir 0 p1))
206 (if (not (file-directory-p path))
207 (cond ((file-exists-p path)
208 (error "Creating directory: %s is not directory" path)
211 (error "Creating directory: %s is not exist" path)
214 (make-directory-internal path)
219 (make-directory-internal dir)
222 ;; Imported from files.el of EMACS 19.33.
223 (defun parse-colon-path (cd-path)
224 "Explode a colon-separated list of paths into a string list."
226 (let (cd-prefix cd-list (cd-start 0) cd-colon)
227 (setq cd-path (concat cd-path path-separator))
228 (while (setq cd-colon (string-match path-separator cd-path cd-start))
231 (list (if (= cd-start cd-colon)
233 (substitute-in-file-name
234 (file-name-as-directory
235 (substring cd-path cd-start cd-colon)))))))
236 (setq cd-start (+ cd-colon 1)))
239 ;; Imported from files.el of EMACS 19.33.
240 (defun file-relative-name (filename &optional directory)
241 "Convert FILENAME to be relative to DIRECTORY (default: default-directory)."
242 (setq filename (expand-file-name filename)
243 directory (file-name-as-directory (expand-file-name
244 (or directory default-directory))))
246 (while (not (string-match (concat "^" (regexp-quote directory)) filename))
247 (setq directory (file-name-directory (substring directory 0 -1))
248 ancestor (concat "../" ancestor)))
249 (concat ancestor (substring filename (match-end 0)))))
251 (or (fboundp 'si:directory-files)
252 (fset 'si:directory-files (symbol-function 'directory-files)))
253 (defun directory-files (directory &optional full match nosort)
254 "Return a list of names of files in DIRECTORY.
255 There are three optional arguments:
256 If FULL is non-nil, return absolute file names. Otherwise return names
257 that are relative to the specified directory.
258 If MATCH is non-nil, mention only file names that match the regexp MATCH.
259 If NOSORT is dummy for compatibility.
260 \[poe-18.el; EMACS 19 emulating function]"
261 (si:directory-files directory full match)
268 (or (fboundp 'si:mark)
269 (fset 'si:mark (symbol-function 'mark)))
270 (defun mark (&optional force)
278 ;;; Imported from Emacs 19.30.
279 (defun force-mode-line-update (&optional all)
280 "Force the mode-line of the current buffer to be redisplayed.
281 With optional non-nil ALL, force redisplay of all mode-lines.
282 \[poe-18.el; Emacs 19 emulating function]"
283 (if all (save-excursion (set-buffer (other-buffer))))
284 (set-buffer-modified-p (buffer-modified-p)))
290 (cond ((boundp 'NEMACS)
291 (defvar emu:available-face-attribute-alist
293 ;;(bold . inversed-region)
294 (italic . underlined-region)
295 (underline . underlined-region)
298 ;; by YAMATE Keiichirou 1994/10/28
299 (defun attribute-add-narrow-attribute (attr from to)
300 (or (consp (symbol-value attr))
302 (let* ((attr-value (symbol-value attr))
303 (len (car attr-value))
306 (while (and (< posfrom len)
307 (> from (nth posfrom attr-value)))
308 (setq posfrom (1+ posfrom)))
310 (while (and (< posto len)
311 (> to (nth posto attr-value)))
312 (setq posto (1+ posto)))
313 (if (= posto posfrom)
314 (if (= (% posto 2) 1)
316 (= to (nth posto attr-value)))
317 (set-marker (nth posto attr-value) from)
318 (setcdr (nthcdr (1- posfrom) attr-value)
319 (cons (set-marker-type (set-marker (make-marker)
322 (cons (set-marker-type
323 (set-marker (make-marker)
326 (nthcdr posto attr-value))))
327 (setcar attr-value (+ len 2))))
328 (if (= (% posfrom 2) 0)
329 (setq posfrom (1- posfrom))
330 (set-marker (nth posfrom attr-value) from))
331 (if (= (% posto 2) 0)
333 (setq posto (1- posto))
334 (set-marker (nth posto attr-value) to))
335 (setcdr (nthcdr posfrom attr-value)
336 (nthcdr posto attr-value)))))
338 (defalias 'make-overlay 'cons)
340 (defun overlay-put (overlay prop value)
341 (let ((ret (and (eq prop 'face)
342 (assq value emu:available-face-attribute-alist)
345 (attribute-add-narrow-attribute (cdr ret)
346 (car overlay)(cdr overlay))
350 (defun make-overlay (beg end &optional buffer type))
351 (defun overlay-put (overlay prop value))
354 (defun overlay-buffer (overlay))
360 (defun set-text-properties (start end properties &optional object))
362 (defun remove-text-properties (start end properties &optional object))
365 ;;; @@ visible/invisible
368 (defmacro enable-invisible ()
371 (make-local-variable 'original-selective-display)
372 (setq original-selective-display selective-display)
373 (setq selective-display t)
376 (defmacro end-of-invisible ()
377 (` (setq selective-display
378 (if (boundp 'original-selective-display)
379 original-selective-display))
382 (defun invisible-region (start end)
383 (let ((buffer-read-only nil) ;Okay even if write protected.
384 (modp (buffer-modified-p)))
387 (eq (following-char) ?\n)
392 (subst-char-in-region start end ?\n ?\^M t)
393 (set-buffer-modified-p modp)
396 (defun visible-region (start end)
397 (let ((buffer-read-only nil) ;Okay even if write protected.
398 (modp (buffer-modified-p)))
400 (subst-char-in-region start end ?\^M ?\n t)
401 (set-buffer-modified-p modp)
404 (defun invisible-p (pos)
407 (eq (following-char) ?\^M)
410 (defun next-visible-point (pos)
414 (if (eq (following-char) ?\n)
424 (defun char-list-to-string (char-list)
425 "Convert list of character CHAR-LIST to string. [poe-18.el]"
426 (mapconcat (function char-to-string) char-list "")
433 (defun-maybe generate-new-buffer-name (name &optional ignore)
434 "Return a string that is the name of no existing buffer based on NAME.
435 If there is no live buffer named NAME, then return NAME.
436 Otherwise modify name by appending `<NUMBER>', incrementing NUMBER
437 until an unused name is found, and then return that name.
438 Optional second argument IGNORE specifies a name that is okay to use
439 \(if it is in the sequence to be tried)
440 even if a buffer with that name exists."
441 (if (get-buffer name)
443 (while (get-buffer (setq new (format "%s<%d>" name n)))
454 ;;; poe-18.el ends here