(rmail-last-rmail-file): Initialize to a file name.
[bpt/emacs.git] / lisp / subr.el
index 591493e..031c7ff 100644 (file)
@@ -181,6 +181,42 @@ in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
                (setq i (1+ i))))))
       (setq scan (cdr scan)))))
 
+(defun define-key-after (keymap key definition after)
+  "Add binding in KEYMAP for KEY => DEFINITION, right after AFTER's binding.
+This is like `define-key' except that the binding for KEY is placed
+just after the binding for the event AFTER, instead of at the beginning
+of the map.
+The order matters when the keymap is used as a menu.
+KEY must contain just one event type--it must be a string or vector
+of length 1."
+  (or (keymapp keymap)
+      (signal 'wrong-type-argument (list 'keymapp keymap)))
+  (if (> (length key) 1)
+      (error "multi-event key specified in `define-key-after'"))
+  (let ((tail keymap) done inserted
+       (first (aref key 0)))
+    (while (and (not done) tail)
+      ;; Delete any earlier bindings for the same key.
+      (if (eq (car-safe (car (cdr tail))) first)
+         (setcdr tail (cdr (cdr tail))))
+      ;; When we reach AFTER's binding, insert the new binding after.
+      ;; If we reach an inherited keymap, insert just before that.
+      ;; If we reach the end of this keymap, insert at the end.
+      (if (or (eq (car-safe (car tail)) after)
+             (eq (car (cdr tail)) 'keymap)
+             (null (cdr tail)))
+         (progn
+           ;; Stop the scan only if we find a parent keymap.
+           ;; Keep going past the inserted element
+           ;; so we can delete any duplications that come later.
+           (if (eq (car (cdr tail)) 'keymap)
+               (setq done t))
+           ;; Don't insert more than once.
+           (or inserted
+               (setcdr tail (cons (cons (aref key 0) definition) (cdr tail))))
+           (setq inserted t)))
+      (setq tail (cdr tail)))))
+
 (defun keyboard-translate (from to)
   "Translate character FROM to TO at a low level.
 This function creates a `keyboard-translate-table' if necessary
@@ -191,7 +227,8 @@ and then modifies one entry in it."
          (> to   (length keyboard-translate-table)))
       (progn
        (let* ((i (length keyboard-translate-table))
-              (table (make-string (- 256 i) 0)))
+              (table (concat keyboard-translate-table
+                             (make-string (- 256 i) 0))))
          (while (< i 256)
            (aset table i i)
            (setq i (1+ i)))
@@ -230,13 +267,20 @@ The normal global definition of the character C-x indirects to this keymap.")
 \f
 ;;;; Event manipulation functions.
 
+;; This code exists specifically to make sure that the
+;; resulting number does not appear in the .elc file.
+;; The number is negative on most machines, but not on all!
+(defconst listify-key-sequence-1
+   (lsh 1 7))
+(setq listify-key-sequence-1 (logior (lsh 1 23) listify-key-sequence-1))
+
 (defun listify-key-sequence (key)
   "Convert a key sequence to a list of events."
   (if (vectorp key)
       (append key nil)
     (mapcar (function (lambda (c)
                        (if (> c 127)
-                           (logxor c ?\M-\200)
+                           (logxor c listify-key-sequence-1)
                          c)))
            (append key nil))))
 
@@ -278,6 +322,8 @@ The elements of the list may include `meta', `control',
 (defun event-basic-type (event)
   "Returns the basic type of the given event (all modifiers removed).
 The value is an ASCII printing character (not upper case) or a symbol."
+  (if (consp event)
+      (setq event (car event)))
   (if (symbolp event)
       (car (get event 'event-symbol-elements))
     (let ((base (logand event (1- (lsh 1 18)))))
@@ -304,7 +350,7 @@ If EVENT is a click event, this function is the same as `event-start'.
 The return value is of the form
    (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
 The `posn-' functions access elements of such lists."
-  (nth (1- (length event)) event))
+  (nth (if (consp (nth 2 event)) 2 1) event))
 
 (defsubst posn-window (position)
   "Return the window in POSITION.
@@ -318,7 +364,9 @@ as returned by the `event-start' and `event-end' functions."
 POSITION should be a list of the form
    (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
 as returned by the `event-start' and `event-end' functions."
-  (nth 1 position))
+  (if (consp (nth 1 position))
+      (car (nth 1 position))
+    (nth 1 position)))
 
 (defsubst posn-col-row (position)
   "Return the row and column in POSITION.
@@ -331,7 +379,7 @@ as returned by the `event-start' and `event-end' functions."
   "Return the timestamp of POSITION.
 POSITION should be a list of the form
    (WINDOW BUFFER-POSITION (COL . ROW) TIMESTAMP)
-nas returned by the `event-start' and `event-end' functions."
+as returned by the `event-start' and `event-end' functions."
   (nth 3 position))
 
 \f
@@ -361,7 +409,8 @@ nas returned by the `event-start' and `event-end' functions."
 
 ;; Some programs still use this as a function.
 (defun baud-rate ()
-  "Obsolete function returning the value of the `baud-rate' variable."
+  "Obsolete function returning the value of the `baud-rate' variable.
+Please convert your programs to use the variable `baud-rate' directly."
   baud-rate)
 
 \f
@@ -374,7 +423,7 @@ nas returned by the `event-start' and `event-end' functions."
 (defalias 'not 'null)
 (defalias 'rplaca 'setcar)
 (defalias 'rplacd 'setcdr)
-(defalias 'beep 'ding) ;preserve lingual purtity
+(defalias 'beep 'ding) ;preserve lingual purity
 (defalias 'indent-to-column 'indent-to)
 (defalias 'backward-delete-char 'delete-backward-char)
 (defalias 'search-forward-regexp (symbol-function 're-search-forward))