Categories: geek » emacs

RSS - Atom - Subscribe via email

2021-08-30 Emacs news

| emacs, emacs-news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Hacker News, planet.emacslife.com, YouTube, the Emacs NEWS file, Emacs Calendar and emacs-devel.

View or add comments

2021-08-23 Emacs news

| emacs, emacs-news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Hacker News, planet.emacslife.com, YouTube, the Emacs NEWS file, Emacs Calendar and emacs-devel.

View or add comments

Using the wgrep package in Emacs to rewrite grep results from lots of files

| 11ty, emacs

acdw let me know that my Emacs News links to https://reddit.com didn't work for him in Firefox on Linux, but that changing the links to https://www.reddit.com would make them work. I was glad that I had migrated my blog from Wordpress to the 11ty static site generator. All my blog posts were HTML files, and I could just whiz through them all.

In the past, I might have used find-dired or find-grep-dired to get a list of files. Then I would record a keyboard macro to open a file, search and replace the text, save the buffer, and then kill the buffer, and I would just repeat this macro until an error occurred.

Some time ago, I learned about using Q (dired-do-find-regexp-and-replace) in Dired to replace regular expressions in marked files, using Y to accept all the replacements. That would then let me use C-x s (save-some-buffers) to save all the modified buffers with !. The bufler package is handy for closing a whole bunch of buffers of a certain type, although ibuffer or helm can handle that too.

Emacs being Emacs, there's an even better way to do it. I used M-x grep to find the lines to change, the wgrep package to make the results editable, and M-x replace-string to change things. A quick C-c C-e (wgrep-finish-edit) later, and I was able to change 5485 matching lines in 302 files.

It's so nice being able to deal with things in plain text. Yay for Emacs! There's always something more to learn.

View or add comments

Started learning how to interactively debug Javascript in Emacs with Indium

| 11ty, emacs, coding

I noticed something strange in my static blog: my blogging category page didn't list my post on statically generating my blog with Eleventy. Now it does, of course, since I fixed it. But it didn't, and that was weird. I tried using console.log to debug it, but it was annoying to try to figure out the right thing to print out in a long list of nested objects. Besides, console.log debugging is so… last century.

Since these tips for debugging in 11ty mentioned interactively debugging things in VS Code, I decided it was a good time to learn how to use Indium, a Javascript development environment for Emacs.

(use-package indium :hook ((js2-mode . indium-interaction-mode)))

After some trial and error, this was the .indium.json file that allowed me to use M-x indium-launch to start the Eleventy process.

{
  "configurations": [
    {
      "name": "11ty",
      "type": "node",
      "program": "node",
      "args": "./node_modules/.bin/eleventy"
    }
  ]
}

I originally had "inspect-brk": true in it as well, following the suggested configuration, but I found it easier to just set breakpoints in my files using indium-add-breakpoint (C-c b b, a keybinding set up by indium-interaction-mode in my js2-mode-hook).

Conditional breakpoints didn't seem to work, so I just put my logic in an if and set my breakpoint in there.

  categories.forEach((item) => {
    if (item.slug == 'blogging') {
      let post = data.collections._posts.find(o => o.inputPath.match(/statically-generating-my-blog-with-eleventy/));
      console.log(post);
    }
    ...
  }

When I set my breakpoint on the let post... line and ran M-x indium-launch, I got an interactive debugger at that breakpoint. I could also switch to the REPL console and type stuff. Yay!

As it turned out, the post I wanted wasn't showing up in the list of posts. It was because I had used eleventyConfig.setTemplateFormats and forgotten to include md for Markdown files. Once I figured out what was going on, it was easy to fix. This is what the debugger looks like. It adds values to the ends of lines, and you can evaluate things.

Screenshot_20210816_002331.png

I'm looking forward to learning more about using Indium to debug scripts running in Node or Chrome. Slowly, slowly having some focused time to sharpen the saw!

If you use Emacs for Javascript development and you're curious about Indium, you can check out the documentation.

View or add comments

2021-08-16 Emacs news

| emacs, emacs-news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Hacker News, planet.emacslife.com, YouTube, the Emacs NEWS file, Emacs Calendar and emacs-devel.

View or add comments

2021-08-09 Emacs news

| emacs, emacs-news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Hacker News, planet.emacslife.com, YouTube, the Emacs NEWS file, Emacs Calendar and emacs-devel.

View or add comments

2021-08-02 Emacs news

| emacs, emacs-news

Links from reddit.com/r/emacs, r/orgmode, r/spacemacs, r/planetemacs, Hacker News, planet.emacslife.com, YouTube, the Emacs NEWS file, Emacs Calendar and emacs-devel.

View or add comments