A Quick EWW Hack

I’ve been writing a bit lately about my growing use of EWW [1, 2, 3, 4]. I was always a little skeptical of those who said they made significant use of EWW for their browsing but then I realized that I had started doing the same thing. It certainly hasn’t replaced Safari but I am using it more and more.

It started fairly innocently. I use elfeed-webkit to render the web pages from my RSS feed. That has the significant disadvantage that my ad and tracking blocker doesn’t work for them. That, in turn, means that I get all sorts of junk displayed. It’s usually a dickover but sometimes there’s a seemingly never ending train of popup ads. Fortunately, elfeed (and elfeed-webkit) have a hot key to display the page in EWW and avoid all that. Now as soon as a dickover covers up the text or a avalanche of ads starting popping up, I simply switch over to EWW and read in peace. It’s surprising how little I need JavaScript.

As I said, I find myself using EWW more and more. It’s easy to call it from Embark when the point is on a URL and often I’ll just use it instead of invoking Safari. Of course, that brings up question. Can I switch from Safari to EWW when I need to? I couldn’t find any builtin way but I realized I already had everything I needed to do it. The first part is to retrieve the URL of the current Safari Web page. I’ve had a function to do this for a long time and use it all the time to capture links to the current Web page into Org. It’s pretty simple but restricted to macOS. Here it is.

(defun jcs-retrieve-url ()
  "Retrieve the URL of the current Safari page as a string."
  ;; (org-trim (shell-command-to-string
  ;;   "osascript -e 'tell application \"Safari\" to return URL of document 1'")))
  (do-applescript "tell application \"Safari\" to return URL of document 1"))

The way to do this varies by browser and OS but is usually straightforward.

The second part is doing the actual switch. Again, it’s simple:

(defun jcs-switch-to-eww ()
  "Invoke EWW for the current Safari web page"
  (interactive)
  (eww (jcs-retrieve-url)))

I put this in iCanHazShortcut and bound it to Ctrl+F7. It works fine except I haven’t yet figured out how to switch to Emacs from Safari so I have to press F6 for that. That’s a small price to play until I figure out the rest of the magic spell.

EWW, of course, has a way to switch to the default browser so it’s easy to pop back and forth as needed. It’s a small thing but makes my workflow easier.

Posted in General | Tagged , | Leave a comment

Embark For CIDER & Projectile

Bozhidar Batsov, who’s been writing about Embark lately has a nice post on integrating CIDER and Projectile into Embark. I don’t use either of them so you might wonder why I care. The answer is that Batsov’s post is a good example of how to add a new application to Embark.

That turns out to be pretty easy. For projectile, Batsov built it into the app so you’ll have to check the source code to see the details. For CIDER, though, he adds the Embark functionality externally so you can see how it’s done. It’s mainly a matter of writing some straightforward wrapper functions, binding them up in a keymap for Embark, providing a target function that identifies symbols, and finally adding the keymap to Embark.

For me, then, the value of Batsov’s post is that it serves as a how to that shows you the recipe for extending Embark to include new applications.

Posted in General | Tagged | Leave a comment

Copy Link At Point In EWW

Raymond Zeitler over at Ray on Emacs has a nice post on copying the link at point in EWW. It’s sort of hidden so that’s the reason for his post and this one. He decided to write his own because he couldn’t find anything that already did the job. It was only after he wrote it that he stumbled on the existing functionality.

The short answer is that the u key does just what he wanted. The longer answer is that sometimes w also works. The documentation says that w copies the URL of the current page but if the point is on a link, it will copy the link’s URL instead.

I’m finding that I’m using EWW more and more so I’m glad to have this information. Zeitler has more details so be sure to take a look at his post.

Posted in General | Tagged | Leave a comment

A Couple Of Tips For Emacs on macOS

Over at The Art Of Not Asking Why, JTR has begun a series on his Emacs configuration. This post covers his special arrangements for macOS. There are two tips, in particular, that seem to come up all the time.

