Function: read--expression-try-read

read--expression-try-read is an interactive and byte-compiled function defined in simple.el.gz.

Signature

(read--expression-try-read)

Documentation

Try to read an Emacs Lisp expression in the minibuffer.

Exit the minibuffer if successful, else report the error to the user and move point to the location of the error. If point is not already at the location of the error, push a mark before moving point.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun read--expression-try-read ()
  "Try to read an Emacs Lisp expression in the minibuffer.

Exit the minibuffer if successful, else report the error to the
user and move point to the location of the error.  If point is
not already at the location of the error, push a mark before
moving point."
  (interactive)
  (unless (> (minibuffer-depth) 0)
    (error "Minibuffer must be active"))
  (if (let* ((contents (minibuffer-contents))
             (error-point nil))
        (with-temp-buffer
          (condition-case err
              (progn
                (insert contents)
                (goto-char (point-min))
                ;; `read' will signal errors like "End of file during
                ;; parsing" and "Invalid read syntax".
                (read (current-buffer))
                ;; Since `read' does not signal the "Trailing garbage
                ;; following expression" error, we check for trailing
                ;; garbage ourselves.
                (or (progn
                      ;; This check is similar to what `string_to_object'
                      ;; does in minibuf.c.
                      (skip-chars-forward " \t\n")
                      (= (point) (point-max)))
                    (error "Trailing garbage following expression")))
            (error
             (setq error-point (+ (length (minibuffer-prompt)) (point)))
             (with-current-buffer (window-buffer (minibuffer-window))
               (unless (= (point) error-point)
                 (push-mark))
               (goto-char error-point)
               (minibuffer-message (error-message-string err)))
             nil))))
      (exit-minibuffer)))