Turning Two Spaces Into A New Sentence

In the Apple ecosphere—especially in iOS—a convenient short cut is to type two spaces to end the current sentence and start a new one. Specifically, two spaces will delete the spaces, insert a period and a space, and capitalize the next letter. There’s probably something similar in the Android world; it seems like a natural thing to do.

Over at Bicycle For Your Mind, macosxguru has a post that describes three of the recent changes he’s made to his Emacs environment. Two of them—showing tabs and newlines explicitly, and fiddling with his mode line probably won’t interest most Irreal readers. The third is importing the two space shortcut into Emacs.

Emacs, of course, doesn’t have that capability but macosxguru added it with a bit of Elisp which he binds to the Space key with the text-mode hook. It looks for two consecutive spaces and repaces them with a period and space. The tricky part is capitalizing the next letter. He does that by reading the next character explicitly and capitalizing it if it’s a letter. He also checks for some special keys (like an arrow key) and “unreads” them so that Emacs can treat them normally. All the code is in the post so see it for the details if you’re interested.

I’m ambivalent about this change. On the one hand, I use it all the time on my iPhone and iPad but that’s because typing is such a pain on virtual keyboards. On a regular keyboard, I’m pretty sure that I could type the period, space, and next letter just as fast. The shift for the next letter might slow things down a bit but not by much. I haven’t decided yet whether I will adopt it but inertia will probably cause me not to.

Posted in General | Tagged | Leave a comment

Folding In Non-Org Buffers

Marcin Borkowski (mbork) really likes being able to cycle folding in Org buffers. Of course, then he wanted to be able to do the same thing in any buffer. In particular, he wanted to be able to fold and unfold groups of functions as a set. He experimented with all sorts of solutions including the builtin outline minor mode.

None of them were quite what he wanted. Then he found outli. It was perfect for his needs. It’s a third party package but appears to be well maintained and is less than 400 lines of code. What he really likes, though, is the keybindings. Most important to him is that Tab cycles the folding just like in Org mode.

Although I like and use headline folding in Org mode, I’ve never been able warm up to code folding. On those rare occasions when I want to narrow focus to a single function—usually to delimit searches—I simply narrow to the function or region in question. Of course, others, like mbork, disagree and those folks may want to check out mbork’s post to get the details of his solution.

Posted in General | Tagged | Leave a comment

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