]> code.delx.au - gnu-emacs/blobdiff - lisp/subr.el
(display-time-string-forms): Test display-time-day-and-date
[gnu-emacs] / lisp / subr.el
index 0c72ed1538e5847fb30d5605c5276ce69c2d31f9..ccd08a52cd0fda1b5e6cb288ad081cb6abb8d4f8 100644 (file)
@@ -46,10 +46,14 @@ BODY should be a list of lisp expressions."
 (defmacro when (cond &rest body)
   "(when COND BODY...): if COND yields non-nil, do BODY, else return nil."
   (list 'if cond (cons 'progn body)))
+(put 'when 'lisp-indent-function 1)
+(put 'when 'edebug-form-spec '(&rest form))
 
 (defmacro unless (cond &rest body)
   "(unless COND BODY...): if COND yields nil, do BODY, else return nil."
   (cons 'if (cons cond (cons nil body))))
+(put 'unless 'lisp-indent-function 1)
+(put 'unless 'edebug-form-spec '(&rest form))
 \f
 ;;;; Keymap support.
 
@@ -121,7 +125,11 @@ in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
              (while (and (symbolp inner-def)
                          (fboundp inner-def))
                (setq inner-def (symbol-function inner-def)))
-             (if (eq defn olddef)
+             (if (or (eq defn olddef)
+                     ;; Compare with equal if definition is a key sequence.
+                     ;; That is useful for operating on function-key-map.
+                     (and (or (stringp defn) (vectorp defn))
+                          (equal defn olddef)))
                  (define-key keymap prefix1 (nconc (nreverse skipped) newdef))
                (if (and (keymapp defn)
                         ;; Avoid recursively scanning
@@ -158,7 +166,9 @@ in KEYMAP as NEWDEF those chars which are defined as OLDDEF in OLDMAP."
                    (while (and (symbolp inner-def)
                                (fboundp inner-def))
                      (setq inner-def (symbol-function inner-def)))
-                   (if (eq defn olddef)
+                   (if (or (eq defn olddef)
+                           (and (or (stringp defn) (vectorp defn))
+                                (equal defn olddef)))
                        (define-key keymap prefix1
                          (nconc (nreverse skipped) newdef))
                      (if (and (keymapp defn)
@@ -216,6 +226,12 @@ The order of bindings in a keymap matters when it is used as a menu."
            (setq inserted t)))
       (setq tail (cdr tail)))))
 
+(defmacro kbd (keys)
+  "Convert KEYS to the internal Emacs key representation.
+KEYS should be a string constant in the format used for
+saving keyboard macros (see `insert-kbd-macro')."
+  (read-kbd-macro keys))
+
 (put 'keyboard-translate-table 'char-table-extra-slots 0)
 
 (defun keyboard-translate (from to)
@@ -857,20 +873,24 @@ If SEPARATORS is absent, it defaults to \"[ \\f\\t\\n\\r\\v]+\"."
       argument
     (if (eq system-type 'windows-nt)
        (concat "\"" argument "\"")
-      ;; Quote everything except POSIX filename characters.
-      ;; This should be safe enough even for really weird shells.
-      (let ((result "") (start 0) end)
-       (while (string-match "[^-0-9a-zA-Z_./]" argument start)
-         (setq end (match-beginning 0)
-               result (concat result (substring argument start end)
-                              "\\" (substring argument end (1+ end)))
-               start (1+ end)))
-       (concat result (substring argument start))))))
+      (if (equal argument "")
+         "''"
+       ;; Quote everything except POSIX filename characters.
+       ;; This should be safe enough even for really weird shells.
+       (let ((result "") (start 0) end)
+         (while (string-match "[^-0-9a-zA-Z_./]" argument start)
+           (setq end (match-beginning 0)
+                 result (concat result (substring argument start end)
+                                "\\" (substring argument end (1+ end)))
+                 start (1+ end)))
+         (concat result (substring argument start)))))))
 
 (defun make-syntax-table (&optional oldtable)
   "Return a new syntax table.
-It inherits all letters and control characters from the standard
-syntax table; other characters are copied from the standard syntax table."
+If OLDTABLE is non-nil, copy OLDTABLE.
+Otherwise, create a syntax table which inherits
+all letters and control characters from the standard syntax table;
+other characters are copied from the standard syntax table."
   (if oldtable
       (copy-syntax-table oldtable)
     (let ((table (copy-syntax-table))
@@ -901,13 +921,13 @@ that can be added."
    ((or (null buffer-invisibility-spec) (eq buffer-invisibility-spec t))
        (setq buffer-invisibility-spec (list arg)))
    (t
-    (setq buffer-invisibility-spec 
-         (nconc buffer-invisibility-spec (list arg))))))
+    (setq buffer-invisibility-spec
+         (cons arg buffer-invisibility-spec)))))
 
 (defun remove-from-invisibility-spec (arg)
   "Remove elements from `buffer-invisibility-spec'."
   (if buffer-invisibility-spec
-    (setq buffer-invisibility-spec (delete* arg buffer-invisibility-spec))))
+    (setq buffer-invisibility-spec (delete arg buffer-invisibility-spec))))
 \f
 (defun global-set-key (key command)
   "Give KEY a global binding as COMMAND.
@@ -963,6 +983,12 @@ configuration."
   (and (consp object)
        (eq (car object) 'frame-configuration)))
 
+(defun functionp (object)
+  "Non-nil of OBJECT is a type of object that can be called as a function."
+  (or (subrp object) (compiled-function-p object)
+      (eq (car-safe object) 'lambda)
+      (and (symbolp object) (fboundp object))))
+
 ;; now in fns.c
 ;(defun nth (n list)
 ;  "Returns the Nth element of LIST.