The first is setting the path. That, of course, is supposed to be a simple process on Unix-like systems but doesn’t work correctly for Emacs on macOS. A long time ago, Steve Purcell solved this problem with his exec-path-from-shell package. You can read the details and what the exact problem is at the package’s GitHub repository. If you’re using Emacs on a Mac, you definitely need this package.

The second problem involves Dired. It’s obvious, if you think about it, that Dired depends on the Unix ‘ls’ command to produce its listings and some of its other operations. The problem is that the macOS version of ls is missing some of the options that Dired needs. The solution is to use the GNU version of ls, called gls. That’s easy to do but you first have to install it. The easy way to do that is through Homebrew. Once gls is installed, you need merely tell Dired to use it.

All the details for solving these two problems are in JTR’s post so if you’re running on macOS, you should definitely take a look at it. I’ve had both those changes installed for as long as I can remember but I do recall struggling with these issues until I found the solutions. Happily, if you’re new to Emacs on the Mac, JTR has both solutions for you in one place.

Posted in General | Tagged , | Leave a comment

Emacs 31.0.91 (pretest 2) Is Available

Sean Whitton writes to say that Emacs 31.0.91, the second Emacs 31 pretest, is now available. If you’re interested in trying it out, you can get a copy from https://alpha.gnu.org/gnu/emacs/pretest/emacs-31.0.91.tar.xz. It’s signed so you should also get the signature file from https://alpha.gnu.org/gnu/emacs/pretest/emacs-31.0.91.tar.xz.sig.

This is good news, of course, because it means that Emacs 31 is that much closer to release. There’s some great new features coming in Emacs 31 (see the NEWS file for details) so I’m looking forward to its release. On the other hand, it’s good that the devs are being conservative and trying to wring all the bugs out before the official release.

If you don’t mind living (slightly) on the edge, try it out and let the devs know if you find any problems.

Posted in General | Tagged | Leave a comment

Making A Window Dedicated

Bozhidar Batsov has been a writing a very nice series of posts on recent Emacs additions that are worth knowing. His latest is on making a window dedicated. A dedicated window is one that is locked to its current buffer. That means, for instance, that if you have a particular window configuration in place and call some other function, the new function can’t hijack the dedicated window and spoil your configuration. Batsov has an animated Gif that shows this in action.

The notion of a dedicated window has been in Emacs for some time but what’s new is a quick way of dedicating a window. That way is toggle-window-dedicated, which is bound to Ctrl+x w d by default. As shown in Batsov’s Gif, that toggles the dedicated state for the current window on and off.

Sadly, I have Ctrl+x w bound to a function that starts up elfeed. I use that several times a day and have a significant investment in muscle memory so I either have to change the toggle-window-dedicated binding or simply call it directly. Since I doubt I’ll be using it that often, I’ll probably just call it directly. With my fuzzy command completion I need only enter Meta+x tog win to get the desired result.

There’s one other aspect that Batsov mentions but doesn’t explain: strongly dedicated windows. If a window is strongly dedicated, you can’t change the buffer displayed by the window. You can make a window strongly dedicated by specifying the universal argument in the call to toggle-window-dedicated.

If you like to set up a specific window configuration for some of your workflows and you don’t like random commands stepping on it, toggle-window-dedicated is just what you need.

Posted in General | Tagged | Leave a comment

Aligning Mode Line Elements

Mode lines. Everybody complains about them and a few brave souls—like Prot—have even taken the time and effort to do something about them. The problem is that they’re so tricky to configure that it’s not worthwhile so we just suffer with the default.

Now Bozhidar Batsov writes about an easy change that anyone can make. As of Emacs 30, it’s possible to right align given elements of the mode line. That was always possible, of course, but it required some tricky padding that was particularly fragile. Now there’s mode-line-format-right-align, which serves as a marker in your mode line definition. Everything before it is left aligned and everything after it is right aligned.

Even the right edge is customizable. You can choose the right edge of the window, the left end of the fringe, or the left edge of the right margin. This facility is going to be useful to those who want a customized mode line.

My main problem with the mode line is getting all the items I want to fit on it. Even though I make liberal use of diminish, a lot of useful information always seems to fall off the right end. That probably means I need to watch Prot’s video again and buckle down to customizing it the way I want it.

