comparison lisp/subr.el @ 61955:a328ce1555c6

(string-to-int): Make obsolete.
author Nick Roberts <nickrob@snap.net.nz>
date Sun, 01 May 2005 04:44:14 +0000
parents 994a6fb78d4c
children d9764486d42f effe22690419
comparison
equal deleted inserted replaced
61954:41f6009ded92 61955:a328ce1555c6
347 (setq loop (1+ loop)))))) 347 (setq loop (1+ loop))))))
348 348
349 (defvar key-substitution-in-progress nil 349 (defvar key-substitution-in-progress nil
350 "Used internally by substitute-key-definition.") 350 "Used internally by substitute-key-definition.")
351 351
352 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix) 352 (defun substitute-key-definitions (subst keymap &optional oldmap prefix)
353 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF. 353 "Applies the SUBST remapping to key bindings in KEYMAP.
354 In other words, OLDDEF is replaced with NEWDEF where ever it appears. 354 SUBST will be a list of elements of the form (OLDDEF . NEWDEF).
355 Alternatively, if optional fourth argument OLDMAP is specified, we redefine 355 See `substitue-key-definition'."
356 in KEYMAP as NEWDEF those keys which are defined as OLDDEF in OLDMAP.
357
358 For most uses, it is simpler and safer to use command remappping like this:
359 \(define-key KEYMAP [remap OLDDEF] NEWDEF)"
360 ;; Don't document PREFIX in the doc string because we don't want to 356 ;; Don't document PREFIX in the doc string because we don't want to
361 ;; advertise it. It's meant for recursive calls only. Here's its 357 ;; advertise it. It's meant for recursive calls only. Here's its
362 ;; meaning 358 ;; meaning
363 359
364 ;; If optional argument PREFIX is specified, it should be a key 360 ;; If optional argument PREFIX is specified, it should be a key
372 ;; Scan OLDMAP, finding each char or event-symbol that 368 ;; Scan OLDMAP, finding each char or event-symbol that
373 ;; has any definition, and act on it with hack-key. 369 ;; has any definition, and act on it with hack-key.
374 (map-keymap 370 (map-keymap
375 (lambda (char defn) 371 (lambda (char defn)
376 (aset prefix1 (length prefix) char) 372 (aset prefix1 (length prefix) char)
377 (substitute-key-definition-key defn olddef newdef prefix1 keymap)) 373 (substitute-key-definitions-key defn subst prefix1 keymap))
378 scan))) 374 scan)))
379 375
380 (defun substitute-key-definition-key (defn olddef newdef prefix keymap) 376 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
381 (let (inner-def skipped menu-item) 377 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
378 In other words, OLDDEF is replaced with NEWDEF where ever it appears.
379 Alternatively, if optional fourth argument OLDMAP is specified, we redefine
380 in KEYMAP as NEWDEF those keys which are defined as OLDDEF in OLDMAP.
381
382 For most uses, it is simpler and safer to use command remappping like this:
383 \(define-key KEYMAP [remap OLDDEF] NEWDEF)"
384 ;; Don't document PREFIX in the doc string because we don't want to
385 ;; advertise it. It's meant for recursive calls only. Here's its
386 ;; meaning
387
388 ;; If optional argument PREFIX is specified, it should be a key
389 ;; prefix, a string. Redefined bindings will then be bound to the
390 ;; original key, with PREFIX added at the front.
391 (substitute-key-definitions (list (cons olddef newdef)) keymap oldmap prefix))
392
393 (defun substitute-key-definitions-key (defn subst prefix keymap)
394 (let (inner-def skipped menu-item mapping)
382 ;; Find the actual command name within the binding. 395 ;; Find the actual command name within the binding.
383 (if (eq (car-safe defn) 'menu-item) 396 (if (eq (car-safe defn) 'menu-item)
384 (setq menu-item defn defn (nth 2 defn)) 397 (setq menu-item defn defn (nth 2 defn))
385 ;; Skip past menu-prompt. 398 ;; Skip past menu-prompt.
386 (while (stringp (car-safe defn)) 399 (while (stringp (car-safe defn))
387 (push (pop defn) skipped)) 400 (push (pop defn) skipped))
388 ;; Skip past cached key-equivalence data for menu items. 401 ;; Skip past cached key-equivalence data for menu items.
389 (if (consp (car-safe defn)) 402 (if (consp (car-safe defn))
390 (setq defn (cdr defn)))) 403 (setq defn (cdr defn))))
391 (if (or (eq defn olddef) 404 (if (or (setq mapping (assq defn subst))
392 ;; Compare with equal if definition is a key sequence. 405 ;; Compare with equal if definition is a key sequence.
393 ;; That is useful for operating on function-key-map. 406 ;; That is useful for operating on function-key-map.
394 (and (or (stringp defn) (vectorp defn)) 407 (and (or (stringp defn) (vectorp defn))
395 (equal defn olddef))) 408 (setq mapping (assoc defn subst))))
396 (define-key keymap prefix 409 (define-key keymap prefix
397 (if menu-item 410 (if menu-item
398 (let ((copy (copy-sequence menu-item))) 411 (let ((copy (copy-sequence menu-item)))
399 (setcar (nthcdr 2 copy) newdef) 412 (setcar (nthcdr 2 copy) (cdr mapping))
400 copy) 413 copy)
401 (nconc (nreverse skipped) newdef))) 414 (nconc (nreverse skipped) (cdr mapping))))
402 ;; Look past a symbol that names a keymap. 415 ;; Look past a symbol that names a keymap.
403 (setq inner-def 416 (setq inner-def
404 (and defn 417 (and defn
405 (condition-case nil (indirect-function defn) (error defn)))) 418 (condition-case nil (indirect-function defn) (error defn))))
406 ;; For nested keymaps, we use `inner-def' rather than `defn' so as to 419 ;; For nested keymaps, we use `inner-def' rather than `defn' so as to
412 (let ((elt (lookup-key keymap prefix))) 425 (let ((elt (lookup-key keymap prefix)))
413 (or (null elt) (natnump elt) (keymapp elt))) 426 (or (null elt) (natnump elt) (keymapp elt)))
414 ;; Avoid recursively rescanning keymap being scanned. 427 ;; Avoid recursively rescanning keymap being scanned.
415 (not (memq inner-def key-substitution-in-progress))) 428 (not (memq inner-def key-substitution-in-progress)))
416 ;; If this one isn't being scanned already, scan it now. 429 ;; If this one isn't being scanned already, scan it now.
417 (substitute-key-definition olddef newdef keymap inner-def prefix))))) 430 (substitute-key-definitions subst keymap inner-def prefix)))))
418 431
419 (defun define-key-after (keymap key definition &optional after) 432 (defun define-key-after (keymap key definition &optional after)
420 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding. 433 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
421 This is like `define-key' except that the binding for KEY is placed 434 This is like `define-key' except that the binding for KEY is placed
422 just after the binding for the event AFTER, instead of at the beginning 435 just after the binding for the event AFTER, instead of at the beginning
841 (defalias 'point-at-eol 'line-end-position) 854 (defalias 'point-at-eol 'line-end-position)
842 (defalias 'point-at-bol 'line-beginning-position) 855 (defalias 'point-at-bol 'line-beginning-position)
843 856
844 ;;; Should this be an obsolete name? If you decide it should, you get 857 ;;; Should this be an obsolete name? If you decide it should, you get
845 ;;; to go through all the sources and change them. 858 ;;; to go through all the sources and change them.
846 (defalias 'string-to-int 'string-to-number) 859 (define-obsolete-function-alias 'string-to-int 'string-to-number)
847 860
848 ;;;; Hook manipulation functions. 861 ;;;; Hook manipulation functions.
849 862
850 (defun make-local-hook (hook) 863 (defun make-local-hook (hook)
851 "Make the hook HOOK local to the current buffer. 864 "Make the hook HOOK local to the current buffer.