]> code.delx.au - gnu-emacs/blobdiff - lisp/subr.el
(gdb-flush-pending-output): New variable.
[gnu-emacs] / lisp / subr.el
index 60e0694e55aab54ff4366f8e5585c8a62b11dc69..b40c64c63eb506432a36f9cabe5005059726df4c 100644 (file)
@@ -484,6 +484,24 @@ The order of bindings in a keymap matters when it is used as a menu."
            (setq inserted t)))
       (setq tail (cdr tail)))))
 
+(defun map-keymap-internal (function keymap &optional sort-first)
+  "Implement `map-keymap' with sorting.
+Don't call this function; it is for internal use only."
+  (if sort-first
+      (let (list)
+       (map-keymap (lambda (a b) (push (cons a b) list))
+                   keymap)
+       (setq list (sort list
+                        (lambda (a b)
+                          (setq a (car a) b (car b))
+                          (if (integerp a)
+                              (if (integerp b) (< a b)
+                                t)
+                            (if (integerp b) t
+                              (string< a b))))))
+       (dolist (p list)
+         (funcall function (car p) (cdr p))))
+    (map-keymap function keymap)))
 
 (defmacro kbd (keys)
   "Convert KEYS to the internal Emacs key representation.
@@ -817,6 +835,10 @@ is converted into a string by expressing it in decimal."
 (make-obsolete-variable 'post-command-idle-delay
   "use timers instead, with `run-with-idle-timer'." "before 19.34")
 
+(defvaralias 'x-lost-selection-hooks 'x-lost-selection-functions)
+(make-obsolete-variable 'x-lost-selection-hooks 'x-lost-selection-functions "21.4")
+(defvaralias 'x-sent-selection-hooks 'x-sent-selection-functions)
+(make-obsolete-variable 'x-sent-selection-hooks 'x-sent-selection-functions "21.4")
 \f
 ;;;; Alternate names for functions - these are not being phased out.
 
@@ -1212,51 +1234,59 @@ any other non-digit terminates the character code and is then used as input."))
     code))
 
 (defun read-passwd (prompt &optional confirm default)
-  "Read a password, prompting with PROMPT.  Echo `.' for each character typed.
-End with RET, LFD, or ESC.  DEL or C-h rubs out.  C-u kills line.
-If optional CONFIRM is non-nil, read password twice to make sure.
-Optional DEFAULT is a default password to use instead of empty input."
-  (if confirm
-      (let (success)
-       (while (not success)
-         (let ((first (read-passwd prompt nil default))
-               (second (read-passwd "Confirm password: " nil default)))
-           (if (equal first second)
-               (progn
-                 (and (arrayp second) (clear-string second))
-                 (setq success first))
-             (and (arrayp first) (clear-string first))
-             (and (arrayp second) (clear-string second))
-             (message "Password not repeated accurately; please start over")
-             (sit-for 1))))
-       success)
-    (let ((pass nil)
-         (c 0)
-         (echo-keystrokes 0)
-         (cursor-in-echo-area t))
-      (while (progn (message "%s%s"
-                            prompt
-                            (make-string (length pass) ?.))
-                   (setq c (read-char-exclusive nil t))
-                   (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
-       (clear-this-command-keys)
-       (if (= c ?\C-u)
-           (progn
-             (and (arrayp pass) (clear-string pass))
-             (setq pass ""))
-         (if (and (/= c ?\b) (/= c ?\177))
-             (let* ((new-char (char-to-string c))
-                    (new-pass (concat pass new-char)))
+  "Read a password, prompting with PROMPT, and return it.
+If optional CONFIRM is non-nil, read the password twice to make sure.
+Optional DEFAULT is a default password to use instead of empty input.
+
+This function echoes `.' for each character that the user types.
+The user ends with RET, LFD, or ESC.  DEL or C-h rubs out.  C-u kills line.
+C-g quits; if `inhibit-quit' was non-nil around this function,
+then it returns nil if the user types C-g.
+
+Once the caller uses the password, it can erase the password
+by doing (clear-string STRING)."
+  (with-local-quit
+    (if confirm
+       (let (success)
+         (while (not success)
+           (let ((first (read-passwd prompt nil default))
+                 (second (read-passwd "Confirm password: " nil default)))
+             (if (equal first second)
+                 (progn
+                   (and (arrayp second) (clear-string second))
+                   (setq success first))
+               (and (arrayp first) (clear-string first))
+               (and (arrayp second) (clear-string second))
+               (message "Password not repeated accurately; please start over")
+               (sit-for 1))))
+         success)
+      (let ((pass nil)
+           (c 0)
+           (echo-keystrokes 0)
+           (cursor-in-echo-area t))
+       (while (progn (message "%s%s"
+                              prompt
+                              (make-string (length pass) ?.))
+                     (setq c (read-char-exclusive nil t))
+                     (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
+         (clear-this-command-keys)
+         (if (= c ?\C-u)
+             (progn
                (and (arrayp pass) (clear-string pass))
-               (clear-string new-char)
-               (setq c ?\0)
-               (setq pass new-pass))
-           (if (> (length pass) 0)
-               (let ((new-pass (substring pass 0 -1)))
+               (setq pass ""))
+           (if (and (/= c ?\b) (/= c ?\177))
+               (let* ((new-char (char-to-string c))
+                      (new-pass (concat pass new-char)))
                  (and (arrayp pass) (clear-string pass))
-                 (setq pass new-pass))))))
-      (message nil)
-      (or pass default ""))))
+                 (clear-string new-char)
+                 (setq c ?\0)
+                 (setq pass new-pass))
+             (if (> (length pass) 0)
+                 (let ((new-pass (substring pass 0 -1)))
+                   (and (arrayp pass) (clear-string pass))
+                   (setq pass new-pass))))))
+       (message nil)
+       (or pass default "")))))
 
 ;; This should be used by `call-interactively' for `n' specs.
 (defun read-number (prompt &optional default)
@@ -1822,14 +1852,14 @@ See also `with-temp-file' and `with-output-to-string'."
 
 (defmacro with-local-quit (&rest body)
   "Execute BODY, allowing quits to terminate BODY but not escape further.
-When a quit terminates BODY, `with-local-quit' requests another quit when
-it finishes.  That quit will be processed in turn, the next time quitting
-is again allowed."
+When a quit terminates BODY, `with-local-quit' returns nil but
+requests another quit.  That quit will be processed, the next time quitting
+is allowed once again."
   (declare (debug t) (indent 0))
   `(condition-case nil
        (let ((inhibit-quit nil))
         ,@body)
-     (quit (setq quit-flag t))))
+     (quit (setq quit-flag t) nil)))
 
 (defmacro combine-after-change-calls (&rest body)
   "Execute BODY, but don't call the after-change functions till the end.
@@ -2023,11 +2053,12 @@ STRING should be given if the last search was by `string-match' on STRING."
 
 (defun looking-back (regexp &optional limit)
   "Return non-nil if text before point matches regular expression REGEXP.
-Like `looking-at' except backwards and slower.
+Like `looking-at' except matches before point, and is slower.
 LIMIT if non-nil speeds up the search by specifying how far back the
 match can start."
-  (save-excursion
-    (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t)))
+  (not (null
+       (save-excursion
+         (re-search-backward (concat "\\(?:" regexp "\\)\\=") limit t)))))
 
 (defconst split-string-default-separators "[ \f\t\n\r\v]+"
   "The default value of separators for `split-string'.
@@ -2196,7 +2227,7 @@ from `standard-syntax-table' otherwise."
     table))
 
 (defun syntax-after (pos)
-  "Return the syntax of the char after POS."
+  "Return the raw syntax of the char after POS."
   (unless (or (< pos (point-min)) (>= pos (point-max)))
     (let ((st (if parse-sexp-lookup-properties
                  (get-char-property pos 'syntax-table))))