Hot answers tagged

11

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: (pp package-alist) Which will format the output in a more readable way.


10

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 ...


7

Perhaps you're looking for indent-pp-sexp, which is bound to C-M-q by default in emacs lisp mode. With a prefix argument (e.g. C-u C-M-q) this will "pretty print" the sexp at point.


6

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 ...


6

Set eval-expression-print-length and eval-expression-print-level to nil.


5

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 ...


5

Try this: (save-excursion (up-list) (char-before)) Note that up-list can throw, so you need to handle errors as well.


5

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. (with-temp-buffer (emacs-lisp-mode) (insert src) (scan-sexps 12 1)) ;; => 54


4

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 ...


4

I never heard this word enunciated, despite using Lisp for over quarter of a century. I always pronounce it "sexp", like it is written. The "p" is not very loud.


3

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


3

Peter Glickstein, in a footnote on p. 9 of Writing GNU Emacs Extensions, says the following about the pronunciation of "sexp": Pronounced "sex pee." Unfortunately. Unfortunate indeed.


2

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. " (interactive) (cond ((eq 4 (car (syntax-after (point)))) (forward-sexp) (forward-char -1)) ((eq 5 (car (syntax-after (point)))) (forward-char 1) ...


2

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 ...


2

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 ...


2

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 ...


2

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: (...


1

Basically use (skip-chars-forward "^}") Needs a helper-function, to check if it's a escaped }: (defun ar-backslashed-p () (save-excursion (and (eq (char-before) ?\\) (< 0 (% (abs (skip-chars-backward (regexp-quote (char-to-string ?\\)) (line-beginning-position))) 2))))) (defun no-newline-in-section () (interactive "*") (let (beg end) (...


1

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: (autoload ...


1

Expanding it to "symbolic expression", which is its meaning.


1

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 ...


1

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 (skip-chars-backward "^{\(\[\]\)}") and a stack. See source here https://github.com/emacs-berlin/general-close


Only top voted, non community-wiki answers of a minimum length are eligible