(scheme-mode-variables): Set comment-start-skip to ignore backslash-quoted
[bpt/emacs.git] / lisp / subr.el
index c923967..f5087fc 100644 (file)
@@ -1,6 +1,6 @@
 ;;; subr.el --- basic lisp subroutines for Emacs
 
-;;; Copyright (C) 1985, 1986, 1992, 1994, 1995 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1986, 1992, 1994, 1995 Free Software Foundation, Inc.
 
 ;; This file is part of GNU Emacs.
 
@@ -15,8 +15,9 @@
 ;; GNU General Public License for more details.
 
 ;; You should have received a copy of the GNU General Public License
-;; along with GNU Emacs; see the file COPYING.  If not, write to
-;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
 
 ;;; Code:
 
@@ -129,7 +130,9 @@ in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
                (if (and (keymapp defn)
                         ;; Avoid recursively scanning
                         ;; where KEYMAP does not have a submap.
-                        (keymapp (lookup-key keymap prefix1))
+                        (let ((elt (lookup-key keymap prefix1)))
+                          (or (null elt)
+                              (keymapp elt)))
                         ;; Avoid recursively rescanning keymap being scanned.
                         (not (memq inner-def
                                    key-substitution-in-progress)))
@@ -163,7 +166,9 @@ in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
                        (define-key keymap prefix1
                          (nconc (nreverse skipped) newdef))
                      (if (and (keymapp defn)
-                              (keymapp (lookup-key keymap prefix1))
+                              (let ((elt (lookup-key keymap prefix1)))
+                                (or (null elt)
+                                    (keymapp elt)))
                               (not (memq inner-def
                                          key-substitution-in-progress)))
                          (substitute-key-definition olddef newdef keymap
@@ -448,122 +453,11 @@ Please convert your programs to use the variable `baud-rate' directly."
 \f
 ;;;; Hook manipulation functions.
 
-(defun run-hooks (&rest hooklist)
-  "Takes hook names and runs each one in turn.  Major mode functions use this.
-Each argument should be a symbol, a hook variable.
-These symbols are processed in the order specified.
-If a hook symbol has a non-nil value, that value may be a function
-or a list of functions to be called to run the hook.
-If the value is a function, it is called with no arguments.
-If it is a list, the elements are called, in order, with no arguments.
-
-To make a hook variable buffer-local, use `make-local-hook', not
-`make-local-variable'."
-  (while hooklist
-    (let ((sym (car hooklist)))
-      (and (boundp sym)
-          (symbol-value sym)
-          (let ((value (symbol-value sym)))
-            (if (and (listp value) (not (eq (car value) 'lambda)))
-                (while value
-                  (if (eq (car value) t)
-                      ;; t indicates this hook has a local binding;
-                      ;; it means to run the global binding too.
-                      (let ((functions (default-value sym)))
-                        (while functions
-                          (funcall (car functions))
-                          (setq functions (cdr functions))))
-                    (funcall (car value)))
-                  (setq value (cdr value)))
-              (funcall value)))))
-    (setq hooklist (cdr hooklist))))
-
-(defun run-hook-with-args (hook &rest args)
-  "Run HOOK with the specified arguments ARGS.
-HOOK should be a symbol, a hook variable.  If HOOK has a non-nil
-value, that value may be a function or a list of functions to be
-called to run the hook.  If the value is a function, it is called with
-the given arguments and its return value is returned.  If it is a list
-of functions, those functions are called, in order,
-with the given arguments ARGS.
-It is best not to depend on the value return by `run-hook-with-args',
-as that may change.
-
-To make a hook variable buffer-local, use `make-local-hook', not
-`make-local-variable'."
-  (and (boundp hook)
-       (symbol-value hook)
-       (let ((value (symbol-value hook)))
-        (if (and (listp value) (not (eq (car value) 'lambda)))
-            (while value
-              (if (eq (car value) t)
-                  ;; t indicates this hook has a local binding;
-                  ;; it means to run the global binding too.
-                  (let ((functions (default-value hook)))
-                    (while functions
-                      (apply (car functions) args)
-                      (setq functions (cdr functions))))
-                (apply (car value) args))
-              (setq value (cdr value)))
-          (apply value args)))))
-
-(defun run-hook-with-args-until-success (hook &rest args)
-  "Run HOOK with the specified arguments ARGS.
-HOOK should be a symbol, a hook variable.  Its value should
-be a list of functions.  We call those functions, one by one,
-passing arguments ARGS to each of them, until one of them
-returns a non-nil value.  Then we return that value.
-If all the functions return nil, we return nil.
-
-To make a hook variable buffer-local, use `make-local-hook', not
-`make-local-variable'."
-  (and (boundp hook)
-       (symbol-value hook)
-       (let ((value (symbol-value hook))
-            success)
-        (while (and value (not success))
-          (if (eq (car value) t)
-              ;; t indicates this hook has a local binding;
-              ;; it means to run the global binding too.
-              (let ((functions (default-value hook)))
-                (while (and functions (not success))
-                  (setq success (apply (car functions) args))
-                  (setq functions (cdr functions))))
-            (setq success (apply (car value) args)))
-          (setq value (cdr value)))
-        success)))
-
-(defun run-hook-with-args-until-failure (hook &rest args)
-  "Run HOOK with the specified arguments ARGS.
-HOOK should be a symbol, a hook variable.  Its value should
-be a list of functions.  We call those functions, one by one,
-passing arguments ARGS to each of them, until one of them
-returns nil.  Then we return nil.
-If all the functions return non-nil, we return non-nil.
-
-To make a hook variable buffer-local, use `make-local-hook', not
-`make-local-variable'."
-  ;; We must return non-nil if there are no hook functions!
-  (or (not (boundp hook))
-      (not (symbol-value hook))
-      (let ((value (symbol-value hook))
-           (success t))
-       (while (and value success)
-         (if (eq (car value) t)
-             ;; t indicates this hook has a local binding;
-             ;; it means to run the global binding too.
-             (let ((functions (default-value hook)))
-               (while (and functions success)
-                 (setq success (apply (car functions) args))
-                 (setq functions (cdr functions))))
-           (setq success (apply (car value) args)))
-         (setq value (cdr value)))
-       success)))
-
-;; Tell C code how to call this function.
+;; We used to have this variable so that C code knew how to run hooks.  That
+;; calling convention is made obsolete now the hook running functions are in C.
 (defconst run-hooks 'run-hooks
   "Variable by which C primitives find the function `run-hooks'.
-Don't change it.")
+Don't change it.  Don't use it either; use the hook running C primitives.")
 
 (defun make-local-hook (hook)
   "Make the hook HOOK local to the current buffer.
@@ -672,6 +566,7 @@ To make a hook variable buffer-local, always use
 
 (defun add-to-list (list-var element)
   "Add to the value of LIST-VAR the element ELEMENT if it isn't there yet.
+The test for presence of ELEMENT is done with `equal'.
 If you want to use `add-to-list' on a variable that is not defined
 until a certain package is loaded, you should put the call to `add-to-list'
 into a hook function that will be run only after loading the package.
@@ -730,8 +625,7 @@ or three octal digits representing its character code."))
            ((and (<= ?0 char) (<= char ?7))
             (setq code (+ (* code 8) (- char ?0))
                   count (1+ count))
-            (and prompt (message (setq prompt
-                                       (format "%s %c" prompt char)))))
+            (and prompt (setq prompt (message "%s %c" prompt char))))
            ((> count 0)
             (setq unread-command-events (list char) count 259))
            (t (setq code char count 259))))
@@ -803,6 +697,17 @@ This variable is meaningful on MS-DOG and Windows NT.
 On those systems, it is automatically local in every buffer.
 On other systems, this variable is normally always nil.")
 
+;; This should probably be written in C (i.e., without using `walk-windows').
+(defun get-buffer-window-list (buffer &optional minibuf frame)
+  "Return windows currently displaying BUFFER, or nil if none.
+See `walk-windows' for the meaning of MINIBUF and FRAME."
+  (let ((buffer (if (bufferp buffer) buffer (get-buffer buffer))) windows)
+    (walk-windows (function (lambda (window)
+                             (if (eq (window-buffer window) buffer)
+                                 (setq windows (cons window windows)))))
+                 minibuf frame)
+    windows))
+
 (defun ignore (&rest ignore)
   "Do nothing and return nil.
 This function accepts any number of arguments, but ignores them."
@@ -810,7 +715,10 @@ This function accepts any number of arguments, but ignores them."
   nil)
 
 (defun error (&rest args)
-  "Signal an error, making error message by passing all args to `format'."
+  "Signal an error, making error message by passing all args to `format'.
+In Emacs, the convention is that error messages start with a capital
+letter but *do not* end with a period.  Please follow this convention
+for the sake of consistency."
   (while t
     (signal 'error (list (apply 'format args)))))
 
@@ -856,12 +764,6 @@ STRING should be given if the last search was by `string-match' on STRING."
          (substring string (match-beginning num) (match-end num))
        (buffer-substring (match-beginning num) (match-end num)))))
 
-(defun buffer-substring-no-properties (beg end)
-  "Return the text from BEG to END, without text properties, as a string."
-  (let ((string (buffer-substring beg end)))
-    (set-text-properties 0 (length string) nil string)
-    string))
-
 (defun shell-quote-argument (argument)
   "Quote an argument for passing as argument to an inferior shell."
   (if (eq system-type 'ms-dos)
@@ -889,19 +791,19 @@ syntax table; other characters are copied from the standard syntax table."
          i)
       (setq i 0)
       (while (<= i 31)
-       (aset table i 13)
+       (aset table i nil)
        (setq i (1+ i)))
       (setq i ?A)
       (while (<= i ?Z)
-       (aset table i 13)
+       (aset table i nil)
        (setq i (1+ i)))
       (setq i ?a)
       (while (<= i ?z)
-       (aset table i 13)
+       (aset table i nil)
        (setq i (1+ i)))
       (setq i 128)
       (while (<= i 255)
-       (aset table i 13)
+       (aset table i nil)
        (setq i (1+ i)))
       table)))
 \f