As mentioned in the comments you can tweak eval-expression-print-* or expand by hitting RET or mouse-2 on the ellipses (which calls last-sexp-toggle-display). However probably the most useful for general messing around in the *scratch* buffer is:
Which will format the output in a more readable way.
Rather than up-list I'd recommend you use (syntax-ppss) which will return to you some parsing state. This will include info about whether you're inside a string or a comment, the position of the last open "paren" etc...
E.g. you can find the kind of paren with
(let ((ppss (syntax-ppss)))
(when (nth 1 ppss) (char-after (nth 1 ppss))))
and it should ...
This isn't really an answer, but...
if I was talking to someone, how does one say this word?
I tend to pronounce it "form" :)
C-hig (elisp)Intro Eval says:
A Lisp object that is intended for evaluation is called a “form” or “expression”(1).
(1) It is sometimes also referred to as an “S-expression” or “sexp”, but we generally do not use this ...
Here's what's happening, for the second case. You have this in the buffer, with point at position 1 (beginning of buffer): (a) (b) (c)
After the first forward-sexp point is just after the first right paren ()).
The next (sexp-at-point) returns the first sexp, not the second. Why? Because point is not on the second list ((b)), and it is just after the ...
The problem is that with-temp-buffer puts the buffer in a fundamental mode, and you are counting on it being in a Lisp mode, such as emacs-lisp-mode. So comments and sexps are not what you are expecting.
(scan-sexps 12 1))
;; => 54
If you want to write your own use the contents of (syntax-ppss (point)) which you give you the positions of matching pairs in the current context amongst other data. Read the docs for syntax-ppss for more info.
But you don't need to implement the function, you can use forward-sexp and backward-sexp to jump between matching pairs. bound by default to C-M-f ...
Please check out Moving in the Parenthesis Structure, specifically:
C-M-f, which runs the command forward-sexp
C-M-b, which runs the command backward-sexp
C-M-d, which runs the command down-list
To get to the beginning of the 1st child, enter the list, then jump behind the 1st child and back to arrive at its beginning:
C-M-d C-M-f C-M-b
An implementation of this command was provided around 20 years ago, unfortunately forgot the source.
Here a basic approach:
(defun ar-simple-match-paren ()
"Jump between matching paren. "
(cond ((eq 4 (car (syntax-after (point))))
((eq 5 (car (syntax-after (point))))
You did not implement alamo-forward-sexp correctly. If point is at begin_data almo-forward-sexp does not go to the block end, i.e., to the end of end_data but to the end of alamo-forward-sexp.
A fairly complete alamo-forward-sexp must treat nested sexps correctly. Something like that is most often done via a stack. Below I give a simple version of a stack ...
I think you should be able to do something like this:
emacsclient -e '(pp (with-temp-buffer (insert-file-contents "my-file-containing sexp") (read (current-buffer))))'
The problem is that this will print a string (e.g., "[foo\n bar]"), so to see it on the screen you will need
echo -e $(emacsclient ...)
You can control the behavior of pp with many ...
Yes, that's the way forward-comment works (likewise forward-sexp).
To quote Stefan, from part of bug #8667:
The forward-THINGY functions all share the following property AFAIK:
when called with a positive argument with point before some
THINGIES, they will skip over that many THINGIES and when called
with a negative argument with point after some ...
While forward-sexp works just fine for me on the code in question (in Emacs 27.0.50), the standard workaround is to add a single backslash, e.g., "^\(defun ".
One place where it actually is needed is when doc string contains code.
Emacs uses a simple heuristic ("line starting with a paren starts a function") for beginning-of-defun and code like this:
After stepping through the latex-forward-sexp-1 function from tex-mode (long live edebug!), I figured out why it works in tex-mode buffers, but not in AucTeX: it's because tex-mode gives the backslash syntax class /, but AucTeX gives it syntax class \!
So, I've simply added this to my AucTeX configuration to get tex-mode's better sexp-navigation:
Here is the whole paragraph.
If the beginning or end of (the accessible part of) the buffer is reached
in the middle of a parenthetical grouping, an error is signaled.
If the beginning or end is reached between groupings
but before count is used up, nil is returned.
So "beginning or end" in this sentence refers to point-min resp. -max. It doesn't ...
While the preferable answer IMO was given by Stefan, here an example which includes a solution not relying on syntax-table WRT delimiters: It uses something like
and a stack. See source here