In any event, it you’d like to place some items at the right side of the mode line, take a look at Batsov’s post to see how to do it.

Posted in General | Tagged | Leave a comment

Flymake Diagnostics

Bozhidar Batsov has a quick post on a recent enhancement to Emacs Flymake. The TL;DR is that you can arrange for Flymake to append a diagnostic at the end of any line with a problem. It’s a quick way of seeing what the problem is and maybe fixing it without a lot of extra work.

As Batsov (and the documentation) says, that can get a little noisy so (of course) Emacs gives you a setting to control how much information is displayed. Take a look at Batsov’s post for the details.

I’ve never warmed up to Flymake but lots of people, I know, love it. If you’re one of those people, be sure to take a look at Batsov’s post. Everything is controlled by a single variable so it’s easy to try out the various options.

This feature is available only with Emacs 30 and later. Getting it may be a good reason to upgrade if you haven’t already.

Posted in General | Tagged | Leave a comment

A Small Jinx Tweak

As I’ve written recently [1, 2, 3, 4], I’ve been changing the Irreal Bunker’s spelling corrector to Jinx. I’ve had a couple of issues—mostly with choosing the correction—but things have mostly been smooth and Jinx has a lot of nice features.

One thing I don’t like is the face that Jinx chooses for misspelled words. Ispell used red, which stood out and made it easy to pick out the misspellings. Jinx uses a color that is almost the same as the text and even though misspellings are underlined with a wavy line they’re harder to pick out. There are two colors: one for dark themes and one for light themes. Oddly, there are no options for changing the colors.

Happily, this is Emacs so the source code is only a click away. It turns out the color is defined by a defface in the jinx.el file. I copied that to my init.el and changed the color to red Here’s the result:

(defface jinx-misspelled
  '((((class color) (min-colors 88) (background dark)
      (supports :underline (:style wave)))
     :underline (:style wave :color "#d2b580"))
    (((class color) (min-colors 88) (background light)
      (supports :underline (:style wave)))
     :underline (:style wave :color "#ff0000")) ; <-- changed color
    (t :underline t :inherit error))
  "Face used for misspelled words.")

I was going to change the color for the dark theme too just for completeness but the Minions wouldn’t allow it. You know how they are about dark themes. If you want to change the color in your Emacs, just paste the above into your init.el and choose whichever color works for you. You can, of course, also fix things up for dark themes. Just don’t tell the Minions.

Posted in General | Tagged | Leave a comment

Reading

Elia Scotto has a very nice post on the reading habit. He says he’s been reading about a book a week for several years. The gist of the post is “how to read more books”. His advice for that is straightforward: read when you have nothing else going on. In particular, instead of reaching for your phone and doom scrolling, pick up a book and read a few pages. I agree with all that but not with some of his other recommendations that seem to me to border on the new Luddism.

For example, he considers it important to avoid using your phone. That means he wears an analog watch (so he won’t have to look at his phone), that he tries to carry a physical book with him at all times, and that when he can’t he uses a separate ebook reader.

I also read when I have a few spare moments but I do it on my phone. My iPhone is always with me so I don’t need to remember to bring along a physical book or separate reader. It’s all there on my iPhone. I always read for about an hour when I go to bed and for that I use my iPad. If during the day I find myself with nothing to do, I can always sync my phone to where I left off on the iPad and continue my reading.

Really, I don’t know why anyone wouldn’t do things more or less the way I do. You always have not only your current book but your entire library at hand. But then, I’ve never found doom scrolling—or social media, for that matter—attractive so I have nothing to resist.

In any event, the important thing is to find time to read. You don’t have to be an intellectual or read big, important books. Although I sometimes read books like that, I mostly read mysteries and science fiction. Some of them are as lowbrow as you can get. It doesn’t matter. The goal is to read and enjoy the content.

Finally, be sure to watch the short video of the late Umberto Eco’s library of about 30,000 physical books. Despite what I said above, I love physical books and found it awe inspiring.

Posted in General | Leave a comment