comparison lisp/prim/subr.el @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents ec9a17fef872
children b9518feda344
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of 15 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 ;; General Public License for more details. 17 ;; General Public License for more details.
18 18
19 ;; You should have received a copy of the GNU General Public License 19 ;; You should have received a copy of the GNU General Public License
20 ;; along with XEmacs; see the file COPYING. If not, write to the Free 20 ;; along with XEmacs; see the file COPYING. If not, write to the
21 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 21 ;; Free Software Foundation, 59 Temple Place - Suite 330,
22 ;; 02111-1307, USA. 22 ;; Boston, MA 02111-1307, USA.
23 23
24 ;;; Synched up with: FSF 19.34. 24 ;;; Synched up with: FSF 19.30.
25
26 ;;; Commentary:
27
28 ;; There's not a whole lot in common now with the FSF version,
29 ;; be wary when applying differences. I've left in a number of lines
30 ;; of commentary just to give diff(1) something to synch itself with to
31 ;; provide useful context diffs. -sb
32 25
33 ;;; Code: 26 ;;; Code:
34 27
35 28
36 ;;;; Lisp language features. 29 ;;;; Lisp language features.
68 "Define a function, just like `define-function', unless it's already defined. 61 "Define a function, just like `define-function', unless it's already defined.
69 Used for compatibility among different emacs variants." 62 Used for compatibility among different emacs variants."
70 `(if (fboundp ,(car args)) 63 `(if (fboundp ,(car args))
71 nil 64 nil
72 (define-function ,@args))) 65 (define-function ,@args)))
73 66
74 ;;;; Keymap support.
75 ;; XEmacs: removed to keymap.el
76
77 ;;;; The global keymap tree.
78
79 ;;; global-map, esc-map, and ctl-x-map have their values set up in
80 ;;; keymap.c; we just give them docstrings here.
81
82 ;;;; Event manipulation functions.
83
84 ;; The call to `read' is to ensure that the value is computed at load time
85 ;; and not compiled into the .elc file. The value is negative on most
86 ;; machines, but not on all!
87 ;; XEmacs: This stuff is done in C Code.
88
89 ;;;; Obsolescent names for functions.
90 ;; XEmacs: not used.
91
92 ;; XEmacs:
93 (define-function 'not 'null) 67 (define-function 'not 'null)
94 (define-function-when-void 'numberp 'integerp) ; different when floats 68 (define-function-when-void 'numberp 'intergerp) ; different when floats
95 69
96 (defun local-variable-if-set-p (sym buffer) 70 (defun local-variable-if-set-p (sym buffer)
97 "Return t if SYM would be local to BUFFER after it is set. 71 "Return t if SYM would be local to BUFFER after it is set.
98 A nil value for BUFFER is *not* the same as (current-buffer), but 72 A nil value for BUFFER is *not* the same as (current-buffer), but
99 can be used to determine whether `make-variable-buffer-local' has been 73 can be used to determine whether `make-variable-buffer-local' has been
101 (local-variable-p sym buffer t)) 75 (local-variable-p sym buffer t))
102 76
103 77
104 ;;;; Hook manipulation functions. 78 ;;;; Hook manipulation functions.
105 79
106 ;; (defconst run-hooks 'run-hooks ...)
107
108 (defun make-local-hook (hook) 80 (defun make-local-hook (hook)
109 "Make the hook HOOK local to the current buffer. 81 "Make the hook HOOK local to the current buffer.
110 When a hook is local, its local and global values 82 When a hook is local, its local and global values
111 work in concert: running the hook actually runs all the hook 83 work in concert: running the hook actually runs all the hook
112 functions listed in *either* the local value *or* the global value 84 functions listed in *either* the local value *or* the global value
121 93
122 This function does nothing if HOOK is already local in the current 94 This function does nothing if HOOK is already local in the current
123 buffer. 95 buffer.
124 96
125 Do not use `make-local-variable' to make a hook variable buffer-local." 97 Do not use `make-local-variable' to make a hook variable buffer-local."
126 (if (local-variable-p hook (current-buffer)) ; XEmacs 98 (if (local-variable-p hook (current-buffer))
127 nil 99 nil
128 (or (boundp hook) (set hook nil)) 100 (or (boundp hook) (set hook nil))
129 (make-local-variable hook) 101 (make-local-variable hook)
130 (set hook (list t)))) 102 (set hook (list t))))
131 103
143 `make-local-hook', not `make-local-variable'. 115 `make-local-hook', not `make-local-variable'.
144 116
145 HOOK should be a symbol, and FUNCTION may be any valid function. If 117 HOOK should be a symbol, and FUNCTION may be any valid function. If
146 HOOK is void, it is first set to nil. If HOOK's value is a single 118 HOOK is void, it is first set to nil. If HOOK's value is a single
147 function, it is changed to a list of functions." 119 function, it is changed to a list of functions."
120 ;(interactive "SAdd to hook-var (symbol): \naAdd which function to %s? ")
148 (or (boundp hook) (set hook nil)) 121 (or (boundp hook) (set hook nil))
149 (or (default-boundp hook) (set-default hook nil)) 122 (or (default-boundp hook) (set-default hook nil))
150 ;; If the hook value is a single function, turn it into a list. 123 ;; If the hook value is a single function, turn it into a list.
151 (let ((old (symbol-value hook))) 124 (let ((old (symbol-value hook)))
152 (if (or (not (listp old)) (eq (car old) 'lambda)) 125 (if (or (not (listp old)) (eq (car old) 'lambda))
153 (set hook (list old)))) 126 (set hook (list old))))
154 (if (or local 127 (if (or local
155 ;; Detect the case where make-local-variable was used on a hook 128 ;; Detect the case where make-local-variable was used on a hook
156 ;; and do what we used to do. 129 ;; and do what we used to do.
157 (and (local-variable-if-set-p hook (current-buffer)) ; XEmacs 130 (and (local-variable-if-set-p hook (current-buffer))
158 (not (memq t (symbol-value hook))))) 131 (not (memq t (symbol-value hook)))))
159 ;; Alter the local value only. 132 ;; Alter the local value only.
160 (or (if (consp function) 133 (or (if (consp function)
161 (member function (symbol-value hook)) 134 (member function (symbol-value hook))
162 (memq function (symbol-value hook))) 135 (memq function (symbol-value hook)))
210 (setq hook-value nil))) 183 (setq hook-value nil)))
211 (set-default hook hook-value))))) 184 (set-default hook hook-value)))))
212 185
213 (defun add-to-list (list-var element) 186 (defun add-to-list (list-var element)
214 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet. 187 "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
215 The test for presence of ELEMENT is done with `equal'.
216 If you want to use `add-to-list' on a variable that is not defined 188 If you want to use `add-to-list' on a variable that is not defined
217 until a certain package is loaded, you should put the call to `add-to-list' 189 until a certain package is loaded, you should put the call to `add-to-list'
218 into a hook function that will be run only after loading the package. 190 into a hook function that will be run only after loading the package.
219 `eval-after-load' provides one way to do this. In some cases 191 `eval-after-load' provides one way to do this. In some cases
220 other hooks, such as major mode hooks, can do the job." 192 other hooks, such as major mode hooks, can do the job."
221 (or (member element (symbol-value list-var)) 193 (or (member element (symbol-value list-var))
222 (set list-var (cons element (symbol-value list-var))))) 194 (set list-var (cons element (symbol-value list-var)))))
223 195
224 ;; XEmacs additions
225 ;; called by Fkill_buffer() 196 ;; called by Fkill_buffer()
226 (defvar kill-buffer-hook nil 197 (defvar kill-buffer-hook nil
227 "Function or functions to be called when a buffer is killed. 198 "Function or functions to be called when a buffer is killed.
228 The value of this variable may be buffer-local. 199 The value of this variable may be buffer-local.
229 The buffer about to be killed is current when this hook is run.") 200 The buffer about to be killed is current when this hook is run.")
235 206
236 ;; not obsolete. 207 ;; not obsolete.
237 (define-function 'rplaca 'setcar) 208 (define-function 'rplaca 'setcar)
238 (define-function 'rplacd 'setcdr) 209 (define-function 'rplacd 'setcdr)
239 210
240 ;; XEmacs
241 (defun mapvector (__function __seq) 211 (defun mapvector (__function __seq)
242 "Apply FUNCTION to each element of SEQ, making a vector of the results. 212 "Apply FUNCTION to each element of SEQ, making a vector of the results.
243 The result is a vector of the same length as SEQ. 213 The result is a vector of the same length as SEQ.
244 SEQ may be a list, a vector or a string." 214 SEQ may be a list, a vector or a string."
245 (let* ((len (length __seq)) 215 (let* ((len (length __seq))
252 (setq i (+ i 1))) 222 (setq i (+ i 1)))
253 vec)) 223 vec))
254 224
255 ;;;; String functions. 225 ;;;; String functions.
256 226
257 ;; XEmacs
258 (defun replace-in-string (str regexp newtext &optional literal) 227 (defun replace-in-string (str regexp newtext &optional literal)
259 "Replaces all matches in STR for REGEXP with NEWTEXT string. 228 "Replaces all matches in STR for REGEXP with NEWTEXT string.
260 Optional LITERAL non-nil means do a literal replacement. 229 Optional LITERAL non-nil means do a literal replacement.
261 Otherwise treat \\ in NEWTEXT string as special: 230 Otherwise treat \\ in NEWTEXT string as special:
262 \\& means substitute original matched text, 231 \\& means substitute original matched text,
328 (,@ forms)) 297 (,@ forms))
329 (prog1 298 (prog1
330 (buffer-string) 299 (buffer-string)
331 (erase-buffer))))) 300 (erase-buffer)))))
332 301
333 (defmacro with-temp-buffer (&rest forms)
334 "Create a temporary buffer, and evaluate FORMS there like `progn'."
335 (let ((temp-buffer (make-symbol "temp-buffer")))
336 `(let ((,temp-buffer
337 (get-buffer-create (generate-new-buffer-name " *temp*"))))
338 (unwind-protect
339 (save-excursion
340 (set-buffer ,temp-buffer)
341 ,@forms)
342 (and (buffer-name ,temp-buffer)
343 (kill-buffer ,temp-buffer))))))
344
345 ;; Moved from 20.1:lisp/mule/mule-coding.el.
346 (defmacro with-string-as-buffer-contents (str &rest body)
347 "With the contents of the current buffer being STR, run BODY.
348 Returns the new contents of the buffer, as modified by BODY.
349 The original current buffer is restored afterwards."
350 `(let ((curbuf (current-buffer))
351 (tempbuf (get-buffer-create " *string-as-buffer-contents*")))
352 (unwind-protect
353 (progn
354 (set-buffer tempbuf)
355 (buffer-disable-undo (current-buffer))
356 (erase-buffer)
357 (insert ,str)
358 ,@body
359 (buffer-string))
360 (erase-buffer tempbuf)
361 (set-buffer curbuf))))
362
363 (defun insert-face (string face) 302 (defun insert-face (string face)
364 "Insert STRING and highlight with FACE. Returns the extent created." 303 "Insert STRING and highlight with FACE. Returns the extent created."
365 (let ((p (point)) ext) 304 (let ((p (point)) ext)
366 (insert string) 305 (insert string)
367 (setq ext (make-extent p (point))) 306 (setq ext (make-extent p (point)))
467 (signal 'error (list (apply 'format args)))) 406 (signal 'error (list (apply 'format args))))
468 407
469 (defmacro check-argument-type (predicate argument) 408 (defmacro check-argument-type (predicate argument)
470 "Check that ARGUMENT satisfies PREDICATE. 409 "Check that ARGUMENT satisfies PREDICATE.
471 If not, signal a continuable `wrong-type-argument' error until the 410 If not, signal a continuable `wrong-type-argument' error until the
472 returned value satisfies PREDICATE, and assign the returned value 411 returned value satifies PREDICATE, and assign the returned value
473 to ARGUMENT." 412 to ARGUMENT."
474 `(if (not (,(eval predicate) ,argument)) 413 `(if (not (,(eval predicate) ,argument))
475 (setq ,argument 414 (setq ,argument
476 (wrong-type-argument ,predicate ,argument)))) 415 (wrong-type-argument ,predicate ,argument))))
477 416
561 500
562 ;; This was not present before. I think Jamie had some objections 501 ;; This was not present before. I think Jamie had some objections
563 ;; to this, so I'm leaving this undefined for now. --ben 502 ;; to this, so I'm leaving this undefined for now. --ben
564 503
565 ;;; The objection is this: there is more than one way to load the same file. 504 ;;; The objection is this: there is more than one way to load the same file.
566 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all different 505 ;;; "foo", "foo.elc", "foo.el", and "/some/path/foo.elc" are all differrent
567 ;;; ways to load the exact same code. `eval-after-load' is too stupid to 506 ;;; ways to load the exact same code. `eval-after-load' is too stupid to
568 ;;; deal with this sort of thing. If this sort of feature is desired, then 507 ;;; deal with this sort of thing. If this sort of feature is desired, then
569 ;;; it should work off of a hook on `provide'. Features are unique and 508 ;;; it should work off of a hook on `provide'. Features are unique and
570 ;;; the arguments to (load) are not. --Stig 509 ;;; the arguments to (load) are not. --Stig
571 510
572 ;;;; Specifying things to do after certain files are loaded. 511 ;;;; Specifying things to do after certain files are loaded.
573 512
574 (defun eval-after-load (file form) 513 ;(defun eval-after-load (file form)
575 "Arrange that, if FILE is ever loaded, FORM will be run at that time. 514 ; "Arrange that, if FILE is ever loaded, FORM will be run at that time.
576 This makes or adds to an entry on `after-load-alist'. 515 ;This makes or adds to an entry on `after-load-alist'.
577 If FILE is already loaded, evaluate FORM right now. 516 ;If FILE is already loaded, evaluate FORM right now.
578 It does nothing if FORM is already on the list for FILE. 517 ;It does nothing if FORM is already on the list for FILE.
579 FILE should be the name of a library, with no directory name." 518 ;FILE should be the name of a library, with no directory name."
580 ;; Make sure there is an element for FILE. 519 ; ;; Make sure there is an element for FILE.
581 (or (assoc file after-load-alist) 520 ; (or (assoc file after-load-alist)
582 (setq after-load-alist (cons (list file) after-load-alist))) 521 ; (setq after-load-alist (cons (list file) after-load-alist)))
583 ;; Add FORM to the element if it isn't there. 522 ; ;; Add FORM to the element if it isn't there.
584 (let ((elt (assoc file after-load-alist))) 523 ; (let ((elt (assoc file after-load-alist)))
585 (or (member form (cdr elt)) 524 ; (or (member form (cdr elt))
586 (progn 525 ; (progn
587 (nconc elt (list form)) 526 ; (nconc elt (list form))
588 ;; If the file has been loaded already, run FORM right away. 527 ; ;; If the file has been loaded already, run FORM right away.
589 (and (assoc file load-history) 528 ; (and (assoc file load-history)
590 (eval form))))) 529 ; (eval form)))))
591 form) 530 ; form)
592 531 ;
593 (defun eval-next-after-load (file) 532 ;(defun eval-next-after-load (file)
594 "Read the following input sexp, and run it whenever FILE is loaded. 533 ; "Read the following input sexp, and run it whenever FILE is loaded.
595 This makes or adds to an entry on `after-load-alist'. 534 ;This makes or adds to an entry on `after-load-alist'.
596 FILE should be the name of a library, with no directory name." 535 ;FILE should be the name of a library, with no directory name."
597 (eval-after-load file (read))) 536 ; (eval-after-load file (read)))
598 537
599 ; alternate names (not obsolete) 538 ; alternate names (not obsolete)
600 (if (not (fboundp 'mod)) (define-function 'mod '%)) 539 (if (not (fboundp 'mod)) (define-function 'mod '%))
601 (define-function 'move-marker 'set-marker) 540 (define-function 'move-marker 'set-marker)
602 (define-function 'beep 'ding) ; preserve lingual purity 541 (define-function 'beep 'ding) ; preserve lingual purity
606 (define-function 'search-backward-regexp (symbol-function 're-search-backward)) 545 (define-function 'search-backward-regexp (symbol-function 're-search-backward))
607 (define-function 'remove-directory 'delete-directory) 546 (define-function 'remove-directory 'delete-directory)
608 (define-function 'set-match-data 'store-match-data) 547 (define-function 'set-match-data 'store-match-data)
609 (define-function 'send-string-to-terminal 'external-debugging-output) 548 (define-function 'send-string-to-terminal 'external-debugging-output)
610 (define-function 'buffer-string 'buffer-substring) 549 (define-function 'buffer-string 'buffer-substring)
611
612 ;;; subr.el ends here