What you are looking for is the function parse-partial-sexp
which returns the parser state (a 10-element list!) which you can use to figure out the start and end positions of your sexp.
Anther useful function will be scan-sexps
.
UPDATE#1:
Your function get-outermost-brackets
returns the position of of the outermost open paren, not a useful part of your buffer, and that value is not going to show in the echo area anyway.
UPDATE#2:
This will send the enclosing sexp to the echo area and the *Messages*
buffer:
(defun get-enclosing-sexp (&optional pos)
(interactive)
(message "%s" (save-excursion
(goto-char (car (last (nth 9 (syntax-ppss)))))
(read (current-buffer)))))
Drop message
if you want to return the sexp from the function instead of just showing it.
Where is my million?