X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/5ab243f40e4db91586ff74b01a775a5218a1d5be..5942c18e9a4f04996d80071b717049f55c1f69d8:/lisp/subr.el diff --git a/lisp/subr.el b/lisp/subr.el index 6eea54f2a3..afc86a77f8 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -66,6 +66,7 @@ For more information, see Info node `(elisp)Declaring Functions'." ;;;; Basic Lisp macros. (defalias 'not 'null) +(defalias 'sxhash 'sxhash-equal) (defmacro noreturn (form) "Evaluate FORM, expecting it not to return. @@ -619,8 +620,10 @@ side-effects, and the argument LIST is not modified." (defun 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 `edmacro-mode')." +KEYS should be a string in the format returned by commands such +as `C-h k' (`describe-key'). +This is the same format used for saving keyboard macros (see +`edmacro-mode')." ;; Don't use a defalias, since the `pure' property is only true for ;; the calling convention of `kbd'. (read-kbd-macro keys)) @@ -846,7 +849,12 @@ above 127 (such as ISO Latin-1) can be included if you use a vector. Note that if KEY has a local binding in the current buffer, that local binding will continue to shadow any global binding that you make with this function." - (interactive "KSet key globally: \nCSet key %s to command: ") + (interactive + (let* ((menu-prompting nil) + (key (read-key-sequence "Set key globally: "))) + (list key + (read-command (format "Set key %s to command: " + (key-description key)))))) (or (vectorp key) (stringp key) (signal 'wrong-type-argument (list 'arrayp key))) (define-key (current-global-map) key command)) @@ -1320,7 +1328,9 @@ is converted into a string by expressing it in decimal." ;; buffer-local. ;; Not used at all in Emacs, last time I checked: -(make-obsolete-variable 'default-mode-line-format 'mode-line-format "23.2") +(make-obsolete-variable 'default-mode-line-format + "use (setq-default mode-line-format) or (default-value mode-line-format) instead" + "23.2") (make-obsolete-variable 'default-header-line-format 'header-line-format "23.2") (make-obsolete-variable 'default-line-spacing 'line-spacing "23.2") (make-obsolete-variable 'default-abbrev-mode 'abbrev-mode "23.2") @@ -2086,6 +2096,10 @@ some sort of escape sequence, the ambiguity is resolved via `read-key-delay'." (aref keys 1) key))) (cancel-timer timer) + ;; For some reason, `read-key(-sequence)' leaves the prompt in the echo + ;; area, whereas `read-event' seems to empty it just before returning + ;; (bug#22714). So, let's mimic the behavior of `read-event'. + (message nil) (use-global-map old-global-map)))) (defvar read-passwd-map @@ -2244,6 +2258,14 @@ might be shortened), and the third, optional entry is a longer explanation that will be displayed in a help buffer if the user requests more help. +This function translates user input into responses by consulting +the bindings in `query-replace-map'; see the documentation of +that variable for more information. In this case, the useful +bindings are `recenter', `scroll-up', and `scroll-down'. If the +user enters `recenter', `scroll-up', or `scroll-down' responses, +perform the requested window recentering or scrolling and ask +again. + The return value is the matching entry from the CHOICES list. Usage example: @@ -2288,7 +2310,7 @@ Usage example: altered-name)) (append choices '((?? "?"))) ", "))) - tchar buf wrong-char) + tchar buf wrong-char answer) (save-window-excursion (save-excursion (while (not tchar) @@ -2314,9 +2336,27 @@ Usage example: (let ((cursor-in-echo-area t)) (read-char)) (error nil)))) + (setq answer (lookup-key query-replace-map (vector tchar) t)) + (setq tchar + (cond + ((eq answer 'recenter) + (recenter) t) + ((eq answer 'scroll-up) + (ignore-errors (scroll-up-command)) t) + ((eq answer 'scroll-down) + (ignore-errors (scroll-down-command)) t) + ((eq answer 'scroll-other-window) + (ignore-errors (scroll-other-window)) t) + ((eq answer 'scroll-other-window-down) + (ignore-errors (scroll-other-window-down)) t) + (t tchar))) + (when (eq tchar t) + (setq wrong-char nil + tchar nil)) ;; The user has entered an invalid choice, so display the ;; help messages. - (when (not (assq tchar choices)) + (when (and (not (eq tchar nil)) + (not (assq tchar choices))) (setq wrong-char (not (memq tchar '(?? ?\C-h))) tchar nil) (when wrong-char @@ -2445,7 +2485,8 @@ floating point support." (declare-function x-popup-dialog "menu.c" (position contents &optional header)) (defun y-or-n-p (prompt) - "Ask user a \"y or n\" question. Return t if answer is \"y\". + "Ask user a \"y or n\" question. +Return t if answer is \"y\" and nil if it is \"n\". PROMPT is the string to display to ask the question. It should end in a space; `y-or-n-p' adds \"(y or n) \" to it. @@ -3421,6 +3462,8 @@ See also `with-temp-file' and `with-output-to-string'." (defmacro with-silent-modifications (&rest body) "Execute BODY, pretending it does not modify the buffer. +This macro is Typically used around modifications of +text-properties which do not really affect the buffer's content. If BODY performs real modifications to the buffer's text, other than cosmetic ones, undo data may become corrupted. @@ -3428,10 +3471,7 @@ This macro will run BODY normally, but doesn't count its buffer modifications as being buffer modifications. This affects things like `buffer-modified-p', checking whether the file is locked by someone else, running buffer modification hooks, and other things -of that nature. - -Typically used around modifications of text-properties which do -not really affect the buffer's content." +of that nature." (declare (debug t) (indent 0)) (let ((modified (make-symbol "modified"))) `(let* ((,modified (buffer-modified-p)) @@ -4080,7 +4120,8 @@ This function makes or adds to an entry on `after-load-alist'." (defmacro with-eval-after-load (file &rest body) "Execute BODY after FILE is loaded. FILE is normally a feature name, but it can also be a file name, -in case that file does not provide any feature." +in case that file does not provide any feature. See `eval-after-load' +for more details about the different forms of FILE and their semantics." (declare (indent 1) (debug t)) `(eval-after-load ,file (lambda () ,@body))) @@ -4241,6 +4282,39 @@ If SYNTAX is nil, return nil." ;; Utility motion commands +(defvar word-move-empty-char-table nil + "Used in `forward-word-strictly' and `backward-word-strictly' +to countermand the effect of `find-word-boundary-function-table'.") + +(defun forward-word-strictly (&optional arg) + "Move point forward ARG words (backward if ARG is negative). +If ARG is omitted or nil, move point forward one word. +Normally returns t. +If an edge of the buffer or a field boundary is reached, point is left there +and the function returns nil. Field boundaries are not noticed if +`inhibit-field-text-motion' is non-nil. + +This function is like `forward-word', but it is not affected +by `find-word-boundary-function-table'. It is also not interactive." + (let ((find-word-boundary-function-table + (if (char-table-p word-move-empty-char-table) + word-move-empty-char-table + (setq word-move-empty-char-table (make-char-table nil))))) + (forward-word (or arg 1)))) + +(defun backward-word-strictly (&optional arg) + "Move backward until encountering the beginning of a word. +With argument ARG, do this that many times. +If ARG is omitted or nil, move point backward one word. + +This function is like `forward-word', but it is not affected +by `find-word-boundary-function-table'. It is also not interactive." + (let ((find-word-boundary-function-table + (if (char-table-p word-move-empty-char-table) + word-move-empty-char-table + (setq word-move-empty-char-table (make-char-table nil))))) + (forward-word (- (or arg 1))))) + ;; Whitespace (defun forward-whitespace (arg)