comparison lisp/subr.el @ 83301:b151ec53c504

Merged from miles@gnu.org--gnu-2005 (patch 68, 286-291) Patches applied: * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-286 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-287 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-288 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-289 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-290 Update from CVS * miles@gnu.org--gnu-2005/emacs--cvs-trunk--0--patch-291 Merge from gnus--rel--5.10 * miles@gnu.org--gnu-2005/gnus--rel--5.10--patch-68 Update from CVS git-archimport-id: lorentey@elte.hu--2004/emacs--multi-tty--0--patch-341
author Karoly Lorentey <lorentey@elte.hu>
date Fri, 06 May 2005 21:06:31 +0000
parents effe22690419 e208ebaf0e17
children 8b66fddd72c5
comparison
equal deleted inserted replaced
83300:6deb860255f3 83301:b151ec53c504
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-definitions (subst keymap &optional oldmap prefix) 352 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix)
353 "Applies the SUBST remapping to key bindings in KEYMAP. 353 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF.
354 SUBST will be a list of elements of the form (OLDDEF . NEWDEF). 354 In other words, OLDDEF is replaced with NEWDEF where ever it appears.
355 See `substitue-key-definition'." 355 Alternatively, if optional fourth argument OLDMAP is specified, we redefine
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)"
356 ;; Don't document PREFIX in the doc string because we don't want to 360 ;; Don't document PREFIX in the doc string because we don't want to
357 ;; advertise it. It's meant for recursive calls only. Here's its 361 ;; advertise it. It's meant for recursive calls only. Here's its
358 ;; meaning 362 ;; meaning
359 363
360 ;; If optional argument PREFIX is specified, it should be a key 364 ;; If optional argument PREFIX is specified, it should be a key
368 ;; Scan OLDMAP, finding each char or event-symbol that 372 ;; Scan OLDMAP, finding each char or event-symbol that
369 ;; has any definition, and act on it with hack-key. 373 ;; has any definition, and act on it with hack-key.
370 (map-keymap 374 (map-keymap
371 (lambda (char defn) 375 (lambda (char defn)
372 (aset prefix1 (length prefix) char) 376 (aset prefix1 (length prefix) char)
373 (substitute-key-definitions-key defn subst prefix1 keymap)) 377 (substitute-key-definition-key defn olddef newdef prefix1 keymap))
374 scan))) 378 scan)))
375 379
376 (defun substitute-key-definition (olddef newdef keymap &optional oldmap prefix) 380 (defun substitute-key-definition-key (defn olddef newdef prefix keymap)
377 "Replace OLDDEF with NEWDEF for any keys in KEYMAP now defined as OLDDEF. 381 (let (inner-def skipped menu-item)
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)
395 ;; Find the actual command name within the binding. 382 ;; Find the actual command name within the binding.
396 (if (eq (car-safe defn) 'menu-item) 383 (if (eq (car-safe defn) 'menu-item)
397 (setq menu-item defn defn (nth 2 defn)) 384 (setq menu-item defn defn (nth 2 defn))
398 ;; Skip past menu-prompt. 385 ;; Skip past menu-prompt.
399 (while (stringp (car-safe defn)) 386 (while (stringp (car-safe defn))
400 (push (pop defn) skipped)) 387 (push (pop defn) skipped))
401 ;; Skip past cached key-equivalence data for menu items. 388 ;; Skip past cached key-equivalence data for menu items.
402 (if (consp (car-safe defn)) 389 (if (consp (car-safe defn))
403 (setq defn (cdr defn)))) 390 (setq defn (cdr defn))))
404 (if (or (setq mapping (assq defn subst)) 391 (if (or (eq defn olddef)
405 ;; Compare with equal if definition is a key sequence. 392 ;; Compare with equal if definition is a key sequence.
406 ;; That is useful for operating on function-key-map. 393 ;; That is useful for operating on function-key-map.
407 (and (or (stringp defn) (vectorp defn)) 394 (and (or (stringp defn) (vectorp defn))
408 (setq mapping (assoc defn subst)))) 395 (equal defn olddef)))
409 (define-key keymap prefix 396 (define-key keymap prefix
410 (if menu-item 397 (if menu-item
411 (let ((copy (copy-sequence menu-item))) 398 (let ((copy (copy-sequence menu-item)))
412 (setcar (nthcdr 2 copy) (cdr mapping)) 399 (setcar (nthcdr 2 copy) newdef)
413 copy) 400 copy)
414 (nconc (nreverse skipped) (cdr mapping)))) 401 (nconc (nreverse skipped) newdef)))
415 ;; Look past a symbol that names a keymap. 402 ;; Look past a symbol that names a keymap.
416 (setq inner-def 403 (setq inner-def
417 (and defn 404 (and defn
418 (condition-case nil (indirect-function defn) (error defn)))) 405 (condition-case nil (indirect-function defn) (error defn))))
419 ;; For nested keymaps, we use `inner-def' rather than `defn' so as to 406 ;; For nested keymaps, we use `inner-def' rather than `defn' so as to
425 (let ((elt (lookup-key keymap prefix))) 412 (let ((elt (lookup-key keymap prefix)))
426 (or (null elt) (natnump elt) (keymapp elt))) 413 (or (null elt) (natnump elt) (keymapp elt)))
427 ;; Avoid recursively rescanning keymap being scanned. 414 ;; Avoid recursively rescanning keymap being scanned.
428 (not (memq inner-def key-substitution-in-progress))) 415 (not (memq inner-def key-substitution-in-progress)))
429 ;; If this one isn't being scanned already, scan it now. 416 ;; If this one isn't being scanned already, scan it now.
430 (substitute-key-definitions subst keymap inner-def prefix))))) 417 (substitute-key-definition olddef newdef keymap inner-def prefix)))))
431 418
432 (defun define-key-after (keymap key definition &optional after) 419 (defun define-key-after (keymap key definition &optional after)
433 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding. 420 "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
434 This is like `define-key' except that the binding for KEY is placed 421 This is like `define-key' except that the binding for KEY is placed
435 just after the binding for the event AFTER, instead of at the beginning 422 just after the binding for the event AFTER, instead of at the beginning
764 (nth 9 position)) 751 (nth 9 position))
765 752
766 753
767 ;;;; Obsolescent names for functions. 754 ;;;; Obsolescent names for functions.
768 755
769 (defalias 'dot 'point)
770 (defalias 'dot-marker 'point-marker)
771 (defalias 'dot-min 'point-min)
772 (defalias 'dot-max 'point-max)
773 (defalias 'window-dot 'window-point) 756 (defalias 'window-dot 'window-point)
774 (defalias 'set-window-dot 'set-window-point) 757 (defalias 'set-window-dot 'set-window-point)
775 (defalias 'read-input 'read-string) 758 (defalias 'read-input 'read-string)
776 (defalias 'send-string 'process-send-string) 759 (defalias 'send-string 'process-send-string)
777 (defalias 'send-region 'process-send-region) 760 (defalias 'send-region 'process-send-region)
778 (defalias 'show-buffer 'set-window-buffer) 761 (defalias 'show-buffer 'set-window-buffer)
779 (defalias 'buffer-flush-undo 'buffer-disable-undo)
780 (defalias 'eval-current-buffer 'eval-buffer) 762 (defalias 'eval-current-buffer 'eval-buffer)
781 (defalias 'compiled-function-p 'byte-code-function-p) 763
782 (defalias 'define-function 'defalias)
783
784 (defalias 'sref 'aref)
785 (make-obsolete 'sref 'aref "20.4")
786 (make-obsolete 'char-bytes "now always returns 1." "20.4") 764 (make-obsolete 'char-bytes "now always returns 1." "20.4")
787 (make-obsolete 'chars-in-region "use (abs (- BEG END))." "20.3")
788 (make-obsolete 'dot 'point "before 19.15")
789 (make-obsolete 'dot-max 'point-max "before 19.15")
790 (make-obsolete 'dot-min 'point-min "before 19.15")
791 (make-obsolete 'dot-marker 'point-marker "before 19.15")
792 (make-obsolete 'buffer-flush-undo 'buffer-disable-undo "before 19.15")
793 (make-obsolete 'baud-rate "use the `baud-rate' variable instead." "before 19.15") 765 (make-obsolete 'baud-rate "use the `baud-rate' variable instead." "before 19.15")
794 (make-obsolete 'compiled-function-p 'byte-code-function-p "before 19.15")
795 (make-obsolete 'define-function 'defalias "20.1")
796 (make-obsolete 'focus-frame "it does nothing." "19.32")
797 (make-obsolete 'unfocus-frame "it does nothing." "19.32")
798 766
799 (defun insert-string (&rest args) 767 (defun insert-string (&rest args)
800 "Mocklisp-compatibility insert function. 768 "Mocklisp-compatibility insert function.
801 Like the function `insert' except that any argument that is a number 769 Like the function `insert' except that any argument that is a number
802 is converted into a string by expressing it in decimal." 770 is converted into a string by expressing it in decimal."
809 ;; Some programs still use this as a function. 777 ;; Some programs still use this as a function.
810 (defun baud-rate () 778 (defun baud-rate ()
811 "Return the value of the `baud-rate' variable." 779 "Return the value of the `baud-rate' variable."
812 baud-rate) 780 baud-rate)
813 781
814 (defalias 'focus-frame 'ignore "")
815 (defalias 'unfocus-frame 'ignore "")
816
817 782
818 ;;;; Obsolescence declarations for variables, and aliases. 783 ;;;; Obsolescence declarations for variables, and aliases.
819 784
820 (make-obsolete-variable 'directory-sep-char "do not use it." "21.1") 785 (make-obsolete-variable 'directory-sep-char "do not use it." "21.1")
821 (make-obsolete-variable 'mode-line-inverse-video "use the appropriate faces instead." "21.1") 786 (make-obsolete-variable 'mode-line-inverse-video "use the appropriate faces instead." "21.1")
822 (make-obsolete-variable 'unread-command-char 787 (make-obsolete-variable 'unread-command-char
823 "use `unread-command-events' instead. That variable is a list of events to reread, so it now uses nil to mean `no event', instead of -1." 788 "use `unread-command-events' instead. That variable is a list of events to reread, so it now uses nil to mean `no event', instead of -1."
824 "before 19.15") 789 "before 19.15")
825 (make-obsolete-variable 'executing-macro 'executing-kbd-macro "before 19.34")
826 (make-obsolete-variable 'post-command-idle-hook 790 (make-obsolete-variable 'post-command-idle-hook
827 "use timers instead, with `run-with-idle-timer'." "before 19.34") 791 "use timers instead, with `run-with-idle-timer'." "before 19.34")
828 (make-obsolete-variable 'post-command-idle-delay 792 (make-obsolete-variable 'post-command-idle-delay
829 "use timers instead, with `run-with-idle-timer'." "before 19.34") 793 "use timers instead, with `run-with-idle-timer'." "before 19.34")
794
795 ;; Lisp manual only updated in 22.1.
796 (define-obsolete-variable-alias 'executing-macro 'executing-kbd-macro
797 "before 19.34")
830 798
831 (defvaralias 'x-lost-selection-hooks 'x-lost-selection-functions) 799 (defvaralias 'x-lost-selection-hooks 'x-lost-selection-functions)
832 (make-obsolete-variable 'x-lost-selection-hooks 'x-lost-selection-functions "22.1") 800 (make-obsolete-variable 'x-lost-selection-hooks 'x-lost-selection-functions "22.1")
833 (defvaralias 'x-sent-selection-hooks 'x-sent-selection-functions) 801 (defvaralias 'x-sent-selection-hooks 'x-sent-selection-functions)
834 (make-obsolete-variable 'x-sent-selection-hooks 'x-sent-selection-functions "22.1") 802 (make-obsolete-variable 'x-sent-selection-hooks 'x-sent-selection-functions "22.1")
2315 (defun syntax-class (syntax) 2283 (defun syntax-class (syntax)
2316 "Return the syntax class part of the syntax descriptor SYNTAX. 2284 "Return the syntax class part of the syntax descriptor SYNTAX.
2317 If SYNTAX is nil, return nil." 2285 If SYNTAX is nil, return nil."
2318 (and syntax (logand (car syntax) 65535))) 2286 (and syntax (logand (car syntax) 65535)))
2319 2287
2320 (defun add-to-invisibility-spec (arg) 2288 (defun add-to-invisibility-spec (element)
2321 "Add elements to `buffer-invisibility-spec'. 2289 "Add ELEMENT to `buffer-invisibility-spec'.
2322 See documentation for `buffer-invisibility-spec' for the kind of elements 2290 See documentation for `buffer-invisibility-spec' for the kind of elements
2323 that can be added." 2291 that can be added."
2324 (if (eq buffer-invisibility-spec t) 2292 (if (eq buffer-invisibility-spec t)
2325 (setq buffer-invisibility-spec (list t))) 2293 (setq buffer-invisibility-spec (list t)))
2326 (setq buffer-invisibility-spec 2294 (setq buffer-invisibility-spec
2327 (cons arg buffer-invisibility-spec))) 2295 (cons element buffer-invisibility-spec)))
2328 2296
2329 (defun remove-from-invisibility-spec (arg) 2297 (defun remove-from-invisibility-spec (element)
2330 "Remove elements from `buffer-invisibility-spec'." 2298 "Remove ELEMENT from `buffer-invisibility-spec'."
2331 (if (consp buffer-invisibility-spec) 2299 (if (consp buffer-invisibility-spec)
2332 (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec)))) 2300 (setq buffer-invisibility-spec (delete element buffer-invisibility-spec))))
2333 2301
2334 (defun global-set-key (key command) 2302 (defun global-set-key (key command)
2335 "Give KEY a global binding as COMMAND. 2303 "Give KEY a global binding as COMMAND.
2336 COMMAND is the command definition to use; usually it is 2304 COMMAND is the command definition to use; usually it is
2337 a symbol naming an interactively-callable function. 2305 a symbol naming an interactively-callable function.