Ramin Honary on Nostr: #Emacs tip of the week This is a two-for-one, these are two tips that I can't believe ...
#Emacs tip of the week
This is a two-for-one, these are two tips that I can't believe I never learned about it until now.
What is an easy way to see the value of a variable, or see the result returned from a function call?
You might know about the M-: (Alt-Colon) command, which lets you run any Lisp code, the result is printed into the *Messages* buffer. But... if you use the prefix command C-u (Control-U) and then press M-: (Alt-Colon), the result returned by the Lisp code is printed into the current buffer after the cursor.
Even better, however is using the (pp) ("Pretty-Printing") function. This also outputs to *Messages* by default, but it takes 2 arguments, the second of which can be a buffer. Try this code:
(pp (buffer-local-variables) (currrent-buffer))
The result returned by (buffer-local-variables), which is a list of all buffer-local variables and their values, is pretty-printed right after the cursor.
Published at
2023-08-15 08:58:59Event JSON
{
"id": "15bb1498e525269188aff1498d4dcbb309a9eb9c2f5c00fe667ef78f4211acf4",
"pubkey": "4ae97b2084e2b2c3bc17385ca42179c75c9177c2fef6f0b99c65fa177ff4d1fa",
"created_at": 1692089939,
"kind": 1,
"tags": [
[
"t",
"emacs"
],
[
"proxy",
"https://emacs.ch/users/ramin_hal9001/statuses/110892806299194305",
"activitypub"
]
],
"content": "#Emacs tip of the week\nThis is a two-for-one, these are two tips that I can't believe I never learned about it until now.\nWhat is an easy way to see the value of a variable, or see the result returned from a function call?\nYou might know about the M-: (Alt-Colon) command, which lets you run any Lisp code, the result is printed into the *Messages* buffer. But... if you use the prefix command C-u (Control-U) and then press M-: (Alt-Colon), the result returned by the Lisp code is printed into the current buffer after the cursor.\nEven better, however is using the (pp) (\"Pretty-Printing\") function. This also outputs to *Messages* by default, but it takes 2 arguments, the second of which can be a buffer. Try this code:\n(pp (buffer-local-variables) (currrent-buffer))\nThe result returned by (buffer-local-variables), which is a list of all buffer-local variables and their values, is pretty-printed right after the cursor.",
"sig": "779f81e66fd9350e658117497389588ddd8a350117c164247ebd0ba7144d1ffee59d9b844472cbd74a60478a148ad5c41bb006a07ed0ec0580d835080792fa3f"
}